(1)安装Alertmanager
安装在k8s-node2服务器上
[root@k8s-node2 ~]# tar -zxvf alertmanager-0.21.0.linux-amd64.tar.gz
alertmanager-0.21.0.linux-amd64/
alertmanager-0.21.0.linux-amd64/alertmanager
alertmanager-0.21.0.linux-amd64/amtool
alertmanager-0.21.0.linux-amd64/NOTICE
alertmanager-0.21.0.linux-amd64/LICENSE
alertmanager-0.21.0.linux-amd64/alertmanager.yml
[root@k8s-node2 ~]# ls
alertmanager-0.21.0.linux-amd64 alertmanager-0.21.0.linux-amd64.tar.gz anaconda-ks.cfg disk_free.sh node_exporter-1.0.1.linux-amd64.tar.gz
[root@k8s-node2 ~]# cp alertmanager-0.21.0.linux-amd64/alertmanager /usr/local/bin/
[root@k8s-node2 ~]# cp alertmanager-0.21.0.linux-amd64/amtool /usr/local/bin/
[root@k8s-node2 ~]# alertmanager --version
(2)配置Alertmanager
[root@k8s-node2 ~]# mkdir -pv /etc/alertmanager
mkdir: 已创建目录 "/etc/alertmanager"
[root@k8s-node2 ~]# cp alertmanager-0.21.0.linux-amd64/alertmanager.yml /etc/alertmanager/
[root@k8s-node2 ~]# cat /etc/alertmanager/alertmanager.yml 默认配置文件
(3)重新配置Alertmanager
[root@k8s-node2 alertmanager]# cp alertmanager.yml alertmanager.yml.bak
[root@k8s-node2 alertmanager]# ls
alertmanager.yml alertmanager.yml.bak
[root@k8s-node2 ~]# cat /etc/alertmanager/alertmanager.yml
[root@k8s-node2 alertmanager]# more alertmanager.yml
global:
smtp_smarthost: 'smtp.qq.com:25'
smtp_from: '[email protected]'
smtp_auth_username: '[email protected]'
smtp_auth_password: '******'
smtp_require_tls: false
route:
receiver: mail
receivers:
- name: 'mail'
email_configs:
- to: '[email protected]'
[root@k8s-node2 alertmanager]#
(4)启动Alertmanager
[root@k8s-node2 alertmanager]# alertmanager --config.file alertmanager.yml
(5)在Prometheus上添加Alertmanage
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
- 192.168.20.43:9093
(6)在Prometheus上添加对Alertmanage监控
- job_name: 'alertmanager'
static_configs:
- targets: ['192.168.20.43:9093']
(7)在Prometheus添加告警规则
groups:
- name: node-up
rules:
- alert: node-up
expr: up{job="k8s-node1"} == 0
for: 15s
labels:
severity: 1
team: node
annotations:
summary: "{{ $labels.instance }} 已停止运行超过 15s!"
(8)把告警规则加入Prometheus配置文件
rule_files:
- "rules/*_rules.yml"
- "rules/*_alerts.yml"
(9) 查看配置规则
(10) 测试:停止k8s-node1节点,是否有报警
提示Pending(1)
(11) 查看报警Alertmanager
(12) 查看邮件报警
Prometheus+Grafana+Alertmanager +邮件告警配置完成
↓↓ 点击"阅读原文" 【加入DevOps运维团】
相关阅读:
1、两种方式部署Prometheus
2、部署Prometheus+Grafana
请分享到朋友圈扫码关注