
Server monitoring is fundamental to maintaining healthy, high-performing applications and infrastructure. Prometheus has emerged as a leading open-source monitoring and alerting toolkit, and to collect metrics from your servers, you need agents like the Node Exporter. This guide walks you through installing the Prometheus Node Exporter on CentOS 8, enabling you to gather vital system-level metrics.
By following these steps, you’ll configure your CentOS 8 server to expose hardware and operating system metrics, ready to be scraped by your Prometheus server.
Prerequisites:
- A server running CentOS 8.
- Root or sudo privileges on the server.
- Basic familiarity with the Linux command line.
Let’s get started.
Step 1: Download the Prometheus Node Exporter
The Node Exporter is distributed as a binary, making installation straightforward. We’ll download the latest stable version directly to the server.
First, navigate to a temporary directory, such as /tmp
:
cd /tmp
Next, download the appropriate Node Exporter tarball. You can find the latest release on the Prometheus website’s download page or GitHub releases. Replace the version number in the command below with the latest stable version if different:
wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
Note: Always check the official Prometheus download page for the very latest stable version and update the wget
command accordingly.
Step 2: Extract and Install the Binary
Now, extract the downloaded tarball and move the node_exporter
binary to a suitable location in your system’s PATH, typically /usr/local/bin
.
Extract the file:
tar -xvf node_exporter-1.7.0.linux-amd64.tar.gz
This will create a directory like node_exporter-1.7.0.linux-amd64
. Navigate into this directory:
cd node_exporter-1.7.0.linux-amd64
Now, move the node_exporter
executable to /usr/local/bin
:
sudo mv node_exporter /usr/local/bin/
You can verify the installation by checking the version:
node_exporter --version
This should output the version information.
Step 3: Create a Dedicated User (Recommended Security Practice)
For security reasons, it’s best practice to run the Node Exporter under its own unprivileged user account.
Create a system user named node_exporter
with no home directory and no shell access:
sudo useradd --no-create-home --shell /bin/false node_exporter
Step 4: Create a Systemd Service File
To manage the Node Exporter easily (start, stop, enable on boot), we’ll create a systemd service file.
Create a new file named node_exporter.service
in the /etc/systemd/system/
directory using your preferred text editor (like nano
or vim
):
sudo nano /etc/systemd/system/node_exporter.service
Paste the following configuration into the file:
[Unit]
Description=Prometheus Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter \
--web.listen-address=":9100"
[Install]
WantedBy=multi-user.target
Explanation:
[Unit]
: Describes the service.Wants
andAfter
ensure the network is available before starting.[Service]
: Configures how the service runs.User
andGroup
: Specifies the user and group the service runs as (the one we created).Type=simple
: Standard service type.ExecStart
: The command to execute to start the service. It points to the binary location and specifies the listening address (default port 9100). You can add--collector.*
flags here if you need to disable specific collectors, but for a basic setup, the defaults are fine.
[Install]
: Defines when the service should be started (during multi-user system startup).
Save and close the file.
Step 5: Start and Enable the Node Exporter Service
Reload systemd to recognize the new service file:
sudo systemctl daemon-reload
Start the Node Exporter service:
sudo systemctl start node_exporter
Check the status to ensure it’s running without errors:
sudo systemctl status node_exporter
You should see active (running)
.
Enable the service to start automatically on boot:
sudo systemctl enable node_exporter
Step 6: Configure the Firewall
CentOS 8 uses firewalld
by default. The firewall will block external access to port 9100 unless explicitly allowed. You need to open this port so your Prometheus server can scrape metrics.
Add a permanent rule to allow TCP traffic on port 9100:
sudo firewall-cmd --permanent --add-port=9100/tcp
Reload the firewall to apply the changes:
sudo firewall-cmd --reload
Security Tip: For enhanced security, consider restricting access to port 9100 only to the IP address of your Prometheus server instead of opening it to the world. You can do this using --add-rich-rule
or by configuring firewall zones.
Verification
You can verify that the Node Exporter is exposing metrics by accessing http://your_server_ip:9100/metrics
from a web browser or using curl
from another machine (if the firewall is configured correctly).
curl http://localhost:9100/metrics
You should see a long output of plain text data, which are the metrics the exporter is exposing.
Conclusion
You have successfully installed and configured the Prometheus Node Exporter on your CentOS 8 server. The server is now exposing system-level metrics on port 9100, ready to be scraped by your Prometheus monitoring server. The next step in setting up comprehensive monitoring is to configure your Prometheus instance to discover and collect data from this new target.
Source: https://kifarunix.com/install-prometheus-node-exporter-on-centos-8/