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_exporterThis 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.gzExtract the downloaded file:
tar -xvzf node_exporter-x.y.z.linux-amd64.tar.gzMove 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_exporterThe 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_exporterYou 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.servicePaste 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.targetAlso create the socket file:
sudo nano /etc/systemd/system/node_exporter.socketPaste the following content into the file:
[Unit]
Description=Node Exporter
[Socket]
ListenStream=9100
[Install]
WantedBy=sockets.targetAfter creating the service file, reload systemd to apply the new service configuration:
sudo systemctl daemon-reloadEnable the Node Exporter service so it starts automatically on boot:
sudo systemctl enable node_exporterFinally, start the Node Exporter service:
sudo systemctl start node_exporterTo verify that the service is running correctly, check the status:
sudo systemctl status node_exporterEnsure 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/metricsIf you see Prometheus metrics, the Node Exporter is installed and running correctly.