Running the Node Exporter as a service in Prometheus involves setting up the Node Exporter on your machine and configuring it to run as a system service so that it starts automatically at system boot. The Node Exporter is a Prometheus exporter that collects hardware and OS metrics exposed by *NIX kernels, then exports them over HTTP for Prometheus to scrape.
Here's how to set up and run Node Exporter as a service on a Linux system using systemd (which is commonly used in distributions like Ubuntu, CentOS, Debian, etc.):
Step 1: Download and Install Node Exporter
Go to the Prometheus downloads page: Navigate to the official Prometheus downloads page and find the latest version of Node Exporter.
Download and unpack Node Exporter:
bashcd /tmp wget https://github.com/prometheus/node_exporter/releases/download/v*/node_exporter-*.*-amd64.tar.gz tar xzf node_exporter-*.*-amd64.tar.gz
Replace
*.*
with the actual version number of Node Exporter.Move the Node Exporter binary to
/usr/local/bin
:bashsudo cp node_exporter-*/node_exporter /usr/local/bin/
Step 2: Create a Systemd Service File
Create a new systemd service file:
bashsudo nano /etc/systemd/system/node_exporter.service
Add the following content to the service file:
ini[Unit] Description=Node Exporter Wants=network-online.target After=network-online.target [Service] User=prometheus Group=prometheus Type=simple ExecStart=/usr/local/bin/node_exporter [Install] WantedBy=multi-user.target
Make sure to replace
User
andGroup
with the user and group you want to run Node Exporter under. If theprometheus
user does not exist, create it usingsudo useradd -rs /bin/false prometheus
.
Step 3: Enable and Start the Service
Reload systemd to read the new unit file:
bashsudo systemctl daemon-reload
Enable Node Exporter to start at boot:
bashsudo systemctl enable node_exporter
Start the Node Exporter service:
bashsudo systemctl start node_exporter
Step 4: Verify the Service
Check the status of the Node Exporter service:
bashsudo systemctl status node_exporter
This command shows you whether the service is active and running without any issues.
Check if Node Exporter is serving metrics: Visit
http://<your-server-ip>:9100/metrics
in a web browser or use curl:bashcurl http://localhost:9100/metrics
This should display a page full of system metrics, indicating that Node Exporter is working correctly.
By following these steps, Node Exporter will be set up and running as a systemd service, automatically starting on boot and ready to be scraped by Prometheus. This setup ensures that you continuously collect and monitor the metrics from your system.
No comments:
Post a Comment