Prometheus Alertmanager is a vital component of the Prometheus monitoring system, responsible for managing alerts by deduplicating, grouping, and routing them to appropriate receivers such as email, Slack, discord or PagerDuty. This guide provides step-by-step instructions to install Alertmanager on an Ubuntu server.
Prerequisites
- Ubuntu Server: Ensure your system is running Ubuntu 20.04 or later.
- Sudo Access: Administrative privileges are required for installation.
- Prometheus Installation: Prometheus installed and running
Step 1: Update the System
Begin by updating your package lists to ensure all repositories are current:
sudo apt update && sudo apt upgrade -y
Step 2: Download Alertmanager
Visit the Prometheus Alertmanager Releases page to find the latest version. As of February 28, 2024, the latest version is 0.27.0.
To download the desired version, use wget
. Replace <VERSION>
with the version number you wish to install (e.g., v0.27.0
):
wget https://github.com/prometheus/alertmanager/releases/download/<VERSION>/alertmanager-<VERSION>.linux-amd64.tar.gz
For example, to download version 0.27.0:
wget https://github.com/prometheus/alertmanager/releases/download/v0.27.0/alertmanager-0.27.0.linux-amd64.tar.gz
Step 3: Extract the Downloaded File
Extract the downloaded tarball:
tar -xvzf alertmanager-0.27.0.linux-amd64.tar.gz
Navigate into the extracted directory:
cd alertmanager-0.27.0.linux-amd64
Step 4: Move Files to System Path
To make Alertmanager accessible globally, move the binaries to /usr/local/bin
:
sudo mv alertmanager amtool /usr/local/bin/
Step 5: Configure Alertmanager
Create a directory for Alertmanager configuration files:
sudo mkdir /etc/alertmanager
Create a configuration file named alertmanager.yml
:
sudo nano /etc/alertmanager/alertmanager.yml
Add the following minimal configuration to the file:
global:
resolve_timeout: 5m
route:
receiver: 'default'
receivers:
- name: 'default'
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'cluster', 'service']
Save and close the file (Ctrl+O
, Enter
, Ctrl+X
).
Step 6: Create a Systemd Service
To manage Alertmanager as a service, create a systemd service file:
sudo nano /etc/systemd/system/alertmanager.service
Add the following content:
[Unit]
Description=Prometheus Alertmanager
Wants=network-online.target
After=network-online.target
[Service]
User=alertmanager
Group=alertmanager
Type=simple
ExecStart=/usr/local/bin/alertmanager --config.file=/etc/alertmanager/alertmanager.yml --storage.path=/var/lib/alertmanager
Restart=on-failure
[Install]
WantedBy=multi-user.target
Create the necessary directories and set permissions:
sudo mkdir -p /var/lib/alertmanager
sudo useradd -M -r -s /bin/false alertmanager
sudo chown -R alertmanager:alertmanager /var/lib/alertmanager /etc/alertmanager
Step 7: Start and Enable the Service
Reload the systemd daemon, start Alertmanager, and enable it to run at boot:
sudo systemctl daemon-reload
sudo systemctl start alertmanager
sudo systemctl enable alertmanager
Verify the service is running:
sudo systemctl status alertmanager
Step 8: Access Alertmanager
By default, Alertmanager runs on port 9093. Access it via your server’s IP address in a browser:
http://<your-server-ip>:9093
Optional: Customize Alertmanager Configuration
Modify the alertmanager.yml
file to suit your alerting needs, such as adding email or Slack integrations. After any configuration changes, restart Alertmanager:
sudo systemctl restart alertmanager
Conclusion
You’ve successfully installed Prometheus Alertmanager v0.27.0 on your Ubuntu server! Whether you use this version or another, the steps remain largely the same. With Alertmanager, you can now efficiently handle and route alerts generated by Prometheus.