安裝 Prometheus監控主機服務
一、安裝 Prometheus
下載 Prometheus
首先,訪問 Prometheus 官網 獲取最新版本的下載鏈接,然后使用 wget 下載:
解壓并安裝
解壓下載的文件:
將解壓后的文件夾移動到 /opt/prometheus:
安裝 htpasswd 來生成密碼 hash
在 prometheus目錄下執行
創建配置文件
創建 Prometheus 用戶
為了安全,創建一個專用用戶來運行 Prometheus:
配置 Prometheus
編輯 Prometheus 配置文件 /opt/prometheus/prometheus.yml:
添加以下內容:
創建 Systemd 服務文件 /etc/systemd/system/prometheus.service:
添加以下內容:
啟動并設置開機啟用 Prometheus 服務:
訪問
二、安裝 Node Exporter
Node Exporter 用于收集系統指標(如 CPU、內存使用率)。
下載 Node Exporter
解壓并安裝
在node_exporter目錄下執行
創建配置文件
創建 Systemd 服務
創建 Systemd 服務文件 /etc/systemd/system/node_exporter.service:
添加以下內容:
啟動 Node Exporter
驗證 Node Exporter
訪問 http://<服務器IP>:9100/metrics,如果看到系統指標數據,說明安裝成功。

三、安裝 Grafana
下載并安裝 Grafana
啟動 Grafana服務
web界面訪問
訪問 Grafana
訪問 http://<服務器IP>:3000,使用默認賬號 admin 和密碼 admin 登錄。
四、配置 Grafana 儀表盤
登錄 Grafana,點擊左側菜單的 Configuration > Data Sources。
點擊 Add data source,

選擇 Prometheus

在 URL 中輸入 http://localhost:9090,點擊 Save & Test。


導入 Node Exporter 儀表盤
在 dashboad頁面點擊 Create > Import。

在 Import via grafana.com 中輸入儀表盤 ID 1860(Node Exporter 官方儀表盤)。

選擇 Prometheus 數據源,點擊 Import。

查看儀表盤
導入成功后,你可以看到一個完整的系統監控儀表盤,包含 CPU、內存、磁盤、網絡等指標。


浙公網安備 33010602011771號