日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

第一章 Promethus(普罗米修斯)监控系统

發(fā)布時(shí)間:2023/12/15 综合教程 49 生活家
生活随笔 收集整理的這篇文章主要介紹了 第一章 Promethus(普罗米修斯)监控系统 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

能夠安裝prometheus服務(wù)器
能夠通過安裝node_exporter監(jiān)控遠(yuǎn)程linux
能夠通過安裝mysqld_exporter監(jiān)控遠(yuǎn)程mysql數(shù)據(jù)庫
能夠安裝grafana
能夠在grafana添加prometheus數(shù)據(jù)源
能夠在grafana添加監(jiān)控cpu負(fù)載的圖形
能夠在grafana圖形顯示mysql監(jiān)控?cái)?shù)據(jù)

一、概述

Prometheus(由go語言(golang)開發(fā))是一套開源的監(jiān)控&報(bào)警&時(shí)間序列數(shù)據(jù)庫的組合。適合監(jiān)控docker容器。因?yàn)閗ubernetes(俗稱k8s)的流行帶動(dòng)了prometheus的發(fā)展。

二、時(shí)間序列數(shù)據(jù)

1.含義

時(shí)間序列數(shù)據(jù)(TimeSeries Data) : 按照時(shí)間順序記錄系統(tǒng)、設(shè)備狀態(tài)變化的數(shù)據(jù)被稱為時(shí)序數(shù)據(jù)。

2.特點(diǎn)

#1.性能好
  關(guān)系型數(shù)據(jù)庫對(duì)于大規(guī)模數(shù)據(jù)的處理性能糟糕。NOSQL可以比較好的處理大規(guī)模數(shù)據(jù),讓依然比不上時(shí)間序列數(shù)據(jù)庫。

#2.成本低
  高效的壓縮算法,節(jié)省存儲(chǔ)空間,有效降低IO
  
#3.高效的時(shí)間序列數(shù)據(jù)存儲(chǔ)方法
  Prometheus有著非常高效的時(shí)間序列數(shù)據(jù)存儲(chǔ)方法,每個(gè)采樣數(shù)據(jù)僅僅占用3.5byte左右空間,上百萬條時(shí)間序列,30秒間隔,保留60天,大概花了200多G(來自官方數(shù)據(jù)) 

3.特征

- 多維度數(shù)據(jù)模型
- 靈活的查詢語言(PromQL)
- 不依賴分布式存儲(chǔ),單個(gè)服務(wù)器節(jié)點(diǎn)是自治的
- 以HTTP方式,通過pull模型拉去時(shí)間序列數(shù)據(jù)
- 也可以通過中間網(wǎng)關(guān)支持push模型
- 通過服務(wù)發(fā)現(xiàn)或者靜態(tài)配置,來發(fā)現(xiàn)目標(biāo)服務(wù)對(duì)象
- 支持多種多樣的圖表和界面展示

三、部署Promethus

1.環(huán)境設(shè)置

名稱 公網(wǎng)IP 內(nèi)網(wǎng)IP 主機(jī)名
Prometheus、Grafana、node_exporter 139.196.79.176 172.19.90.51 ga002
node_exporter 139.224.227.189 172.19.72.206 ga001
node_exporter 139.224.223.153 172.19.72.207 gw001
node_exporter、mysqld_exporter 47.100.226.16 172.19.54.147 gd001
node_exporter 47.102.86.70 172.19.90.50 ga003

2.下載相關(guān)軟件(全部安裝在/opt路徑)

從 https://prometheus.io/download/ 下載相應(yīng)版本,安裝到服務(wù)器上官網(wǎng)提供的是二進(jìn)制版,解壓就能用,不需要編譯。

[root@ga002 ~]# cd /opt
[root@ga002 opt]# wget https://github.com/prometheus/prometheus/releases/download/v2.26.0/prometheus-2.26.0.linux-amd64.tar.gz
[root@ga002 opt]# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
[root@ga002 opt]# wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz
[root@ga002 opt]# wget https://dl.grafana.com/oss/release/grafana-7.5.5-1.x86_64.rpm 

3.安裝Promethus

#1.解壓Promethus安裝包到/opt目錄下
[root@ga002 opt]# tar xf prometheus-2.26.0.linux-amd64.tar.gz -C /opt

#2.創(chuàng)建Prometheus數(shù)據(jù)存儲(chǔ)路徑
[root@ga002 opt]# mkdir /data/prometheus

#3.配置數(shù)據(jù)源
[root@ga002 opt]# vim /opt/prometheus-2.17.1.linux-amd64/prometheus.yml 
修改job內(nèi)容,并且保存

scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['ga002:9090']
    
#4.創(chuàng)建system啟動(dòng)
[root@ga002 opt]# vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=root
Restart=on-failure
ExecStart=/opt/prometheus-2.26.0.linux-amd64/prometheus --config.file=/opt/prometheus-2.26.0.linux-amd64/prometheus.yml --storage.tsdb.path=/data/prometheus --storage.tsdb.retention=60d
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF

或者直接啟動(dòng)
[root@ga001 opt]# nohup /opt/prometheus-2.26.0.linux-amd64/prometheus --config.file=/opt/prometheus-2.26.0.linux-amd64/prometheus.yml --storage.tsdb.path=/data/prometheus --storage.tsdb.retention=60d &amp;

#5.啟動(dòng)服務(wù)
[root@ga002 opt]# systemctl daemon-reload
[root@ga002 opt]# systemctl enable --now prometheus

#6.查看服務(wù)狀態(tài)以及端口
[root@ga002 opt]# systemctl status prometheus

[root@ga002 opt]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp6       0      0 :::9090                 :::*                    LISTEN      3373/prometheus

4.測(cè)試連接

在瀏覽器上輸入:`http://服務(wù)器IP:9090`,出現(xiàn)如下頁面及表示啟動(dòng)成功。
http://139.196.79.176:9090

默認(rèn)只監(jiān)控了本機(jī)一臺(tái),點(diǎn)`Status --&gt;`點(diǎn)`Targets --&gt;`可以看到只監(jiān)控了本機(jī)。

通過`http://服務(wù)器IP:9090/metrics`可以查看到監(jiān)控的數(shù)據(jù),在web主界面可以通過關(guān)鍵字查詢監(jiān)控項(xiàng)
http://139.196.79.176:9090/metrics

5.安裝node_exporter監(jiān)控服務(wù)器信息

#被監(jiān)控端都要執(zhí)行,這里ga001為例

#1.下載node_exporter安裝包
[root@ga001 ~o]# cd /opt
[root@ga001 opt]# wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz

#2.解壓node_exporter安裝包
[root@ga001 opt]# tar -xf node_exporter-1.1.2.linux-amd64.tar.gz 

#3.創(chuàng)建system啟動(dòng)
[root@ga001 opt]# vim /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=root
ExecStart=/opt/node_exporter-1.1.2.linux-amd64/node_exporter
[Install]
WantedBy=default.target

或者直接啟動(dòng)
[root@ga001 opt]# nohup /opt/node_exporter-1.1.2.linux-amd64/node_exporter &amp;

#4.啟動(dòng)服務(wù)
[root@ga001 opt]# systemctl daemon-reload
[root@ga001 opt]# systemctl enable --now node_exporter

#5.查看服務(wù)狀態(tài)以及端口
[root@ga001 opt]# systemctl status node_exporter

[root@ga001 opt]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp6       0      0 :::9100                 :::*                    LISTEN      28829/node_exporter

6.測(cè)試連接

通過瀏覽器訪問`http://被監(jiān)控端IP:9100/metrics`就可以查看到node_exporter在被監(jiān)控端收集的監(jiān)控信息。
http://139.224.227.189:9100/metrics

7.配置Prometheus數(shù)據(jù)源

#1.配置Prometheus數(shù)據(jù)源
[root@ga002 opt]# vim /opt/prometheus-2.17.1.linux-amd64/prometheus.yml 
添加如下job內(nèi)容,并且保存
  - job_name: 'node_exporter' # 添加內(nèi)容
    metrics_path: /metrics
    static_configs:
      - targets: ['ga002:9100','gd001:9100','ga001:9100','gw001:9100','ga003:9100'] # 多個(gè)監(jiān)控?cái)?shù)據(jù)源則 后?繼續(xù)添加,數(shù)組形式'a','b'
改完配置文件后,重啟服務(wù)

#2.重啟服務(wù)
[root@ga002 opt]# systemctl restart prometheus

#3.驗(yàn)證服務(wù)
[root@ga002 opt]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp6       0      0 :::9100                 :::*                    LISTEN      21944/node_exporter
tcp6       0      0 :::9090                 :::*                    LISTEN      3373/prometheus

回到web管理界面 --&gt; 點(diǎn)`Status --&gt; 點(diǎn)Targets` --&gt; 可以看到多了四臺(tái)監(jiān)控目標(biāo)

8.安裝mysqld_exporter監(jiān)控MySQL

#在被管理機(jī)gd001上安裝mysqld_exporter組件
#1.下載mysqld_exporter安裝包
[root@gd001 ~o]# cd /opt
[root@gd001 opt]#  wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz

#2.解壓mysqld_exporter安裝包
[root@gd001 opt]# tar -xf mysqld_exporter-0.12.1.linux-amd64.tar.gz 

#3.數(shù)據(jù)庫授權(quán)
[root@gd001 opt]# mysql
mysql &gt; GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'mysqlexporter'@'localhost' identified by '*************';
mysql &gt; GRANT SELECT ON performance_schema.* TO 'mysqlexporter'@'localhost';
mysql &gt; flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql &gt; quit;
Bye
# (注意:授權(quán)ip為localhost,因?yàn)椴皇莗rometheus服務(wù)器來直接找mysql獲取數(shù)據(jù),而是prometheus服務(wù)器找mysql_exporter,mysql_exporter 再找mysql。所以這個(gè)localhost是指的mysql_exporter的IP)

#4.創(chuàng)建一個(gè)mysql配置文件,寫上連接的用戶名與密碼(和上面的授權(quán)的用戶名 和密碼要對(duì)應(yīng))
[root@gd001 opt]# vim /opt/mysqld_exporter-0.12.1.linux-amd64/.my.cnf
[client]
user=mysqlexporter
password=mysqlexporter@dataxgroup

#5.創(chuàng)建system啟動(dòng)mysqld_exporter
[root@gd001 opt]# vim /etc/systemd/system/mysql_exporter.service
#添加如下內(nèi)容
[Unit]
Description=Mysql Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=root
ExecStart=/opt/mysqld_exporter-0.12.1.linux-amd64/mysqld_exporter --config.my-cnf=/opt/mysqld_exporter-0.12.1.linux-amd64/.my.cnf
[Install]
WantedBy=default.target

或者直接命令行啟動(dòng):
[root@gd001 opt]# nohup /opt/mysqld_exporter-0.12.1.linux-amd64/mysqld_exporter --config.my-cnf=/opt/mysqld_exporter-0.12.1.linux-amd64/.my.cnf &amp;

#6.重載并啟動(dòng)服務(wù)
[root@gd001 opt]# systemctl daemon-reload
[root@gd001 opt]# systemctl enable --now mysql_exporter
[root@gd001 opt]# systemctl status mysql_exporter

#7.查看服務(wù)狀態(tài),確認(rèn)端口(9104)
[root@gd001 ~]# netstat  -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2260/sshd
tcp6       0      0 :::3306                 :::*                    LISTEN      2133/mysqld
tcp6       0      0 :::9100                 :::*                    LISTEN      28829/node_exporter
tcp6       0      0 :::9104                 :::*                    LISTEN      1894/mysqld_exporte

#8.回到prometheus服務(wù)器的配置文件里添加被監(jiān)控的mysql的配置段
[root@ga002 opt]# vim /opt/prometheus-2.17.1.linux-amd64/prometheus.yml 
 # 最后加上以下內(nèi)容
 - job_name: 'mysql_exporter'
    metrics_path: /metrics
    static_configs:
      - targets: ['gd001:9104']
        labels:
          instance: gatorade

#9.重啟prometheus
[root@gd001 opt]# systemctl restart prometheus

#10.web界面驗(yàn)證服務(wù)

9.最終Prometheus監(jiān)控效果

四、Grafana學(xué)習(xí)

1.什么是Grafana

Grafana是一個(gè)開源的度量分析和可視化工具,可以通過將采集的數(shù)據(jù)分析,查詢,然后進(jìn)行可視化的展示,并能實(shí)現(xiàn)報(bào)警。

2.使用Grafana連接Prometheus

#1.下載grafana
[root@ga002 ~]# cd /opt
[root@ga002 opt]# wget https://dl.grafana.com/oss/release/grafana-7.5.5-1.x86_64.rpm 

#2.安裝grafana
[root@ga002 opt]# yum install grafana-7.5.5-1.x86_64.rpm

#3.啟動(dòng)服務(wù)
[root@ga002 opt]# systemctl enable --now grafana-server

3.web界面訪問驗(yàn)證

通過瀏覽器訪問 `http:// grafana服務(wù)器IP:3000`就到了登錄界面,使用默認(rèn)的admin用戶,admin密碼就可以登陸了。
http://139.196.79.176:3000

4.添加Prometheus數(shù)據(jù)源

下面我們把prometheus服務(wù)器收集的數(shù)據(jù)做為一個(gè)數(shù)據(jù)源添加到grafana,讓grafana可以得到prometheus的數(shù)據(jù)。

5.監(jiān)控node_exporter節(jié)點(diǎn)

1.配置數(shù)據(jù)源后導(dǎo)入監(jiān)控node_exporter節(jié)點(diǎn)的模板,
填寫模板ID 11074 對(duì)應(yīng)link https://grafana.com/grafana/dashboards/11074

2.點(diǎn)擊grafana圖標(biāo),點(diǎn)擊home,選擇Node Exporter for Prometheus Dashboard EN v20191102 

3.最終顯示界面如下:

6.監(jiān)控MYSQL節(jié)點(diǎn)(mysqld_exporter)

1)配置數(shù)據(jù)源

2)選擇mysql數(shù)據(jù)庫

3)添加如下配置,并保存

4)導(dǎo)?MySQL監(jiān)控模板 7362

5)查看mysql界面

7.另一種方式監(jiān)控mysql節(jié)點(diǎn)

在grafana上修改配置文件,并下載安裝mysql監(jiān)控的dashboard(包含相關(guān)**json**文件,這些json文件可以看作是開發(fā)人員開發(fā)的一個(gè)監(jiān)控模板)

[root@ga002 opt]# vim /etc/grafana/grafana.ini 
[dashboards.json]
enabled=true
path=/var/lib/grafana/dashboards


[root@ga002 ~]# cd /var/lib/grafana/ 
[root@ga002 grafana]# git clone https://github.com/percona/grafana-dashboards.git 
[root@ga002 grafana]# cp -r grafana-dashboards/dashboards/ /var/lib/grafana/ 重啟grafana服務(wù) 
[root@ga002 grafana]# systemctl restart grafana-server
                                                                                                                                                                                                                                                                      </job_name>

總結(jié)

以上是生活随笔為你收集整理的第一章 Promethus(普罗米修斯)监控系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。