【文档】部署 alertmanager
操作系统:Rocky Linux 8
实验环境:VMware® Workstation 17 Pro
实验要求:部署至 prometheus 服务器上(针对小生产环境)大规模生产环境应考虑独立服务器
Prometheus 组件下载页面
流程
Tips01 | 下载组件
# 使用代理服务器 https://gh-proxy.net/ 下载
# 例如 Prometheus v3.5.0 linux-amd64 版本地址(见下方)
# https://github.com/prometheus/alertmanager/releases/download/v0.29.0-rc.1/alertmanager-0.29.0-rc.1.linux-amd64.tar.gz
# 代理服务器地址追加至下载地址前方。
[root@prometheus opt]# wget \
https://gh-proxy.net/\
https://github.com/prometheus/alertmanager/releases/download/v0.29.0-rc.1/alertmanager-0.29.0-rc.1.linux-amd64
Tips02 | 准备 应用文件
# 解压
[root@prometheus opt]# tar -xzf alertmanager-0.29.0-rc.1.darwin-amd64.tar.gz# 根据 Linux 文件系统层次规则
# /var/lib 创建数据目录
# /etc/ 创建配置目录
[root@prometheus opt]# mkdir -p /var/lib/alertmanager # 数据目录
[root@prometheus opt]# mkdir -p /etc/alertmanager # 配置目录
[root@prometheus opt]# cp alertmanager-0.29.0-rc.1.linux-amd64/alertmanager.yml /etc/alertmanager/
# /usr/local/bin 存储三方应用程序
[root@prometheus opt]# mv alertmanager-0.29.0-rc.1.linux-amd64 /usr/local/bin/
Tips03 | 准备 专用用户
# 最小权限原则 - 不可登录 + 系统用户
[root@prometheus opt]# useradd -r -s /bin/false alertmanager
[root@prometheus opt]# chown alertmanager:alertmanager /usr/local/bin/alertmanager-0.29.0-rc.1.linux-amd64
Tips04 | 准备 服务文件
[root@prometheus opt]# vim /etc/systemd/system/alertmanager.service
[Unit]
Description=Prometheus Alertmanager
After=network.target[Service]
User=alertmanager
Group=alertmanager
Type=simple
ExecStart=/usr/local/bin/alertmanager-0.29.0-rc.1.linux-amd64/alertmanager \--config.file=/etc/alertmanager/alertmanager.yml \--storage.path=/var/lib/alertmanager/
Restart=on-failure[Install]
WantedBy=multi-user.target# 启用服务
[root@prometheus opt]# systemctl enable alertmanager --now
访问 本机IP地址:9093
跳转至页面(示例图)视为服务正常启动。
Tips05 | Alertmanager 关联 Prometheus
# 往 prometheus 服务器上路径修改配置文件 /etc/prometheus/prometheus.yml
[root@prometheus prometheus]# vim prometheus.yml
alerting:alertmanagers:- static_configs:- targets: ['192.168.88.250:9093'] # 若同主机用 localhost:9093
Tips06 | 关于 /etc/alertmanager/alertmanager.yml 配置文件
# 前往 prometheus 服务器上路径修改配置文件 /etc/alertmanager/alertmanager.yml
[root@prometheus alertmanager]# vim alertmanager.yml
route:group_by: ['alertname'] # 分组规则(按告警名称)group_wait: 30s # 等待30s后发送同组告警group_interval: 5m # 同组告警每次间隔5min(针对持续触发类)repeat_interval: 1h # 重复告警每次间隔1hreceiver: 'web.hook' # 默认接收器
receivers:- name: 'web.hook'webhook_configs: # 本地告警发送目标 | 可替换钉钉/邮件等- url: 'http://127.0.0.1:5001/'
inhibit_rules: # 抑制规则- source_match: # severity: 'critical'target_match:severity: 'warning' # 目标类型equal: ['alertname', 'dev', 'instance'] # 忽略相同名的告警