Monitor
Prometheus ¶
useradd -s /sbin/nologin -m -d /data/prometheus -r prometheus chown -R prometheus:prometheus /data/prometheus/
mkdir -p /data/prometheus && cd !$
wget https://github.com/prometheus/prometheus/releases/download/v2.25.0/prometheus-2.25.0.linux-amd64.tar.gz
cat >> /usr/lib/systemd/system/prometheus.service <<EOF
[Unit]
Description=Prometheus Monitoring System
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=prometheus
LimitNOFILE=10000
ExecStart=/data/prometheus/prometheus \
--config.file=/data/prometheus/prometheus.yml \
--storage.tsdb.path=/data/prometheus/data
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/bin/kill -9 $MAINPID
TimeoutStopSec=50
Restart=on-failure
RestartPreventExitStatus=1
RestartSec=2
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload && systemctl enable --now prometheus
Node_exporter ¶
wget https://github.com/prometheus/node_exporter/releases/download/v1.1.1/node_exporter-1.1.1.linux-amd64.tar.gz
cat > /usr/lib/systemd/system/node_exporter.service <<EOF
[Unit]
Description=Node Exporter Monitor
After=network.target local-fs.target
[Service]
Type=simple
User=prometheus
LimitNOFILE=1048576
LimitCORE=infinity
ExecStart=/data/prometheus/node_exporter --web.listen-address=0.0.0.0:9100
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -9 $MAINPID
TimeoutStopSec=300
Restart=on-failure
RestartPreventExitStatus=1
RestartSec=2
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload && systemctl enable --now nodeexporter
Alertmanager ¶
wget https://github.com/prometheus/alertmanager/releases/download/v0.21.0/alertmanager-0.21.0.linux-amd64.tar.gz
cat > /usr/lib/systemd/system/alertmanager.service <<EOF
[Unit]
Description=Alertmanager
After=network.target local-fs.target
[Service]
Type=simple
User=prometheus
LimitNOFILE=1048576
LimitCORE=infinity
ExecStart=/data/prometheus/alertmanager \
--config.file=/data/prometheus/alertmanager.yml \
--web.listen-address=0.0.0.0:9093 \
--log.level=debug
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -9 $MAINPID
TimeoutStopSec=300
Restart=on-failure
RestartPreventExitStatus=1
RestartSec=2
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload && systemctl enable --now alertmanager