Naposledy aktivní 1748530138

node_exp_install.sh Raw
1#!/bin/bash
2
3# Define version
4VERSION="1.9.1"
5
6# Create user for node_exporter
7useradd --no-create-home --shell /usr/sbin/nologin node_exporter
8
9# Download and extract Node Exporter
10cd /tmp
11wget https://github.com/prometheus/node_exporter/releases/download/v$VERSION/node_exporter-$VERSION.linux-amd64.tar.gz
12tar xvf node_exporter-$VERSION.linux-amd64.tar.gz
13
14# Move binary to /usr/local/bin
15cp node_exporter-$VERSION.linux-amd64/node_exporter /usr/local/bin/
16chown node_exporter:node_exporter /usr/local/bin/node_exporter
17
18# Clean up
19rm -rf node_exporter-$VERSION.linux-amd64*
20
21# Create systemd service file
22cat <<EOF >/etc/systemd/system/node_exporter.service
23[Unit]
24Description=Prometheus Node Exporter
25Wants=network-online.target
26After=network-online.target
27
28[Service]
29User=node_exporter
30Group=node_exporter
31Type=simple
32ExecStart=/usr/local/bin/node_exporter
33
34[Install]
35WantedBy=default.target
36EOF
37
38# Reload systemd, enable and start service
39systemctl daemon-reexec
40systemctl daemon-reload
41systemctl enable --now node_exporter
42
43# Check status
44systemctl status node_exporter --no-pager
45
46echo "Node Exporter installation complete."
47echo "Access it via http://<server-ip>:9100/metrics"
48