Grafana+Prometheus打造运维监控系统(一)-安装篇
1. Prometheus、Grafana介紹
Prometheus是一個開源的系統監控和報警系統,Grafana 是一個開源的監控數據分析和可視化套件,利用Grafana+Prometheus組合,打造運維日常的各種指標監控以及數據可視化。
2. Prometheus
2.1 下載
訪問:https://prometheus.io/download/,選擇對應版本,下載保存到服務器中。我這里選擇的是2022-12-01發布的2.40.5版本。
2.2 安裝
解壓到/etc/路徑下,并重命名文件夾名字為prometheus
tar zxvf prometheus-2.40.5.linux-amd64.tar.gz -C /etc/ cd /etc/ mv prometheus-2.40.5.linux-amd64 prometheus2.3 注冊為系統服務并設置開機自啟
vi /usr/lib/systemd/system/prometheus.service,添加如下內容:
[Service] ExecStart=/etc/prometheus/prometheus --config.file=/etc/prometheus/prometheus.yml ExecReload=/bin/kill -HUP $MAINPID KillMode=process Restart=on-failure[Install] WantedBy=multi-user.target[Unit] Description=node_exporter After=network.target systemctl daemon-reload # 重新加載使服務配置文件生效 systemctl enable prometheus # 添加開機自啟 systemctl start prometheus # 啟動Prometheus此時Prometheus已經啟動,默認的訪問端口是9090
關閉防火墻systemctl stop firewalld.service,瀏覽器輸入虛擬機IP:9090,出現如下頁面,代表訪問正常。
3. Grafana
3.1 下載&安裝
訪問:https://grafana.com/grafana/download,選擇對應版本,下載保存到服務器中。我這里選擇的是2022-12-02發布的9.3.1版本,選擇自己對應的Linux發行版本,進行安裝。
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.3.1-1.x86_64.rpm sudo rpm -i --nodeps grafana-enterprise-9.3.1-1.x86_64.rpm
安裝完成后,執行systemctl start grafana-server.service啟動grafana服務,默認監聽的是3000端口,可通過修改/etc/grafana/grafana.ini配置文件進行修改。
如果想修改端口,取消注釋用的;號,并修改3000為你想要的值
瀏覽器輸入虛擬機IP:3000,出現如下頁面,代表訪問正常.
初始賬號:admin
初始密碼:admin
驗證成功后,會要求你輸入新的密碼,也可以點擊skip選擇跳過,我個人為了方便,設置為123456,溫馨提示:生產環境請勿使用簡單密碼哦~!
4. 安裝節點采集器node_exporter
node_exporter可以采集服務器的各種指標,比如CPU、內存、磁盤、網絡等,形成時序數據。
4.1 下載
訪問:https://prometheus.io/download/#node_exporter,選擇對應版本,下載保存到服務器中
4.2 安裝
解壓到/etc/路徑下,并重命名文件夾名字為node_exporter
tar zxvf node_exporter-1.4.0.linux-amd64.tar.gz -C /etc/ cd /etc/ mv node_exporter-1.5.0.linux-amd64/ node_exporter4.3 注冊為系統服務并設置開機自啟
vi /usr/lib/systemd/system/prometheus.service,添加如下內容:
[Service] ExecStart=/etc/node_exporter/node_exporter ExecReload=/bin/kill -HUP $MAINPID KillMode=process Restart=on-failure[Install] WantedBy=multi-user.target[Unit] Description=node_exporter After=network.target systemctl daemon-reload # 重新加載使服務配置文件生效 systemctl enable node_exporter.service # 添加開機自啟 systemctl start node_exporter.service # 啟動此時node_exporter已經啟動,默認的訪問端口是9100
瀏覽器輸入虛擬機IP:9090,出現如下頁面,代表訪問正常。
5. Grafana數據可視化展示
5.1 添加Prometheus抓取任務
vi /etc/prometheus/prometheus.yml,添加如下內容:
- job_name: 'node_exporter'static_configs:- targets: ["localhost:9100"]5.2 重啟Prometheus
systemctl restart prometheus
5.3 添加grafana數據源
左側導航欄,設置–>Datasouces–>Add data souce
選擇Prometheus
URL框輸入:http://localhost:9090,
Save & test,提示Data souce is working,說明添加數據源成功
5.4 添加儀表盤
grafana提供了各式各樣的儀表盤,除了自己手動創建,我們也可以使用別人已經做好的儀表盤進行導入。
左側導航欄,Dashboards–>Import
導入的方式有兩種,第一種是本地上傳json文件;第二種是從grafana導入,但是要指明對應的儀表盤URL或者ID。這里我們選擇第二種方式
訪問:https://grafana.com/grafana/dashboards/,選擇Collector Types為Node exporter,點擊Node Exporter Full進入詳情頁,得到ID為1860
輸入1860,點擊Load進行加載
選擇數據源為Prometheus,點擊Import進行導入。
這樣就得到了一個漂亮的可視化儀表盤了,是不是So Easy呀~!
總結
以上是生活随笔為你收集整理的Grafana+Prometheus打造运维监控系统(一)-安装篇的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: css中的选择器及其权重
- 下一篇: 【开源协议】BSD、Apache2、GP