1. 程式人生 > 其它 >企業級監控 - Prometheus部署

企業級監控 - Prometheus部署

Prometheus 是由 SoundCloud 開源監控告警解決方案,由時序資料方式進行儲存,以時間維度儲存連續的資料的集合。

服務端部署

下載安裝Prometheus(https://prometheus.io/download/ )

[root@centos-prometheus ~]# wgethttps://github.com/prometheus/prometheus/releases/download/v2.31.1/prometheus-2.31.1.linux-amd64.tar.gz
[root@centos-prometheus ~]# tar zxf prometheus-2.31.1.linux-amd64.tar.gz
[root@centos-prometheus ~]# mkdir -p/opt/prometheus
[root@centos-prometheus ~]# mv prometheus-2.31.1.linux-amd64 /opt/prometheus/prometheus
[root@centos-prometheus ~]# groupadd prometheus && useradd -g prometheus prometheus -d /opt/prometheus/

配置成系統服務

[root@centos-prometheus ~]# vim /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
User=prometheus
ExecStart=/opt/prometheus/prometheus/bin/prometheus --config.file=/opt/prometheus/prometheus/conf/prometheus.yml --storage.tsdb.path=/opt/prometheus/prometheus/data
Restart=on-failure

[Install]
WantedBy=multi-user.target

配置資料目錄及配置檔案

[root@centos-prometheus ~]# mkdir /opt/prometheus/prometheus/{data,conf,bin}
[root@centos-prometheus ~]# cd/opt/prometheus/prometheus/
[root@centos-prometheus prometheus]#mvprometheuspromtool bin/
[root@centos-prometheus prometheus]#mvprometheus.ymlconf/
[root@centos-prometheus prometheus]#chown prometheus:prometheus /opt/prometheus/prometheus/data
[root@centos-prometheus prometheus]#ln -s /opt/prometheus/prometheus/conf /etc/prometheus

啟動Prometheus

[root@centos-prometheus ~]# systemctl daemon-reload
[root@centos-prometheus ~]# systemctl start prometheus.service
[root@centos-prometheus ~]# systemctl enable prometheus.service

檢視啟動狀態並訪問測試

[root@centos-prometheus ~]# netstat -lntp | grep prometheus
tcp6  0  0  :::9090    :::*    LISTEN    29320/prometheus

瀏覽器訪問:http://172.16.1.10:9090


部署node_exporter(主機監控)

下載安裝node_exporter(https://prometheus.io/download/)

[root@centos-prometheus ~]#wgethttps://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz
[root@centos-prometheus ~]# tar zxf node_exporter-1.2.2.linux-amd64.tar.gz
[root@centos-prometheus ~]# mv node_exporter-1.2.2.linux-amd64 /opt/prometheus/node_exporter

配置成系統服務

[root@centos-prometheus ~]# vim /etc/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
ExecStart=/opt/prometheus/node_exporter/node_exporter
Restart=on-failure

[Install]
WantedBy=multi-user.target

啟動node_exporter服務

[root@centos-prometheus ~]# systemctl daemon-reload
[root@centos-prometheus ~]# systemctl start node_exporter.service
[root@centos-prometheus ~]# systemctl enable node_exporter.service

檢視啟動狀態並訪問:http://172.16.1.10:9100/metrics

[root@centos-prometheus ~]# netstat -lntp | grep node_exporter
tcp6  0  0  :::9100    :::*    LISTEN    30096/node_exporter

部署blackbox_exporter(黑盒監控)

GitHub主頁:https://github.com/prometheus/blackbox_exporter
下載地址:https://github.com/prometheus/blackbox_exporter/releases

下載安裝blackbox_exporter

[root@centos-prometheus ~]#https://github.com/prometheus/blackbox_exporter/releases/download/v0.19.0/blackbox_exporter-0.19.0.linux-amd64.tar.gz
[root@centos-prometheus ~]# tar zxf blackbox_exporter-0.19.0.linux-amd64.tar.gz
[root@centos-prometheus ~]# mv blackbox_exporter-0.19.0.linux-amd64 /opt/prometheus/blackbox_exporter

配置成系統服務

[root@centos-prometheus ~]# vim /etc/systemd/system/blackbox_exporter.service
[Unit]
Description=blackbox_exporter
After=network.target

[Service]
WorkingDirectory=/opt/prometheus/blackbox_exporter
ExecStart=/opt/prometheus/blackbox_exporter/blackbox_exporter \
  --config.file=/opt/prometheus/blackbox_exporter/blackbox.yml

[Install]
WantedBy=multi-user.target

啟動黑盒監控

[root@centos-prometheus ~]# systemctl start blackbox_exporter.service
[root@centos-prometheus ~]# systemctl enable blackbox_exporter.service