Running Prometheus with Systemd
10 Nov 2022Table of Contents
Prometheus is a powerful open-source monitoring system that can be used to collect and track a variety of metrics for your applications. In this guide, we will cover how to get Prometheus up and running with systemd on a Ubuntu or Debian server.
Download and Install Prometheus
Create a dedicated prometheus
user with:
sudo useradd -M -U prometheus
Select a version for your system from here and download it:
wget https://github.com/prometheus/prometheus/releases/download/v2.40.0-rc.0/prometheus-2.40.0-rc.0.linux-amd64.tar.gz
tar -xzvf prometheus-2.40.0-rc.0.linux-amd64.tar.gz
sudo mv prometheus-2.40.0-rc.0.linux-amd64 /opt/prometheus
Change folder permissions for prometheus
user with:
sudo chown prometheus:prometheus -R /opt/prometheus
Create Systemd Unit File
Create systemd service in /etc/systemd/system/prometheus.service
with the following contents:
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Restart=on-failure
ExecStart=/opt/prometheus/prometheus \
--config.file=/opt/prometheus/prometheus.yml \
--storage.tsdb.path=/opt/prometheus/data \
--storage.tsdb.retention.time=30d
[Install]
WantedBy=multi-user.target
Start systemd service of Prometheus with:
sudo systemctl daemon-reload
sudo systemctl start prometheus.service
Enable service to start and system start-up:
sudo systemctl enable prometheus.service
Check the status of the service with:
sudo systemctl status prometheus.service
To view the logs of Prometheus for troubleshooting, type:
sudo journalctl -u prometheus.service -f