Skip to content

Instantly share code, notes, and snippets.

@buraktabn
Last active April 28, 2023 02:38
Show Gist options
  • Save buraktabn/2cbb8ed910f24db2d1b41db9cea92cf0 to your computer and use it in GitHub Desktop.
Save buraktabn/2cbb8ed910f24db2d1b41db9cea92cf0 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
# Download the file
wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz
# Extract the file
tar xvf node_exporter-1.5.0.linux-amd64.tar.gz
# Go into the extracted directory
cd node_exporter-1.5.0.linux-amd64
# Copy the binary to /usr/local/bin
cp node_exporter /usr/local/bin
# Go back to the parent directory
cd ..
# Remove the downloaded file and extracted directory
rm node_exporter-1.5.0.linux-amd64.tar.gz
rm -rf node_exporter-1.5.0.linux-amd64
# Create a user for node_exporter
useradd --no-create-home --shell /bin/false node_exporter
# Set the ownership of the binary
chown node_exporter:node_exporter /usr/local/bin/node_exporter
# Create a service file for node_exporter
nano /etc/systemd/system/node_exporter.service
# Add the following service to node_exporter.service
tee /etc/systemd/system/node_exporter.service >/dev/null <<EOF
[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
# Reload the systemd daemon
systemctl daemon-reload
# Enable and start the node_exporter service
systemctl enable --now node_exporter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment