Skip to main content

Prometheus as a Service

Introduction

This guide will provide instructions on how to install Prometheus as a service on Ubuntu 24.04.

Download and Install Prometheus

Navigate to the Prometheus Download Page and locate the release with the "Latest" tag. I typically do not use the beta version, and at the time of this wiki the latest version is prometheus-2.55.0.linux-amd64.tar.gz and it will be used as an example in future commands within this wiki.

Downloaded the latest version to the home directory

wget -P ~/ https://github.com/prometheus/prometheus/releases/download/v2.55.0/prometheus-2.55.0.linux-amd64.tar.gz

Extract the downloaded file

tar -xvf ~/prometheus-2.55.0.linux-amd64.tar.gz

Move the extracted files

sudo mv ~/prometheus-2.55.0.linux-amd64 /etc/prometheus

Delete the tar.gz file

rm ~/prometheus-2.55.0.linux-amd64.tar.gz

Create the prometheus user

sudo useradd -r -s /bin/false -c "Prometheus service account" -d /nonexistent prometheus
  • -r makes it a system users
  • --no-create-home: This option prevents the creation of a home directory for the prometheus user.
  • --shell /bin/false: This prevents the user from being able to log in interactively.

Set permissions

sudo chown -R prometheus:prometheus /etc/prometheus

Create a data directory in /var/lib for Prometheus storage

sudo mkdir /var/lib/prometheus

Set permissions for the prometheus user

sudo chown -R prometheus:prometheus /var/lib/prometheus

Create a systemd service

sudo nano /etc/systemd/system/prometheus.service

Add the following configuration, the press ctrl + x, then y, then enter to save.

[Unit]
Description=Prometheus Service
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/etc/prometheus/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries

[Install]
WantedBy=multi-user.target

Reload daemon

sudo systemctl daemon-reload

Start service

sudo systemctl start prometheus

Enable service to start on boot

sudo systemctl enable prometheus

Verify the status

sudo systemctl status prometheus

Access Prometheus

The Prometheus web front end should now be accessible on http://localhost:9090. If the service is running on another host, replace localhost with the IP of that host. To start scraping metrics, endpoints can be added to the prometheus.yml file, and then the prometheus service should be restarted for the changes to take effect.

Grafana

Learn how to add Prometheus as a data source for Grafana