Created
December 4, 2025 18:14
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Node Exporter Installer Script
A Bash script to automatically download, install, and configure Prometheus Node Exporter as a
systemdservice on Linux.Features:
node_exporteruser with no shell access.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)
Option B: Install Specific Version (e.g., v1.7.0)
Pass the version number as an argument using
bash -s.Method 2: Manual Installation
Download the script:
Make it executable:
Run the script:
Verification
After installation, verify that Node Exporter is running and exposing metrics:
Check Service Status:
Check Metrics Endpoint: