The node_exporter
user should be non-privileged with a shell of /sbin/nologin
. This user will own the necessary directories and will run the service.
sudo useradd --system --shell /sbin/nologin --no-create-home --home-dir /var/lib/node_exporter node_exporter
This command creates a system user without login access, with the home directory set to /var/lib/node_exporter
.
Go to the official Prometheus Node Exporter GitHub releases page and download the latest release for your operating system (usually Linux). Replace x.y.z
with the latest version number.
wget https://github.com/prometheus/node_exporter/releases/download/vx.y.z/node_exporter-x.y.z.linux-amd64.tar.gz
Extract the downloaded file:
tar -xvzf node_exporter-x.y.z.linux-amd64.tar.gz
Move the node_exporter
binary to /usr/sbin/
:
sudo mv node_exporter-x.y.z.linux-amd64/node_exporter /usr/sbin/
Example, using version 1.8.2 (linux-amd64)
:
wget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz
tar -zxvf node_exporter-1.8.2.linux-amd64.tar.gz
sudo mv node_exporter-1.8.2.linux-amd64/node_exporter /usr/sbin/
Create the directory /var/lib/node_exporter/textfile_collector
and set the appropriate ownership.
sudo mkdir -p /var/lib/node_exporter/textfile_collector
sudo chown -R node_exporter:node_exporter /var/lib/node_exporter
The sysconfig file will be placed in /etc/sysconfig/node_exporter
and will contain configuration options for the Node Exporter.
sudo mkdir -p /etc/sysconfig/
sudo touch /etc/sysconfig/node_exporter
sudo chown root:root /etc/sysconfig/node_exporter
You can now edit the file and configure any environment variables or options for Node Exporter.
OPTIONS="--collector.textfile.directory=/var/lib/node_exporter/textfile_collector"
Create the systemd service unit file for Node Exporter in /etc/systemd/system/node_exporter.service
:
sudo nano /etc/systemd/system/node_exporter.service
Paste the following content into the file:
[Unit]
Description=Node Exporter
Requires=node_exporter.socket
[Service]
User=node_exporter
# Fallback when environment file does not exist
Environment=OPTIONS=
EnvironmentFile=-/etc/sysconfig/node_exporter
ExecStart=/usr/sbin/node_exporter --web.systemd-socket $OPTIONS
[Install]
WantedBy=multi-user.target
Also create the socket file:
sudo nano /etc/systemd/system/node_exporter.socket
Paste the following content into the file:
[Unit]
Description=Node Exporter
[Socket]
ListenStream=9100
[Install]
WantedBy=sockets.target
After creating the service file, reload systemd to apply the new service configuration:
sudo systemctl daemon-reload
Enable the Node Exporter service so it starts automatically on boot:
sudo systemctl enable node_exporter
Finally, start the Node Exporter service:
sudo systemctl start node_exporter
To verify that the service is running correctly, check the status:
sudo systemctl status node_exporter
Ensure that Node Exporter is running and accessible by visiting http://<your-server-ip>:9100/metrics
in a browser or via curl
from the command line:
curl http://localhost:9100/metrics
If you see Prometheus metrics, the Node Exporter is installed and running correctly.