0%

Prometheus+Grafana监控系统搭建

相关文档:

1
2
3
4
5
6
7
Prometheus官网:https://prometheus.io/download/
Grafana官网:https://grafana.com/grafana/download
Grafana 模板官网:https://grafana.com/grafana/dashboards
Rules 规则:https://awesome-prometheus-alerts.grep.to/
发送告警模板:https://github.com/prometheus/alertmanager/blob/master/template/default.tmpl
官方文档中文版: https://github.com/Alrights/prometheus
官方监控agent列表: https://prometheus.io/docs/instrumenting/exporters/

安装 Prometheus Server

下载

1
2
wget https://github.com/prometheus/prometheus/releases/download/v2.20.1/prometheus-2.20.1.linux-amd64.tar.gz
tar xzf prometheus-2.20.1.linux-amd64.tar.gz -C /usr/local/prometheus

配置语法校验

1
./promtool check config prometheus.yml

设置prometheus系统服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
vim /usr/lib/systemd/system/prometheus.service

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
# --storage.tsdb.path是可选项,默认数据目录在运行目录的./dada目录中
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.enable-lifecycle --storage.tsdb.path=/data/prometheus --storage.tsdb.retention=30d
Restart=on-failure

[Install]
WantedBy=multi-user.target


#Prometheus启动参数说明
--config.file -- 指明prometheus的配置文件路径
--web.enable-lifecycle -- 指明prometheus配置更改后可以进行热加载
--storage.tsdb.path -- 指明监控数据存储路径
--storage.tsdb.retention --指明数据保留时间

设置开机启动

1
2
3
4
systemctl daemon-reload
systemctl enable prometheus.service
systemctl status prometheus.service
systemctl restart prometheus.service

备注:在启动prometheus时加上参数 web.enable-lifecycle , 可以启用配置的热加载, 配置修改后, 热加载配置

1
curl -X POST  http://localhost:9090/-/reload

安装Grafana

下载安装

1
2
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-7.1.3-1.x86_64.rpm
sudo yum install grafana-enterprise-7.1.3-1.x86_64.rpm

granafa首次登录账户名和密码admin/admin

安装alertmanager

下载

1
2
wget https://github.com/prometheus/alertmanager/releases/download/v0.21.0/alertmanager-0.21.0.linux-amd64.tar.gz
tar xzf alertmanager-0.21.0.linux-amd64.tar.gz -C /usr/local/alertmanager

配置服务

1
2
3
4
5
6
7
8
9
10
11
12
vim /usr/lib/systemd/system/alertmanager.service

[Unit]
Description=Alertmanager
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/alertmanager/alertmanager --config.file=/usr/local/alertmanager/alertmanager.yml --storage.path=/data/alertmanager/
Restart=on-failure
[Install]
WantedBy=multi-user.target

设置服务开机自启动

1
2
systemctl enable alertmanager
systemctl start alertmanager

安装node_exporter

下载

1
2
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
tar xzf node_exporter-1.0.1.linux-amd64.tar.gz -C /usr/local/node_exporter

配置服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
vim /usr/lib/systemd/system/node_exporter.service

[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure

[Install]
WantedBy=multi-user.target

设置服务开机自启动

1
2
systemctl enable node_exporter
systemctl start node_exporter

安装pushgateway

下载

1
2
wget https://github.com/prometheus/pushgateway/releases/download/v1.2.0/pushgateway-1.2.0.linux-amd64.tar.gz
tar xzf pushgateway-1.2.0.linux-amd64.tar.gz -C /usr/local/pushgateway

配置服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
vim /usr/lib/systemd/system/pushgateway.service

[Unit]
Description=pushgateway
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/pushgateway/pushgateway
Restart=on-failure

[Install]
WantedBy=multi-user.target

设置服务开机自启动

1
2
systemctl enable pushgateway
systemctl start pushgateway

安装redis_exporter

下载

1
2
// 下载地址:https://github.com/oliver006/redis_exporter/releases
tar xzf redis_exporter-v1.10.0.linux-amd64.tar.gz -C /usr/local/redis_exporter

配置服务

1
2
3
4
5
6
7
8
9
10
11
12
# vim /usr/lib/systemd/system/redis_exporter.service

[Unit]
Description=redis_exporter
After=network.target

[Service]
Restart=on-failure
ExecStart=/usr/local/redis_exporter/redis_exporter -redis.addr 127.0.0.1:6379 -redis.password 123456

[Install]
WantedBy=multi-user.target

设置服务开机自启动

1
2
systemctl enable redis_exporter
systemctl start redis_exporter

安装blackbox_exporter

下载

1
2
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.17.0/blackbox_exporter-0.17.0.linux-amd64.tar.gz
tar xzf blackbox_exporter-0.17.0.linux-amd64.tar.gz -C /usr/local/blackbox_exporter

配置服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ vim /usr/lib/systemd/system/blackbox_exporter.service

[Unit]
Description=blackbox_exporter
After=network.target

[Service]
User=root
Type=simple
ExecStart=/usr/local/blackbox_exporter/blackbox_exporter --config.file=/usr/local/blackbox_exporter/blackbox.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target

设置服务开机自启动

1
2
systemctl enable blackbox_exporter
systemctl start blackbox_exporter