Install Prometheus Node Exporter
Download and Install Prometheus Node Exporter Binary
To keep this as simple as possible, we will install the Prometheus Node Exporter binary as a service.
NOTE : If you installed Prometheus using apt install, it may have already installed a version of prometheus-node-exporter for you. At the time of creating this lecture, the version auto installed was version 0.15. I need to purge that version and manually install a version 0.16 or higher.
Check current version of prometheus-node-exporter in apt cache.
apt-cache policy prometheus-node-exporter
If version is 0.16 or above, then we can just install using
sudo apt install prometheus-node-exporter (If it wasn't already installed when installing prometheus)
But in my case, on my server running Prometheus, the node exporter version is to old, so I need to purge it.
sudo apt purge prometheus-node-exporter
Then manually download the latest binary,
tar xzf node_exporter-0.18.1.linux-amd64.tar.gz
cp node_exporter-0.18.1.linux-amd64/node_exporter /usr/local/bin/
Does it work, excellent, you can now stop the service by pressing CTRL C.
You may also want to restrict the ports to prevent access to everything else except localhost.
iptables -A INPUT -p tcp -s localhost --dport 9100 -j ACCEPT iptables -A INPUT -p tcp --dport 9100 -j DROP iptables -L
Configure Prometheus Node Exporter as a Service
Now we will configure Prometheus Node Exporter as a Service so that we can keep it running in the background.
Create a file called node-exporter.service
sudo nano /etc/systemd/system/node-exporter.service
Add the script and save
[Unit] Description=Prometheus Node Exporter Service After=network.target [Service] Type=simple ExecStart=/usr/local/bin/node_exporter [Install] WantedBy=multi-user.target
Now start and check the service is running.
systemctl daemon-reload sudo service node-exporter start sudo service node-exporter status
We can now leave the new Prometheus Node Exporter service running.
If you ever need to stop the new Prometheus Node Exporter service, then type
sudo service prometheus-node-exporter stop sudo service prometheus-node-exporter status
If you want to try a more detailed course on Prometheus, then you can visit my Prometheus tutorials.