一,下载alertmanager
1,官网下载地址https://prometheus.io/download/
2,原理图:
二,下载和安装
1,下载安装包: 选择linux+amd64的版本下载:# wget https://github.com/prometheus/alertmanager/releases/download/v0.27.0/alertmanager-0.27.0.linux-amd64.tar.gz
2,安装
解压:
# tar -zxvf alertmanager-0.27.0.linux-amd64.tar.gz
移动到安装目录:
# mv alertmanager-0.27.0.linux-amd64 /usr/local/soft/
3,查看版本:
# /usr/local/soft/alertmanager-0.27.0.linux-amd64/alertmanager --version
alertmanager, version 0.27.0 (branch: HEAD, revision: 0aa3c2aad14cff039931923ab16b26b7481783b5)
build user: root@22cd11f671e9
build date: 20240228-11:51:20
go version: go1.21.7
platform: linux/amd64
tags: netgo
三,配置、启动
1,配置文件:
# vi alertmanager.yml
内容:
global:
resolve_timeout: 5m
smtp_smarthost: 'smtp.163.com:465'
smtp_from: '您的邮箱'
smtp_auth_username: '您的邮箱用户名'
smtp_auth_password: '此处替换为您邮箱的authcode'
smtp_require_tls: false
route:
group_by: ['alertname']
group_wait: 30s
group_interval: 5m
repeat_interval: 1h
receiver: 'web.hook'
receivers:
- name: 'web.hook'
email_configs:
- to: '此处替换为您的收件邮箱'
webhook_configs:
- url: 'http://127.0.0.1:5001/'
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'dev', 'instance']
测试配置是否正确:
# ./amtool check-config alertmanager.yml
Checking 'alertmanager.yml' SUCCESS
Found:
- global config
- route
- 1 inhibit rules
- 1 receivers
- 0 templates
2,使用systemctl管理服务:
# vi /lib/systemd/system/alertmanager.service
内容:
[Unit]
Description=Alert Manager
wants=network-online.target
After=network-online.target
[Service]
Type=simple
Restart=always
ExecStart=/usr/local/soft/alertmanager-0.27.0.linux-amd64/alertmanager --config.file=/usr/local/soft/alertmanager-0.27.0.linux-amd64/alertmanager.yml --storage.path=/usr/local/so
ft/alertmanager-0.27.0.linux-amd64/data/
[Install]
WantedBy=multi-user.target
重新加载服务
# systemctl daemon-reload
3,启动:
# systemctl start alertmanager.service
4,查看端口:可以看到启用了9093/9094两个端口
# ss -lntp | grep alert
LISTEN 0 4096 *:9093 *:* users:(("alertmanager",pid=474456,fd=8))
LISTEN 0 4096 *:9094 *:* users:(("alertmanager",pid=474456,fd=3))
5,服务启动后查看配置:
访问: 你的ip:9093 可以看到服务的状态
如图:
四,用postman测试发送一封邮件
说明:
地址用:ip:9093/api/v2/alerts
方法用:POST
选择Body,
然后选择raw,
输入邮件内容后,点 send
如图:
标签:alertmanager,amd64,0.27,manager,alert,prometheus,usr,linux,local From: https://www.cnblogs.com/architectforest/p/18515540