> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Alertmanager Installation Systemd

> Guide to installing and configuring Prometheus Alertmanager as a systemd service, covering download, user and directory setup, binary installation, service unit creation, and startup verification.

This guide shows how to install Prometheus Alertmanager and configure it to be managed by systemd so you can start, stop, and enable it with `systemctl`.

High-level workflow:

* Download and extract Alertmanager.
* Create a dedicated `alertmanager` system user.
* Create configuration and storage directories and place the config.
* Install binaries and set correct permissions.
* Create a systemd unit file, reload systemd, and enable/start the service.

<Callout icon="lightbulb" color="#1CB2FE">
  This lesson uses Alertmanager v0.24.0 as an example. Replace the version in the commands if you need a newer/older release. For releases see the Alertmanager GitHub releases: [https://github.com/prometheus/alertmanager/releases](https://github.com/prometheus/alertmanager/releases)
</Callout>

Summary of important paths and settings:

|          Resource | Purpose                          | Example                                                |
| ----------------: | -------------------------------- | ------------------------------------------------------ |
|       System user | Service account for Alertmanager | `alertmanager`                                         |
|  Config directory | Alertmanager configuration       | `/etc/alertmanager/alertmanager.yml`                   |
| Storage directory | Runtime and WAL storage          | `/var/lib/alertmanager`                                |
|          Binaries | Executables on PATH              | `/usr/local/bin/alertmanager`, `/usr/local/bin/amtool` |
|      Systemd unit | Service definition               | `/etc/systemd/system/alertmanager.service`             |

## 1. Download and extract Alertmanager

Example (v0.24.0):

```bash theme={null}
wget https://github.com/prometheus/alertmanager/releases/download/v0.24.0/alertmanager-0.24.0.linux-amd64.tar.gz
tar xzf alertmanager-0.24.0.linux-amd64.tar.gz
cd alertmanager-0.24.0.linux-amd64
```

You should see the extracted files, for example:

```bash theme={null}
$ ls -la
total 55752
drwxr-xr-x  2 user user    4096 Mar 25  2022 .
-rwxr--r--  1 user user     356 Mar 25  2022 alertmanager.yml
-rwxr--r--  1 user user 25067944 Mar 25  2022 amtool
-rwxr--r--  1 user user 20542176 Mar 25  2022 alertmanager
-rw-r--r--  1 user user     457 Mar 25  2022 LICENSE
-rw-r--r--  1 user user     166 Mar 25  2022 NOTICE
```

## 2. Create a dedicated system user

Create a non-login system user to run Alertmanager:

```bash theme={null}
sudo useradd --no-create-home --system --shell /bin/false alertmanager
```

Using `--system` is recommended for service accounts; it keeps user IDs in the system range.

## 3. Create configuration and storage directories

Create the config and storage directories, copy the shipped config into place, and set ownership to the `alertmanager` user:

```bash theme={null}
sudo mkdir -p /etc/alertmanager
sudo mkdir -p /var/lib/alertmanager

# Copy the provided config file into place
sudo cp alertmanager.yml /etc/alertmanager/alertmanager.yml

# Ensure the directories and files are owned by the alertmanager user
sudo chown -R alertmanager:alertmanager /etc/alertmanager
sudo chown -R alertmanager:alertmanager /var/lib/alertmanager
```

<Callout icon="warning" color="#FF6B6B">
  Be careful with `chown -R` — do NOT run `sudo chown -R alertmanager:alertmanager /etc/` or similarly broad commands. Target only `/etc/alertmanager` (and other specific directories) to avoid damaging system ownerships.
</Callout>

## 4. Install the binaries

Copy the `alertmanager` binary and the `amtool` helper to a directory on PATH, set execute permissions, and set ownership:

```bash theme={null}
sudo cp alertmanager /usr/local/bin/alertmanager
sudo cp amtool /usr/local/bin/amtool

sudo chmod 0755 /usr/local/bin/alertmanager /usr/local/bin/amtool
sudo chown root:root /usr/local/bin/alertmanager /usr/local/bin/amtool
```

Notes:

* Keeping the binaries owned by `root` and world-executable is common and safe; the process will run as the `alertmanager` user when started by systemd.
* If you prefer, you can set ownership to `alertmanager:alertmanager`, but `root:root` is typical.

## 5. Create the systemd service unit

Create `/etc/systemd/system/alertmanager.service` with the following content:

```ini theme={null}
[Unit]
Description=Alertmanager Service
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=alertmanager
Group=alertmanager
ExecStart=/usr/local/bin/alertmanager \
    --config.file=/etc/alertmanager/alertmanager.yml \
    --storage.path=/var/lib/alertmanager
Restart=always

[Install]
WantedBy=multi-user.target
```

Key points:

* `--config.file` points to your Alertmanager config (`/etc/alertmanager/alertmanager.yml`).
* `--storage.path` sets the data directory (`/var/lib/alertmanager`).
* The unit runs the process as `alertmanager:alertmanager`.

After creating the unit file, reload systemd so it recognizes the new service:

```bash theme={null}
sudo systemctl daemon-reload
```

## 6. Start, enable, and verify the service

Start and enable the service so it runs on boot:

```bash theme={null}
sudo systemctl start alertmanager
sudo systemctl enable alertmanager
```

Check status and follow logs:

```bash theme={null}
sudo systemctl status alertmanager
sudo journalctl -u alertmanager -f
```

Troubleshooting checklist:

* Validate that `/etc/alertmanager/alertmanager.yml` is valid YAML (use a linter or `amtool check-config` if available).
* Confirm ownership and permissions: the `alertmanager` user must be able to read the config and write to `/var/lib/alertmanager`.
* Inspect `journalctl` output for startup errors and missing flags or permission issues.

## Reference: Example final systemd unit

For convenience, here is the final unit again:

```ini theme={null}
[Unit]
Description=Alertmanager Service
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=alertmanager
Group=alertmanager
ExecStart=/usr/local/bin/alertmanager \
    --config.file=/etc/alertmanager/alertmanager.yml \
    --storage.path=/var/lib/alertmanager
Restart=always

[Install]
WantedBy=multi-user.target
```

Congratulations — Alertmanager should now be installed and managed by systemd.

Links and references:

* Alertmanager releases: [https://github.com/prometheus/alertmanager/releases](https://github.com/prometheus/alertmanager/releases)
* Alertmanager documentation: [https://prometheus.io/docs/alerting/latest/alertmanager/](https://prometheus.io/docs/alerting/latest/alertmanager/)
* systemd documentation: [https://www.freedesktop.org/wiki/Software/systemd/](https://www.freedesktop.org/wiki/Software/systemd/)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/prometheus-certified-associate-pca/module/499d9ac5-c2e0-43fe-b000-f08f33fbf2dc/lesson/eb7ae2f0-0d55-4789-af61-fdf337265d10" />

  <Card title="Practice Lab" icon="flask-conical" cta="Learn more" href="https://learn.kodekloud.com/user/courses/prometheus-certified-associate-pca/module/499d9ac5-c2e0-43fe-b000-f08f33fbf2dc/lesson/fbd1026a-cd0c-4ebf-89bb-4182630754ba" />
</CardGroup>
