prometheus+grafana+node_exporter+alertmanager搭建监控报警平台

1 版本选择

prometheus版本2.25.0,Grafana 版本7.5.0,node_exporter 1.1.2,alertmanager 0.22.0-rc.1 。

下载地址:

https://prometheus.io/download/

https://grafana.com/grafana/download?pg=get&plcmt=selfmanaged-box1-cta1

2 环境准备

2.1 本次演示准备了三台机器。方案如下


2.2 交换公钥,设置无密码登陆

创建一个hostfile文件,包含cluster中的所有机器。


因为我们需要使用OushuDB命令行工具”hawq ssh-exkeys”来简化无密码登录设置以及使用“hawq ssh”来简化集群操作,所以我们在oushu1上先安装OushuDB。

在oushum1执行:

hawq ssh-exkeys -f hostfile


3 prometheus搭建


groupadd prometheus

useradd -g prometheus -M -s /sbin/nologin prometheus

tar -zxvf /opt/module/prometheus-2.25.0.linux-amd64.tar.gz -C /usr/local

cd /usr/local

mv /usr/local/prometheus-2.25.0.linux-amd64/ /usr/local/prometheus

mkdir -pv /usr/local/prometheus/data

chown -R prometheus.prometheus /usr/local/prometheus

vi /usr/lib/systemd/system/prometheus.service(添加如下内容)



启动服务


systemctl daemon-reload

systemctl start prometheus.service

systemctl enable prometheus.service

systemctl status prometheus.service



访问web页面


4 node_exporter 搭建


groupadd prometheus

useradd -g prometheus -M -s /sbin/nologin prometheus

tar -zxvf /opt/module/node_exporter-1.1.2.linux-amd64.tar.gz -C /usr/local/

cd /usr/local

mv /usr/local/node_exporter-1.1.2.linux-amd64/ /usr/local/node_exporter

chown -R prometheus.prometheus /usr/local/node_exporter

vi /usr/lib/systemd/system/node_exporter.service(添加如下内容)

启动node_exporter(localhost:9100)

systemctl daemon-reload

systemctl enable node_exporter

systemctl start node_exporter

systemctl status node_exporter


如果可以正常获取到上游的指标后,我们可以将node_exporter集成到prometheus


vim  /usr/local/prometheus/prometheus.yml

- job_name: 'node-01_agent1' #

  static_configs:

          - targets: ['172.20.10.7:9100']


设置完成后,保存,然后重新启动Prometheus  普罗米修斯监控系统

重启prometheus:


systemctl reload prometheus.service


可以看到prometheus已经获取到job了


5 alertmanager搭建

tar -zxvf alertmanager-0.22.0-rc.1.linux-amd64.tar.gz -C /usr/local/

mv /usr/local/alertmanager-0.22.0-rc.1.linux-amd64/ /usr/local/alertmanager

vi /usr/lib/systemd/system/alertmanager.service(添加如下内容)


[Unit]

Description=Alertmanager

After=network-online.target

[Service]

Restart=on-failure

ExecStart=/usr/local/alertmanager/alertmanager --config.file=/usr/local/alertmanager/alertmanager.yml

[Install]

WantedBy=multi-user.target


启动服务

systemctl daemon-reload

systemctl enable alertmanager

systemctl start alertmanager

systemctl status alertmanager


6 grafana搭建

tar -zxvf grafana-7.5.0.linux-amd64.tar.gz -C /usr/local/

mv /usr/local/grafana-7.5.0/ /usr/local/grafana

vi /usr/lib/systemd/system/grafana-server.service(添加如下内容)


[Unit]

Description=Grafana Server

After=network-online.target

[Service]

Restart=on-failure

ExecStart=/usr/local/grafana/bin/grafana-server -config /usr/local/grafana/conf/defaults.ini -homepath /usr/local/grafana

[Install]

WantedBy=multi-user.target


启动服务

systemctl daemon-reload

systemctl enable grafana-server

systemctl start grafana-server

systemctl status grafana-server


进入grafana web页面


添加prometheus数据源


选择prometheus


添加数据源成功


导入json文件




面板示例


你可能感兴趣的:(prometheus+grafana+node_exporter+alertmanager搭建监控报警平台)