使用 Linux Binaries 方式安装 Alertmanager

https://prometheus.io/

1、下载 Alertmanager 二进制文件。

从浏览器 或 命令行 下载 Alertmanager 二进制文件。

注意:可先网页下载到本地,上传到 /usr/local/src 目录下,也可以使用 wget 下载;

下载地址:

官方地址:https://prometheus.io/download/

GitHub:https://github.com/prometheus/alertmanager/releases

从您的浏览器下载

从命令行下载

  • Standalone Linux Binaries (64 Bit)
wget https://github.com/prometheus/alertmanager/releases/download/v0.25.0/alertmanager-0.25.0.linux-amd64.tar.gz
tar -zxvf alertmanager-0.25.0.linux-amd64.tar.gz
  • Standalone Linux Binaries (ARM64)
wget https://github.com/prometheus/alertmanager/releases/download/v0.25.0/alertmanager-0.25.0.linux-arm64.tar.gz
tar -zxvf alertmanager-0.25.0.linux-arm64.tar.gz
  • Standalone Linux Binaries (ARMv5)
wget https://github.com/prometheus/alertmanager/releases/download/v0.25.0/alertmanager-0.25.0.linux-armv5.tar.gz
tar -zxvf alertmanager-0.25.0.linux-armv5.tar.gz
  • Standalone Linux Binaries (ARMv6)
wget https://github.com/prometheus/alertmanager/releases/download/v0.25.0/alertmanager-0.25.0.linux-armv6.tar.gz
tar -zxvf alertmanager-0.25.0.linux-armv6.tar.gz
  • Standalone Linux Binaries (ARMv7)
wget https://github.com/prometheus/alertmanager/releases/download/v0.25.0/alertmanager-0.25.0.linux-armv7.tar.gz
tar -zxvf alertmanager-0.25.0.linux-armv7.tar.gz
2、解压并安装(以 Standalone Linux Binaries (64 Bit) 为例)
  • Standalone Linux Binaries (64 Bit)
$ cd /usr/local/src && https://github.com/prometheus/alertmanager/releases/download/v0.25.0/alertmanager-0.25.0.linux-amd64.tar.gz --no-check-certificate
$ tar -zxvf alertmanager-0.25.0.linux-amd64.tar.gz -C /usr/local
$ cd .. && mv /usr/local/alertmanager-0.25.0.linux-amd64 alertmanager
$ echo 'export ALERT_MANAGER_HOME=/usr/local/alertmanager/' >>/etc/profile
$ echo 'export PATH="$PATH:$ALERT_MANAGER_HOME"' >>/etc/profile
$ source /etc/profile
3、启动 Alertmanager 服务:

查询使用帮助

$ cd /usr/local/alertmanager && ./alertmanager -h

帮助说明内容:

usage: alertmanager [<flags>]

Flags:
  -h, --help                     Show context-sensitive help (also try --help-long and --help-man).
      --config.file="alertmanager.yml"
                                 Alertmanager configuration file name.
      --storage.path="data/"     Base path for data storage.
      --data.retention=120h      How long to keep data for.
      --data.maintenance-interval=15m
                                 Interval between garbage collection and snapshotting to disk of the silences and the notification logs.
      --alerts.gc-interval=30m   Interval between alert GC.
      --web.systemd-socket       Use systemd socket activation listeners instead of port listeners (Linux only).
      --web.listen-address=:9093 ...
                                 Addresses on which to expose metrics and web interface. Repeatable for multiple addresses.
      --web.config.file=""       [EXPERIMENTAL] Path to configuration file that can enable TLS or authentication.
      --web.external-url=WEB.EXTERNAL-URL
                                 The URL under which Alertmanager is externally reachable (for example, if Alertmanager is served via a reverse proxy). Used for
                                 generating relative and absolute links back to Alertmanager itself. If the URL has a path portion, it will be used to prefix all
                                 HTTP endpoints served by Alertmanager. If omitted, relevant URL components will be derived automatically.
      --web.route-prefix=WEB.ROUTE-PREFIX
                                 Prefix for the internal routes of web endpoints. Defaults to path of --web.external-url.
      --web.get-concurrency=0    Maximum number of GET requests processed concurrently. If negative or zero, the limit is GOMAXPROC or 8, whichever is larger.
      --web.timeout=0            Timeout for HTTP requests. If negative or zero, no timeout is set.
      --cluster.listen-address="0.0.0.0:9094"
                                 Listen address for cluster. Set to empty string to disable HA mode.
      --cluster.advertise-address=CLUSTER.ADVERTISE-ADDRESS
                                 Explicit address to advertise in cluster.
      --cluster.peer=CLUSTER.PEER ...
                                 Initial peers (may be repeated).
      --cluster.peer-timeout=15s
                                 Time to wait between peers to send notifications.
      --cluster.gossip-interval=200ms
                                 Interval between sending gossip messages. By lowering this value (more frequent) gossip messages are propagated across the cluster
                                 more quickly at the expense of increased bandwidth.
      --cluster.pushpull-interval=1m0s
                                 Interval for gossip state syncs. Setting this interval lower (more frequent) will increase convergence speeds across larger clusters
                                 at the expense of increased bandwidth usage.
      --cluster.tcp-timeout=10s  Timeout for establishing a stream connection with a remote node for a full state sync, and for stream read and write operations.
      --cluster.probe-timeout=500ms
                                 Timeout to wait for an ack from a probed node before assuming it is unhealthy. This should be set to 99-percentile of RTT
                                 (round-trip time) on your network.
      --cluster.probe-interval=1s
                                 Interval between random node probes. Setting this lower (more frequent) will cause the cluster to detect failed nodes more quickly
                                 at the expense of increased bandwidth usage.
      --cluster.settle-timeout=1m0s
                                 Maximum time to wait for cluster connections to settle before evaluating notifications.
      --cluster.reconnect-interval=10s
                                 Interval between attempting to reconnect to lost peers.
      --cluster.reconnect-timeout=6h0m0s
                                 Length of time to attempt to reconnect to a lost peer.
      --cluster.tls-config=""    [EXPERIMENTAL] Path to config yaml file that can enable mutual TLS within the gossip protocol.
      --cluster.allow-insecure-public-advertise-address-discovery
                                 [EXPERIMENTAL] Allow alertmanager to discover and listen on a public IP address.
      --log.level=info           Only log messages with the given severity or above. One of: [debug, info, warn, error]
      --log.format=logfmt        Output format of log messages. One of: [logfmt, json]
      --version                  Show application version.

带参数启动

$ ./alertmanager --config.file="/usr/local/alertmanager/alertmanager.yml"

浏览器访问 Alertmanager:

http://localhost:9093/

4、配置 Alertmanager

为 Prometheus 创建专用的数据存储目录

$ mkdir -p /mnt/alertmanager/data
$ mkdir -p /mnt/alertmanager/logs

为 Prometheus 创建专用的数据存储目录

route:
  group_by: ['alertname']
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 1h
  receiver: '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']
5、开机自启动

[root@local ~]# vi /lib/systemd/system/alertmanager.service

脚本内容:

[Unit]
Description="alertmanager"
Documentation=https://prometheus.io/docs/alerting/latest/alertmanager/
After=network.target

[Service]
User=root
Type=simple
ExecStart=/usr/local/alertmanager/alertmanager  --config.file=/usr/local/alertmanager/alertmanager.yml --storage.path="/mnt/alertmanager/data" --data.retention=120h --data.maintenance-interval=10m
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
LimitNOFILE=65536
TimeoutStopSec=20
Restart=on-failure
SuccessExitStatus=0
StartLimitInterval=60
StartLimitBurst=3000
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=alertmanager

[Install]
WantedBy=multi-user.target

设置随机启动:

[root@local ~]# systemctl daemon-reload
[root@local ~]# systemctl disable alertmanager.service
[root@local ~]# systemctl enable alertmanager.service
[root@local ~]# systemctl start alertmanager.service
[root@local ~]# systemctl status alertmanager.service
[root@local ~]# systemctl stop alertmanager.service
[root@local ~]# systemctl restart alertmanager.service
作者:Jeebiz  创建时间:2023-02-21 21:53
最后编辑:Jeebiz  更新时间:2024-01-24 21:48