Skip to content

Instantly share code, notes, and snippets.

@muhep06
Created December 4, 2025 18:14
Show Gist options
  • Select an option

  • Save muhep06/4203ac98984db8aff36a1f9dc28a946a to your computer and use it in GitHub Desktop.

Select an option

Save muhep06/4203ac98984db8aff36a1f9dc28a946a to your computer and use it in GitHub Desktop.
Automated shell script to install and configure Prometheus Node Exporter as a systemd service on Linux.
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
# 1. Define Version (Use argument if provided, otherwise default to 1.8.2)
DEFAULT_VERSION="1.10.2"
VERSION="${1:-$DEFAULT_VERSION}"
echo "------------------------------------------------"
echo "Starting Node Exporter Installation..."
echo "Target Version: v$VERSION"
echo "------------------------------------------------"
# 2. Create the Node Exporter user (Security)
# Check if user already exists to avoid errors
if id "node_exporter" &>/dev/null; then
echo "User 'node_exporter' already exists. Skipping creation..."
else
sudo useradd --no-create-home --shell /bin/false node_exporter
echo "User 'node_exporter' created."
fi
# 3. Download and Extract
echo "Downloading node_exporter-$VERSION.linux-amd64.tar.gz..."
wget -q --show-progress https://github.com/prometheus/node_exporter/releases/download/v$VERSION/node_exporter-$VERSION.linux-amd64.tar.gz
tar xf node_exporter-$VERSION.linux-amd64.tar.gz
# 4. Move Binary and Set Permissions
echo "Installing binary to /usr/local/bin/..."
sudo cp node_exporter-$VERSION.linux-amd64/node_exporter /usr/local/bin/
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter
# 5. Clean up downloaded files
rm -rf node_exporter-$VERSION.linux-amd64.tar.gz node_exporter-$VERSION.linux-amd64
echo "Cleaned up temporary files."
# 6. Create Systemd Service File
echo "Creating systemd service file..."
sudo bash -c 'cat <<EOF > /etc/systemd/system/node_exporter.service
[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
[Install]
WantedBy=multi-user.target
EOF'
# 7. Start and Enable the Service
echo "Reloading daemon and starting service..."
sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl enable node_exporter
# 8. Check Status
echo "------------------------------------------------"
echo "Installation Complete (v$VERSION). Service Status:"
sudo systemctl status node_exporter --no-pager
@muhep06
Copy link
Author

muhep06 commented Dec 4, 2025

Node Exporter Installer Script

A Bash script to automatically download, install, and configure Prometheus Node Exporter as a systemd service on Linux.

Features:

  • Version Control: Installs v1.10.2 by default, or any specific version you provide.
  • Security: Creates a dedicated node_exporter user with no shell access.
  • Cleanup: Automatically removes tarballs and extracted folders after installation.
  • Systemd Integration: Creates, enables, and starts the service automatically.

Usage

Method 1: One-Line Installation (via curl)

You can run the script directly from the raw Gist URL without saving the file.

Option A: Install Default Version (v1.10.2)

# Replace <GIST_RAW_URL> with your actual raw gist link
curl -sL <GIST_RAW_URL> | bash

Option B: Install Specific Version (e.g., v1.7.0)
Pass the version number as an argument using bash -s.

curl -sL <GIST_RAW_URL> | bash -s 1.7.0

Method 2: Manual Installation

  1. Download the script:

    wget <GIST_RAW_URL> -O install_node_exporter.sh
  2. Make it executable:

    chmod +x install_node_exporter.sh
  3. Run the script:

    # Run with default version
    ./install_node_exporter.sh
    
    # OR run with a specific version
    ./install_node_exporter.sh 1.6.1

Verification

After installation, verify that Node Exporter is running and exposing metrics:

  1. Check Service Status:

    systemctl status node_exporter
  2. Check Metrics Endpoint:

    curl localhost:9100/metrics

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment