#273: Create a Systemd Service for Prometheus - Rmhibbert/oe2-group-c GitHub Wiki

Link to the ticket: https://rt.dataraster.com/Ticket/Display.html?id=273

Step by step

Copy Prometheus files

Description: From your Prometheus directory, copy Prometheus files to /usr/local/bin/prometheus

Command: if needed cd prometheus-2.53.4.linux-amd64 then sudo cp -r . /usr/local/bin/prometheus


Create a service file

Description: Create a service file at /etc/systemd/system/prometheus.service:

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

then paste

[Unit] Description=Prometheus After=network.target [Service] User=prometheus Group=prometheus ExecStart=/usr/local/bin/prometheus/prometheus
--config.file=/usr/local/bin/prometheus/prometheus.yml
--storage.tsdb.path=/var/lib/prometheus/data
--web.console.templates=/usr/local/bin/prometheus/consoles RestartSec=5s [Install] WantedBy=multi-user.target


Create the directory

Description: Prometheus needs a writable directory for its data, Create the directory (use /var/lib/prometheus ):

Command: sudo mkdir -p /var/lib/prometheus/data


Create the directory

Description: Prometheus needs a writable directory for its data, Create the directory (use /var/lib/prometheus ):

Command: sudo mkdir -p /var/lib/prometheus/data


Create a user then set ownership

Description: create user

Command: sudo useradd --no-create-home --shell /bin/false prometheus

Description: Set ownership

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


Reload systemd, start Prometheus, and check its status:

Description: Run commands

Command:

sudo systemctl daemon-reload sudo systemctl start prometheus sudo systemctl status prometheus

image