CentOS7 下部署Prometheus+Grafana+node_exporter+blackbox_exporter監(jiān)控
一究恤、環(huán)境
監(jiān)控端(192.168.20.13)安裝:Prometheus+Grafana
被監(jiān)控端(39.96.187.128)安裝:node_exporter+blackbox_exporter
二悟衩、軟件包下載
https://prometheus.io/download/
(統(tǒng)一下載到 /soft)
node_exporter下載:
Wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
prometheus下載:
Wget https://github.com/prometheus/prometheus/releases/download/v2.14.0/prometheus-2.14.0.linux-amd64.tar.gz
blackbox_exporter下載:
Wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.16.0/blackbox_exporter-0.16.0.linux-amd64.tar.gz
grafana下載:
https://dl.grafana.com/oss/release/grafana-6.5.1-1.x86_64.rpm
三埋哟、Prometheus安裝及配置
1践叠、解壓安裝包
mkdir -p / software/prometheus
groupadd prometheus
useradd -g prometheus prometheus -d /software/Prometheus
tar -zxvf prometheus-2.14.0.linux-amd64.tar.gz
cd prometheus-2.14.0.linux-amd64/
mv * /software/prometheus/
cd /software/prometheus/
mkdir {data,cfg,logs,bin} -p
mv prometheus promtool bin/
mv prometheus.yml cfg/
chown -R prometheus.prometheus *
2、設(shè)置環(huán)境變量
vim /etc/profile
PATH=/software/prometheus/bin:$PATH:$HOME/bin
3映皆、使變量生效
source /etc/profile
4租幕、創(chuàng)建prometheus.service 的 systemd unit 文件
vim /etc/systemd/system/prometheus.service
內(nèi)容:
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/software/prometheus/bin/prometheus --config.file=/software/prometheus/cfg/prometheus.yml --storage.tsdb.path=/software/prometheus/data
Restart=on-failure
[Install]
WantedBy=multi-user.target
5、prometheus.yml配置文件
6着倾、啟動服務(wù)
systemctl daemon-reload
systemctl enable prometheus.service
systemctl start prometheus.service
7拾酝、運行狀態(tài)
Prometheus自帶有簡單的UI, http://192.168.20.13:9090/targets
四、node_exporter安裝及配置
1卡者、解壓安裝包
mkdir -p /software
mkdir -p /software/prometheus
cd /soft
tar -zxvf node_exporter-0.18.1.linux-amd64.tar.gz -C /software/prometheus/
cd /software/prometheus/
mv node_exporter-0.18.1.linux-amd64 node_exporter
2蒿囤、創(chuàng)建用戶
groupadd prometheus
useradd -g prometheus prometheus -d /software/prometheus
chown -R prometheus.prometheus node_exporter
3、創(chuàng)建node_exporter.service的 systemd unit 文件
vim /usr/lib/systemd/system/node_exporter.service
內(nèi)容:
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/software/prometheus/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
4崇决、啟動服務(wù)
systemctl daemon-reload
systemctl enable node_exporter.service
systemctl start node_exporter.service
5材诽、運行狀態(tài)
6、客戶監(jiān)控端數(shù)據(jù)匯報
訪問: http://192.168.20.13:9100/metrics嗽桩,查看從exporter具體能抓到的數(shù)據(jù).如下 :
訪問: http://192.168.20.196:9100/metrics岳守,查看從exporter具體能抓到的數(shù)據(jù).如下 :
五、blackbox_exporter安裝及配置
1碌冶、安裝
cd /software
tar -zxvf blackbox_exporter-0.16.0.linux-amd64.tar.gz -C /software/prometheus/
cd /software/prometheus/
mv blackbox_exporter-0.16.0.linux-amd64 blackbox_exporter
2湿痢、創(chuàng)建用戶
chown -R prometheus.prometheus blackbox_exporter
3、驗證安裝是否成功
cd /software/Prometheus/blackbox_exporter
./blackbox_exporter --version
![image.png](https://upload-images.jianshu.io/upload_images/26078328-e32be51c15b16633.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
4扑庞、創(chuàng)建systemd服務(wù)
vim /usr/lib/systemd/system/blackbox_exporter.service
內(nèi)容:
Description=blackbox_exporter
Documentation=https://prometheus.io/
After=network.target
Type=simple
User=prometheus
ExecStart=/software/prometheus/blackbox_exporter/blackbox_exporter --config.file=/software/prometheus/blackbox_exporter/blackbox.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
5譬重、啟動服務(wù)
systemctl daemon-reload
systemctl enable blackbox_exporter.service
systemctl start blackbox_exporter.service
六、Grafana安裝及配置
1罐氨、安裝
yum localinstall grafana-6.5.1-1.x86_64.rpm
2臀规、啟動服務(wù)
systemctl daemon-reload
systemctl enable grafana-server.service
systemctl start grafana-server.service
3、訪問WEB界面
默認(rèn)賬號/密碼:admin/admin
①add data source
②填寫信息栅隐,點擊“save&test”塔嬉,如果成功,會有綠色的提示
③創(chuàng)建dashboard
③創(chuàng)建dashboard
④導(dǎo)入json文件
實現(xiàn)可視化我們可以直接使用現(xiàn)成的模板
硬件監(jiān)控:1-node-exporter-for-prometheus-dashboard-update-1102_rev11.json
進程監(jiān)控:2 Blackbox Exporter 0.14 for Prometheus 監(jiān)控展示看板-1575517197953.json
七租悄、關(guān)于Prometheus的配置文件
1谨究、注意事項
①嚴(yán)格按照格式進行縮進,否則將導(dǎo)致配置文件無效泣棋。
②job_name不能重復(fù)胶哲,否則將導(dǎo)致Prometheus啟動不了。
2潭辈、node_exporter部分的格式
例子:
- job_name: 'node_39.96.187.128'
static_configs:- targets: ['39.96.187.128:9100']
labels:
instance: '39.96.187.128'
- targets: ['39.96.187.128:9100']
效果:
3鸯屿、blackbox_exporter部分的格式
例子:
- job_name: "blackbox_39.96.187.128"
scrape_interval: 5s
metrics_path: /probe
params:
module: [tcp_connect]
static_configs:
- targets: ['39.96.187.128:9115','39.96.187.128:9100','39.96.187.128:9948','39.96.187.128:9941','39.96.187.128:9951','39.96.187.128:9954','39.96.187.128:9956','39.96.187.128:9936','39.96.187.128:9952','39.96.187.128:9944','39.96.187.128:9942','39.96.187.128:9947','39.96.187.128:9947','39.96.187.128:9966','39.96.187.128:9909','39.96.187.128:8901','39.96.187.128:7777']
labels:
group: '進程監(jiān)控'
relabel_configs:
- source_labels: [address]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: address
replacement: 39.96.187.128:9115
效果: