国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

Prometheus簡(jiǎn)單搭建

發(fā)布時(shí)間:2023-05-25 09:10 來(lái)源:西部 閱讀:189 作者:西部數碼 欄目: 虛擬主機 歡迎投稿:712375056

系統運維

一.Prometheus介紹
Prometheus(普羅米修斯)是一個(gè)最初在SoundCloud上構建的監控系統。自2012年成為社區開(kāi)源項目,擁有非?;钴S的開(kāi)發(fā)人員和用戶(hù)社區。為強調開(kāi)源及獨立維護,Prometheus于2016年加入云原生云計算基金會(huì )(CNCF),成為繼Kubernetes之后的第二個(gè)托管項目。
http://wap.friendlycc.com.cn/host/

作為新一代的監控框架,Prometheus 具有以下特點(diǎn):
? 多維數據模型:由度量名稱(chēng)和鍵值對標識的時(shí)間序列數據
? PromSQL:一種靈活的查詢(xún)語(yǔ)言,可以利用多維數據完成復雜的查詢(xún)
? 不依賴(lài)分布式存儲,單個(gè)服務(wù)器節點(diǎn)可直接工作
? 基于HTTP的pull方式采集時(shí)間序列數據
? 推送時(shí)間序列數據通過(guò)PushGateway組件支持
? 通過(guò)服務(wù)發(fā)現或靜態(tài)配置發(fā)現目標
? 多種圖形模式及儀表盤(pán)支持
Prometheus適用于以機器為中心的監控以及高度動(dòng)態(tài)面向服務(wù)架構的監控。

二.Prometheus部署
轉載:http://wap.friendlycc.com.cn/host/ 主節點(diǎn) 190.168.3.250
server2:centos7.6 節點(diǎn)1 190.168.3.251

為您的平臺下載最新版本的Prometheus,然后解壓縮并運行它:

http://wap.friendlycc.com.cn/host/

http://wap.friendlycc.com.cn/host/

2.二進(jìn)制安裝
tar xvfz prometheus-2.15.0.linux-amd64.tar.gz
cd prometheus-2.15.0.linux-amd64
mv prometheus-2.15.0.linux-amd64 /usr/local/prometheus

啟動(dòng)
./prometheus –config.file=prometheus.yml

為了方便,加入到服務(wù)配置文件里
vi /usr/lib/systemd/system/prometheus.service
[Unit]
Description=http://wap.friendlycc.com.cn/host/

[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus –config.file=/usr/local/prometheus/prometheus.yml

[Install]
WantedBy=multi-user.target

重啟服務(wù)
systemctl daemon-reload
systemctl start prometheus.service

3.容器安裝
http://wap.friendlycc.com.cn/host/ class="wp_keywordlink_affiliate">docker run -p 9090:9090 -v /tmp/prometheus.yml:/etc/prometheus/prometheus.yml \\
prom/prometheus
或者為配置使用額外的卷:
docker run -p 9090:9090 -v /prometheus-data \\
prom/prometheus –config.file=/prometheus-data/prometheus.yml

4.訪(fǎng)問(wèn)web
http://wap.friendlycc.com.cn/host/

三.配置監控服務(wù)
1.配置Prometheus監控本身
全局配置文件簡(jiǎn)介
有關(guān)配置選項的完整,請參閱:http://wap.friendlycc.com.cn/host/

global:全局配置
alerting:告警配置
rule_files:告警規則
scrape_configs:配置數據源,稱(chēng)為target,每個(gè)target用job_name命名。又分為靜態(tài)配置和服務(wù)發(fā)現

global:
默認抓取周期,可用單位ms、smhdwy #設置每15s采集數據一次,默認1分鐘
[ scrape_interval: <duration> | default = 1m ]
默認抓取超時(shí)
[ scrape_timeout: <duration> | default = 10s ]
估算規則的默認周期 # 每15秒計算一次規則。默認1分鐘
[ evaluation_interval: <duration> | default = 1m ]
和外部系統(例如AlertManager)通信時(shí)為時(shí)間序列或者警情(Alert)強制添加的標簽列表
external_labels:
[ <labelname>: <labelvalue> … ]

規則文件列表
rule_files:
[ – <filepath_glob> … ]

抓取配置列表
scrape_configs:
[ – <scrape_config> … ]

Alertmanager相關(guān)配置
alerting:
alert_relabel_configs:
[ – <relabel_config> … ]
alertmanagers:
[ – <alertmanager_config> … ]

遠程讀寫(xiě)特性相關(guān)的配置
remote_write:
[ – <remote_write> … ]
remote_read:
[ – <remote_read> … ]

vi prometheus.yml
下面就是拉取自身服務(wù)采樣點(diǎn)數據配置
scrape_configs:
別監控指標,job名稱(chēng)會(huì )增加到拉取到的所有采樣點(diǎn)上,同時(shí)還有一個(gè)instance目標服務(wù)的host:port標簽也會(huì )增加到采樣點(diǎn)上

job_name: \’prometheus\’
覆蓋global的采樣點(diǎn),拉取時(shí)間間隔5s
scrape_interval: 5s
static_configs:

targets: [\’localhost:9090\’]

最下面,靜態(tài)配置監控本機,采集本機9090端口數據

注:每次修改配置完成,用promtool檢測配置文件是否正確
[root@server1 prometheus]# ./promtool check config prometheus.yml

重啟服務(wù)
可以用kill -hup 進(jìn)程id 自動(dòng)加載新配置文件

查看targets可以看到節點(diǎn)正常

也可以在這里搜尋收集來(lái)的數據

2.配置服務(wù)發(fā)現監控linux主機及相關(guān)服務(wù)
在server2 190.168.3.251上安裝node_exporter
使用文檔:http://wap.friendlycc.com.cn/host/

在server2安裝節點(diǎn)采集器,mysql服務(wù),nginx服務(wù)
tar zxf node_exporter-0.17.0.linux-amd64.tar.gz
mv node_exporter-0.17.0.linux-amd64 /usr/local/node_exporter
cd /usr/local/node_exporter/
./node_exporter –help

服務(wù)發(fā)現,我們這里使用file_sd_configs,寫(xiě)監控配置文件,服務(wù)發(fā)現node節點(diǎn)

mkdir sd_config創(chuàng )建服務(wù)發(fā)現目錄

寫(xiě)采集地址targets
[root@server1 prometheus]# vi sd_config/node.yml

方便管理服務(wù),將宿主機節點(diǎn)監控采集node_exporter加入到服務(wù)配置文件里,

如果要監控節點(diǎn)的系統服務(wù),需要在后面添加名單參數
–collector.systemd.unit-whitelist=". " 從systemd中循環(huán)正則匹配單元
–collector.systemd.unit-whitelist="(docker|sshd|nginx).service" 白名單,收集目標

/usr/bin/node_exporter –collector.systemd –collector.systemd.unit-whitelist=(docker|sshd|nginx).service

在http://wap.friendlycc.com.cn/host/

補充:
也可以將之前190.168.3.250上監控本機的9090的靜態(tài)采集改成文件服務(wù)發(fā)現的形式

[root@server1 prometheus]# vi sd_config/test.yml ,其中的加上了標簽,添加采集地址,可以在targets里使用標簽查找

四.使用grafana前端展示數據并監控docker服務(wù)

1.cAdvisor采集容器信息
使用cAdvisor(Container Advisor)用于收集正在運行的容器資源使用和性能信息。
docker run \\
–volume=/:/rootfs:ro \\
–volume=/var/run:/var/run:ro \\
–volume=/sys:/sys:ro \\
–volume=/var/lib/docker/:/var/lib/docker:ro \\
–volume=/dev/disk/:/dev/disk:ro \\
–publish=8080:8080 \\
–detach=true \\
–name=cadvisor \\

http://wap.friendlycc.com.cn/host/ 

2.Grafana

http://wap.friendlycc.com.cn/host/

Grafana是一個(gè)開(kāi)源的度量分析和可視化系統,Grafana支持查詢(xún)普羅米修斯。自Grafana 2.5.0(2015-10-28)以來(lái),包含了Prometheus的Grafana數據源。

在官網(wǎng)上下載http://wap.friendlycc.com.cn/host/ run -d –name=grafana -p 3000:3000 grafana/grafana

跑起來(lái)后,190.168.3.250:3000訪(fǎng)問(wèn)web接口
密碼賬號都是admin,第一次登陸需要修改密碼
添加數據源

已經(jīng)有一個(gè)Prometheus數據源

3.添加監控宿主機模板

輸入9276,導入

修改名字和數據庫

完成,查看最后模板效果

4.查看docker監控
添加新job,修改采集配置文件prometheus.yml
[root@server1 prometheus]# vi prometheus.yml

檢查配置文件后,重啟主服務(wù) ./promtool check config prometheus.yml

同樣方法在Grafana下載模板,導入193
也可以在http://wap.friendlycc.com.cn/host/

五.監控Mysql服務(wù)

MYSQL_exporter:用于收集MySQL性能信息。

下載http://wap.friendlycc.com.cn/host/

我們在server2 190.168.3.251上配置,需要下載mysqld_exporter數據庫采集和安裝mariadb

登錄mysql為exporter創(chuàng )建賬號,以便可以采集數據:
mysql> CREATE USER \’exporter\’@\’localhost\’ IDENTIFIED BY \’123456\’;
mysql> GRANT PROCESS, REPLICATION CLIENT, SELECT ON . TO \’exporter\’@\’localhost\’;

vi .my.cnf ,添加用戶(hù)隱藏的數據庫賬號,prometheus監控mysql需要用這個(gè)賬號采集

在server1 190.168.3.250修改采集配置文件
[root@server1 prometheus]# vi prometheus.yml

檢查配置文件并重啟服務(wù),systemctl restart prometheus.service

[root@server2 mysql_exporter]# ./mysqld_exporter –config.my-cnf=.my.cnf

數據庫信息已經(jīng)采集到了
http://wap.friendlycc.com.cn/host/

導入模板后7362后

六.郵件告警
1.告警介紹
在Prometheus平臺中,警報由獨立的組件Alertmanager處理。通常情況下,我們首先告訴Prometheus Alertmanager所在的位置,然后在Prometheus配置中創(chuàng )建警報規則,最后配置Alertmanager來(lái)處理警報并發(fā)送給接收者(郵件,webhook、slack等)。

地址1:http://wap.friendlycc.com.cn/host/ 部署Alertmanager
第二步 配置Prometheus與Alertmanager通信
第三步 在Prometheus中創(chuàng )建告警規則

2.配置Prometheus與Alertmanager通信

需要在官網(wǎng)下載以上的報警包

修改告警媒介,使用郵箱發(fā)送
[root@server1 alertmanager-0.16.0.linux-amd64]# vi alertmanager.yml

注意:上面的驗證密碼不是郵箱密碼,是授權碼

修改完檢查配置文件alertmanager.yml是否正確,然后重啟服務(wù)
./alertmanager –config.file alertmanager.yml
systemctl restart prometheus.service

修改prometheus連接告警模塊,并設定告警規則
[root@server1 prometheus]# vi prometheus.yml

[root@server1 prometheus]# vi rules/test.yml
參照官網(wǎng)告警上寫(xiě)的

groups:

name: example # 報警規則組名稱(chēng)
rules:

alert: InstanceDown
expr: up == 0
for: 1m #持續時(shí)間 , 表示持續一分鐘獲取不到信息,則觸發(fā)報警
labels:
severity: page # 自定義標簽
annotations:
summary: "Instance {{ $labels.instance }} down" # 自定義摘要
description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes." # 自定義具體描述

3.測試郵箱告警
我們把server2 上的mysql監控關(guān)閉,測試告警
http://wap.friendlycc.com.cn/host/

我們看郵箱,收到報警

更多關(guān)于云服務(wù)器,域名注冊,虛擬主機的問(wèn)題,請訪(fǎng)問(wèn)特網(wǎng)科技官網(wǎng):wap.friendlycc.com.cn

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。

国产又猛又黄又爽| 野狼AV午夜福利在线| 亚洲国产最新av片| 国产亚洲精品BT天堂精选| 伊人成色综合网| 嫩草在线视频WWW免费看|