Install Prometheus Node exporter on linux

Categories

Monitoring

This tutorial will be very quick, you can use it as a cheat sheet from which to copy/paste the commands when you need to install Prometheus Node Exporter on your linux (debian and ubuntu) machines.

Here’s how to install it in a single block of commands, which you can copy/paste directly into the terminal at once.

sudo wget https://github.com/prometheus/node_exporter/releases/download/v1.8.1/node_exporter-1.8.1.linux-amd64.tar.gz
sudo tar xzf node_exporter-1.8.1.linux-amd64.tar.gz
sudo mv node_exporter-1.8.1.linux-amd64/node_exporter /usr/bin/node_exporter
sudo rm -rf node_exporter-1.8.1.linux-amd64.tar.gz
sudo rm -rf node_exporter-1.8.1.linux-amd64
cat <<EOF >> /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/usr/bin/node_exporter
Restart=always

[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now node_exporter

Now let’s take some time to detail the process a bit more.

The first step is to download the archive containing the executable from the releases on the project’s GitHub.

sudo wget https://github.com/prometheus/node_exporter/releases/download/v1.8.1/node_exporter-1.8.1.linux-amd64.tar.gz

The following command will extract this archive.

sudo tar xzf node_exporter-1.8.1.linux-amd64.tar.gz

We move the executable to the appropriate folder.

sudo mv node_exporter-1.8.1.linux-amd64/node_exporter /usr/bin/node_exporter

A little cleanup!

sudo rm -rf node_exporter-1.8.1.linux-amd64.tar.gz
sudo rm -rf node_exporter-1.8.1.linux-amd64

We will now declare our service and inject a basic configuration that simply calls the executable we copied earlier.

cat <<EOF >> /etc/systemd/system/node_exporter.service
[Unit]
Description=Prometheus Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/usr/bin/node_exporter
Restart=always

[Install]
WantedBy=multi-user.target
EOF

Finally, we reload the service configurations and then enable our service to start immediately after system startup.

sudo systemctl daemon-reload
sudo systemctl enable --now node_exporter

0 Comments