Skip to content

Setup Node Exporter with Systemd

Updated: at 06:59 PM

Installing Node Exporter with Systemd

Node Exporter is a Prometheus exporter that collects hardware and OS metrics from your Linux systems. This guide explains how to install and configure Node Exporter as a systemd service on Ubuntu Linux VPS instances.

Prerequisites

Step 1: Create a System User for Node Exporter

For security reasons, it’s best to run Node Exporter as a dedicated non-privileged user:

sudo useradd --no-create-home --shell /bin/false node_exporter

This creates a system user without a home directory and with a non-functional shell.

Step 2: Download and Install Node Exporter

Download the latest version of Node Exporter from the official GitHub repository:

# Set the version you want to install
NODE_EXPORTER_VERSION=1.9.0

# Download the binary
wget https://github.com/prometheus/node_exporter/releases/download/v${NODE_EXPORTER_VERSION}/node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64.tar.gz

# Extract the archive
tar xvf node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64.tar.gz

# Copy the binary to /usr/local/bin
sudo cp node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64/node_exporter /usr/local/bin/

# Set ownership to the node_exporter user
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter

# Clean up the downloaded files
rm -rf node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64 node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64.tar.gz

Step 3: Create a Systemd Service File

Create a systemd service file to manage Node Exporter:

sudo nano /etc/systemd/system/node_exporter.service

Add the following content to the file:

[Unit]
Description=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

# Optional: Add custom collectors or disable default collectors
# ExecStart=/usr/local/bin/node_exporter --collector.disable-defaults --collector.cpu --collector.meminfo

# Security enhancements
CapabilityBoundingSet=
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Step 4: Enable and Start the Node Exporter Service

Reload systemd to recognize the new service file, then enable and start Node Exporter:

# Reload systemd configuration
sudo systemctl daemon-reload

# Start Node Exporter
sudo systemctl start node_exporter

# Enable Node Exporter to start at boot
sudo systemctl enable node_exporter

Step 5: Verify the Installation

Check if Node Exporter is running correctly:

# Check service status
sudo systemctl status node_exporter

# Verify that Node Exporter is exposing metrics
curl http://localhost:9100/metrics

You should see a large output of metrics if Node Exporter is working correctly.

Step 6: Configure Firewall (Optional)

If you’re using UFW (Uncomplicated Firewall), you may want to allow access to Node Exporter only from your Prometheus server:

# Replace prometheus-server-ip with the actual IP of your Prometheus server
sudo ufw allow from prometheus-server-ip to any port 9100

Step 7: Test from Prometheus Server

From your Prometheus server, verify that it can scrape metrics from Node Exporter:

curl http://your-vps-ip:9100/metrics

Troubleshooting

If you encounter issues:

  1. Check the service status:

    sudo systemctl status node_exporter
    
  2. View the logs:

    sudo journalctl -u node_exporter
    
  3. Verify the port is open:

    sudo ss -tulpn | grep 9100
    
  4. Check firewall rules:

    sudo ufw status
    

Customizing Node Exporter

Node Exporter provides many collectors that can be enabled or disabled. To see all available options:

/usr/local/bin/node_exporter --help

To customize which collectors are enabled, modify the ExecStart line in the systemd service file. For example, to disable all collectors by default and only enable specific ones:

ExecStart=/usr/local/bin/node_exporter --collector.disable-defaults --collector.cpu --collector.meminfo --collector.filesystem --collector.netdev

After making changes to the service file, reload systemd and restart Node Exporter:

sudo systemctl daemon-reload
sudo systemctl restart node_exporter

All in One Script

If you prefer a one-liner script to install Node Exporter, you can use the following:

#!/bin/bash
# Node Exporter installation script

# Exit on any error
set -e

echo "=== Installing Node Exporter as a systemd service ==="

# Create system user
echo "Creating system user..."
sudo useradd --no-create-home --shell /bin/false node_exporter || true

# Set version and download Node Exporter
NODE_EXPORTER_VERSION=1.9.0
echo "Downloading Node Exporter v${NODE_EXPORTER_VERSION}..."
wget -q https://github.com/prometheus/node_exporter/releases/download/v${NODE_EXPORTER_VERSION}/node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64.tar.gz

# Extract and install
echo "Extracting and installing Node Exporter..."
tar xvf node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64.tar.gz > /dev/null
sudo cp node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64/node_exporter /usr/local/bin/
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter

# Create systemd service file
echo "Creating systemd service file..."
cat << EOF | sudo tee /etc/systemd/system/node_exporter.service > /dev/null
[Unit]
Description=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

# Security enhancements
CapabilityBoundingSet=
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF

# Enable and start service
echo "Enabling and starting Node Exporter service..."
sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl enable node_exporter

# Clean up downloaded files
echo "Cleaning up..."
rm -rf node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64 node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64.tar.gz

# Verify installation
echo "Verifying installation..."
if systemctl is-active --quiet node_exporter; then
    echo "✅ Node Exporter is running successfully!"
    echo "✅ Metrics are available at: http://$(hostname -I | awk '{print $1}'):9100/metrics"
else
    echo "❌ Node Exporter installation failed. Check logs with: sudo journalctl -u node_exporter"
    exit 1
fi

# Print service status
echo -e "\nService status:"
sudo systemctl status node_exporter --no-pager

Conclusion

You now have Node Exporter installed and running as a systemd service on your Ubuntu VPS. This will expose system metrics that Prometheus can scrape, allowing you to monitor your server’s performance and health through Grafana dashboards.


Previous Post
How to setup adguard home to block ads in your home network