On the road again

The article shows how to install Prometheus on Ubuntu 20.04 as a systemd service.

Create user, group and directory structure:

groupadd --system prometheus
useradd -s /sbin/nologin --system -g prometheus prometheus
mkdir /var/lib/prometheus
for i in rules rules.d files_sd; do mkdir -p /etc/prometheus/${i}; done

Download archive:

wget https://github.com/prometheus/prometheus/releases/download/v2.26.0/prometheus-2.26.0.linux-amd64.tar.gz

Unpack and move binaries and config files to appropriate directories:

tar xvf prometheus*.tar.gz
cd prometheus*/
mv prometheus promtool /usr/local/bin/
prometheus --version
mv prometheus.yml /etc/prometheus/prometheus.yml
mv consoles/ console_libraries/ /etc/prometheus/

Edit configuration if needed:

vim /etc/prometheus/prometheus.yml

Create systemd unit - etc/systemd/system/prometheus.service - with following content:

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP \$MAINPID
ExecStart=/usr/local/bin/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 \
  --web.listen-address=0.0.0.0:9090 \
  --web.external-url=

SyslogIdentifier=prometheus
Restart=always

[Install]
WantedBy=multi-user.target

Change permissions:

#for i in rules rules.d files_sd; do sudo chown -R prometheus:prometheus /etc/prometheus/${i}; done
#for i in rules rules.d files_sd; do sudo chmod -R 775 /etc/prometheus/${i}; done
#chown -R prometheus:prometheus /var/lib/prometheus/

Start service:

systemctl daemon-reload
systemctl start prometheus
systemctl enable prometheus
systemctl status prometheus

Now you should be able to access Prometheus web console on port 9090. 

Add comment