Skip to content

Instantly share code, notes, and snippets.

@rysyd
Last active July 13, 2024 10:05
Show Gist options
  • Save rysyd/70ee75c066fc87803a1eee083b903697 to your computer and use it in GitHub Desktop.
Save rysyd/70ee75c066fc87803a1eee083b903697 to your computer and use it in GitHub Desktop.
auto_node_exporter.sh
#!/bin/bash
wget -P /tmp/ https://github.com/prometheus/node_exporter/releases/download/v1.8.1/node_exporter-1.8.1.linux-amd64.tar.gz
tar -xf /tmp/node_exporter-1.8.1.linux-amd64.tar.gz -C /tmp/
cp /tmp/node_exporter-1.8.1.linux-amd64/node_exporter /usr/bin/
groupadd -f node_exporter && useradd -g node_exporter --no-create-home --shell /bin/false node_exporter
chown node_exporter:node_exporter /usr/bin/node_exporter
cat > /usr/lib/systemd/system/node_exporter.service <<EOL
[Unit]
Description=Node Exporter
Documentation=https://prometheus.io/docs/guides/node-exporter/
Wants=network-online.target
After=network-online.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
Restart=on-failure
ExecStart=/usr/bin/node_exporter
[Install]
WantedBy=multi-user.target
EOL
chmod 664 /usr/lib/systemd/system/node_exporter.service
systemctl daemon-reload
systemctl start node_exporter.service
systemctl enable node_exporter.service
sleep 3
systemctl status node_exporter.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment