安裝環境
- OS: Oracle Linux 9, Debian 12
- 測試版本: 1.8.2
安裝步驟
01. 新增帳號
sudo groupadd --system -g 800 prometheus &&\
sudo useradd -s /sbin/nologin --system -g prometheus --uid 800 -c "prometheus_exporter" prometheus
02. 下載 Node Exporter 及部署程式
下載 Node Exporter
curl -s https://api.github.com/repos/prometheus/node_exporter/releases/latest| grep browser_download_url|grep linux-amd64|cut -d '"' -f 4|wget -i -
# https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz
部署程式
tar -xvf node_exporter*.tar.gz &&\
cd node_exporter*/ &&\
sudo cp node_exporter /usr/local/bin &&\
sudo chown prometheus: /usr/local/bin/node_exporter
03. 將 context path 作為識別主機
這邊我們將 context path 作為識別主機 依據,會把設定寫入參數檔。RedHat 與 Debian 放的位置會稍微不一樣
- Redhat
sudo tee /etc/sysconfig/node_exporter <<EOF
OPTIONS="--web.telemetry-path=\"/$(hostname)/node/metrics\""
EOF
- Debian
sudo tee /etc/node_exporter <<EOF
OPTIONS="--web.telemetry-path=\"/$(hostname)/node/metrics\""
EOF
04. 設定 systemctl deamon
sudo tee /etc/systemd/system/node_exporter.service<<EOF
[Unit]
Description=Node Exporter
[Service]
User=prometheus
Group=prometheus
UMask=0027
EnvironmentFile=-/etc/node_exporter
EnvironmentFile=-/etc/sysconfig/node_exporter
ExecStart=/usr/local/bin/node_exporter \$OPTIONS
[Install]
WantedBy=multi-user.target
EOF
立即啟用 及開機時啟動
sudo systemctl daemon-reload &&\
sudo systemctl enable --now node_exporter &&\
sudo systemctl status node_exporter
05. 檢查下載有東西
curl -i 127.0.0.1:9100/$(hostname)/node/metrics
結果如下
jameschang@loki:~/node_exporter-1.3.1.linux-amd64$ curl localhost:9100/metrics > /dev/null
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 63048 0 63048 0 0 6157k 0 --:--:-- --:--:-- --:--:-- 6157k
prometheus 主機設定
- 修改 /usr/local/etc/prometheus/prometheus.yml
sudo systemctl restart prometheus
sudo systemctl reload prometheus
http://192.168.56.3:9090/targets
檢查有成功
匯入別人寫好的面板
https://grafana.com/grafana/dashboards/11074
參考資料
How to Monitor Linux Servers with Prometheus and Node Exporter