Operations 10 min read

Batch Installation of Node Exporter on Linux Hosts Using Ansible, JumpServer, and a Static File Server

This guide explains three practical methods for deploying the Prometheus node_exporter collector across large numbers of Linux servers—using a JumpServer with Ansible, a standalone Ansible playbook, or a custom Bash script combined with an internal static file server—complete with configuration, service setup, and integration into Consul and vmagent monitoring.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Batch Installation of Node Exporter on Linux Hosts Using Ansible, JumpServer, and a Static File Server

When monitoring a fleet of Linux hosts, the node_exporter collector must be installed on each machine; this article outlines three common approaches for bulk deployment.

1. JumpServer + Ansible

If all Linux hosts are managed by a bastion (JumpServer), you can use the integrated Ansible tool to run a deployment script on every host, installing node_exporter as a systemd service.

2. Standalone Ansible

Without a bastion, a pure Ansible playbook can be written to perform the same steps: detect OS, install dependencies, download the latest node_exporter binary, create a dedicated user, configure systemd service and socket files, and finally enable and start the service.

3. Custom Bash Script

The following Bash script implements the full installation workflow. It detects the OS, installs required tools, removes any previous node_exporter installation, downloads the latest version, extracts it, creates a system user, writes systemd unit files, sets service options based on the distribution, and starts the service.

#!/bin/bash
# Detect OS and package manager
check_os() { ... }
# Verify /etc/systemd/system exists
check_service_path() { ... }
# Install dependencies (curl, tar, etc.)
install_dependencies() { ... }
# Clean up old node_exporter
cleanup_old_node_exporter() { ... }
# Download and extract latest node_exporter
download_and_extract_node_exporter() { ... }
# Create node_exporter user
create_node_exporter_user() { ... }
# Configure systemd service and socket
configure_systemd_service() { ... }
# Enable and start service
start_and_enable_service() { ... }
# Main interactive menu
main() { ... }
main

To adapt the script for an internal network, replace the download_url variable with the address of an internal static file server.

Static File Server

Deploy a simple static file server using Docker to host the node_exporter binary and the deployment script:

docker run -d \
    -v /data/file:/web \
    -p 80:8080 \
    halverneus/static-file-server:latest

Upload the node_exporter tarball and the deploy-node.sh script to /data/file . Clients can then download them via wget http:// /node_exporter- .linux-amd64.tar.gz or curl -O http:// /node_exporter- .linux-amd64.tar.gz and execute the script.

Consul Service Registration

After installation, register each node_exporter instance in Consul so that vmagent can scrape metrics. Example vmagent job configuration:

- job_name: "node_exporter"
  scrape_interval: 15s
  consul_sd_configs:
    - server: '172.16.100.151:8500'
      token: 'afxxxxxx-ffxx-4bxx-bxxx-94xxxa4xxx44'
      services: ['selfnode_exporter']
      tags: ['linux']
      relabel_configs:
        - source_labels: [__meta_consul_tags]
          regex: .*OFF.*
          action: drop
        - source_labels: ['__meta_consul_service']
          target_label: cservice
        - source_labels: ['__meta_consul_service_metadata_vendor']
          target_label: vendor
        ...

Once Consul is updated, vmagent will display the new targets on its /targets page, and you can view the Linux host monitoring dashboard in Grafana (Prometheus/VictoriaMetrics data sources).

The article concludes with notes on adapting the script for different environments, using Ansible playbooks for large-scale rollouts, and encourages community sharing of dashboards and configurations.

PrometheusConsulAnsiblelinux monitoringNode Exporterdeployment scriptstatic file server
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.