Skip to content

Instantly share code, notes, and snippets.

@NotYusta
Last active May 18, 2025 12:43
Show Gist options
  • Save NotYusta/7f0121db2fb01c60edb3d64ad1b9cd27 to your computer and use it in GitHub Desktop.
Save NotYusta/7f0121db2fb01c60edb3d64ad1b9cd27 to your computer and use it in GitHub Desktop.
Install Node-Exporter
#!/bin/sh
PORT=9100
BIN_DIR="/usr/local/bin"
SERVICE_NAME="node-exporter"
BINARY_NAME="node-exporter"
VERSION="1.9.1"
DOWNLOAD_URL="https://github.com/prometheus/node_exporter/releases/download/v${VERSION}/node_exporter-${VERSION}.linux-amd64.tar.gz"
# Function to download and extract node_exporter
install_node_exporter() {
curl -sL "$DOWNLOAD_URL" -o /tmp/node_exporter.tar.gz
tar -xzf /tmp/node_exporter.tar.gz -C /tmp
mv /tmp/node_exporter-${VERSION}.linux-amd64/node_exporter "$BIN_DIR/${BINARY_NAME}"
chmod +x "$BIN_DIR/${BINARY_NAME}"
}
# Function to create systemd service for node_exporter
create_systemd_service() {
cat <<EOF > /etc/systemd/system/${SERVICE_NAME}.service
[Unit]
Description=Prometheus Node Exporter
After=network.target
[Service]
ExecStart=${BIN_DIR}/${BINARY_NAME} --web.listen-address=":${PORT}"
Restart=always
[Install]
WantedBy=multi-user.target
EOF
}
# Function to enable and start the service
start_service() {
systemctl daemon-reload
systemctl enable ${SERVICE_NAME} --now
}
# Main function that calls other functions
main() {
install_node_exporter
create_systemd_service
start_service
}
# Run the main function
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment