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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

catcti监控linux主机,CentOS7搭建Prometheus 监控Linux主机

發布時間:2025/3/11 linux 56 豆豆
生活随笔 收集整理的這篇文章主要介紹了 catcti监控linux主机,CentOS7搭建Prometheus 监控Linux主机 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

簡介

prometheus可以拆分成多個節點進行指標收集。

安裝prometheus

wget?-c?https://github.com/prometheus/prometheus/releases/download/v2.23.0/prometheus-2.23.0.linux-amd64.tar.gz

tar?zxvf?prometheus-2.23.0.linux-amd64.tar.gz??-C?/opt/

cd?/opt/

ln?-s?prometheus-2.23.0.linux-amd64?prometheus

cat?>?/etc/systemd/system/prometheus.service?<

[Unit]

Description=prometheus

After=network.target

[Service]

Type=simple

WorkingDirectory=/opt/prometheus

ExecStart=/opt/prometheus/prometheus?--config.file="/opt/prometheus/prometheus.yml"

LimitNOFILE=65536

PrivateTmp=true

RestartSec=2

StartLimitInterval=0

Restart=always

[Install]

WantedBy=multi-user.target

EOF

systemctl?daemon-reload

systemctl?enable?prometheus

systemctl?start?prometheus

這里配置的是監聽/opt/prometheus/servers/目錄下的json文件

cat?>?/opt/prometheus/prometheus.yml?<

#?my?globalconfig

global:

scrape_interval:?????15s?#?Setthe?scrape?intervaltoevery?15?seconds.Defaultisevery?1minute.

evaluation_interval:?15s?#?Evaluate?rules?every?15?seconds.?The?defaultisevery?1minute.

#?scrape_timeout?issettotheglobaldefault(10s).

#?Alertmanager?configuration

alerting:

alertmanagers:

-?static_configs:

-?targets:

#?-?alertmanager:9093

#?Loadrules?onceandperiodically?evaluate?them?accordingtotheglobal'evaluation_interval'.

rule_files:

#?-?"first_rules.yml"

#?-?"second_rules.yml"

#?A?scrape?configuration?containing?exactly?one?endpoint?toscrape:

#?Here?it's?Prometheus?itself.

scrape_configs:

#?The?job?nameisaddedasa?label?`job=`toanytimeseries?scrapedfromthis?config.

-?job_name:?'prometheus'

#?metrics_path?defaults?to'/metrics'

#?scheme?defaults?to'http'.

static_configs:

-?targets:?['localhost:9090']

-?job_name:?'servers'

file_sd_configs:

-?refresh_interval:?61s

files:

-?/opt/prometheus/servers/*.json

EOF

systemctl?restart?prometheus

json格式

每個json文件需要是一個數組對象,如果不需要自定義標簽,可以直接寫到targets里面去也可以,可以有多個文件

[

{

"targets":?[

"192.168.1.164:9100"

],

"labels":?{

"instance":"192.168.1.164",

"job":"node_exporter"

}

},

{

"targets":?[

"192.168.1.167:9100"

],

"labels":?{

"instance":"192.168.1.167",

"job":"node_exporter"

}

}

]

安裝node_exporter

安裝到/opt/node_exporter路徑下,保持默認的端口

https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz

tar?zxvf?node_exporter-1.0.1.linux-amd64.tar.gz?-C?/opt/

cd?/opt/

ln?-s??node_exporter-1.0.1.linux-amd64?node_exporter

cat?>?/etc/systemd/system/node_exporter.service?<

[Unit]

Description=node_exporter

After=network.target

[Service]

Type=simple

WorkingDirectory=/opt/node_exporter

ExecStart=/opt/node_exporter/node_exporter

LimitNOFILE=65536

PrivateTmp=true

RestartSec=2

StartLimitInterval=0

Restart=always

[Install]

WantedBy=multi-user.target

EOF

systemctl?daemon-reload

systemctl?enable?node_exporter

systemctl?start?node_exporter

圖形展示

直接安裝grafana進行展示

yum?-y?install???https://dl.grafana.com/oss/release/grafana-7.3.6-1.x86_64.rpm

systemctl?enable?grafana-server

systemctl?start?grafana-server

啟動之后,grafana默認監聽的是3000端口,直接使用瀏覽器進行訪問就可以了,默認用戶名密碼是admin/admin,第一次登陸之后會提示修改。

配置數據源:鼠標左邊的菜單 Configuration -> Data Source -> Add data source -> 選擇prometheus -> url那欄填入prometheus的地址就可以了 -> 最后 Save & test 就可以了。

grafana.com/grafana/dashboards 官網已經有人做好的模板,我們直接import進來就可以了。

導入面板:鼠標左邊的菜單 Dashboards -> Import -> 填入id -> Load -> 選擇數據源就可以了。

我經常用的是:1860 、8919 這兩個來查看node_exporter監控

總結

安裝這些服務都是使用systemd進行管理的,操作起來比較方便的。

這里沒有設置告警,可以根據自己的需要設置對應的告警規則,使用alertmanager進行告警。

總結

以上是生活随笔為你收集整理的catcti监控linux主机,CentOS7搭建Prometheus 监控Linux主机的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。