Skip to content

Lab_00| Prometheus Setup

deepak gupta edited this page May 30, 2021 · 3 revisions

Lab_00

In this section of Lab we'll be starting with :

* Installing Prometheus
* Service Start of Prometheus

Before You Begin

Prerequisites

* A Linux VM or Machine
* A non-root sudo user, preferably one named prometheus

Installing Prometheus Server

 cd /etc/

Use wget to download the latest build of the Prometheus server and time-series database from GitHub and Use tar to extract prometheus-2.2.1.linux-amd64.tar.gz:

wget https://github.com/prometheus/prometheus/releases/download/v2.2.1/prometheus-2.2.1.linux-amd64.tar.gz
tar -xvzf prometheus-2.2.1.linux-amd64.tar.gz
rm -rf prometheus-2.2.1.linux-amd64.tar.gz
mv prometheus-2.2.1.linux-amd64/ prometheus

Create configuration and data directories for Prometheus

Prometheus needs a directory to store its data. We will create /var/lib/prometheus

mkdir /var/lib/prometheus

Copy Prometheus binary files to a directory in your $PATH

Preferred directory to put third party binaries on Linux is /usr/local/bin/ since it is in $PATH by default and it doesn't interfere with system binaries.

cp prometheus promtool /usr/local/bin/

Verify the installation by typing in the following command:

prometheus --version

Create Prometheus system group and system user

groupadd --system prometheus
useradd -s /sbin/nologin -r -g prometheus prometheus

Change directory permissions to Prometheus user and group

The ownership of Prometheus files and data should be its user and group.

 chown -R prometheus:prometheus /etc/prometheus/  /var/lib/prometheus/
 chmod -R 775 /etc/prometheus/ /var/lib/prometheus/

Create systemd unit file:

We need to create a Service unit file for managing Prometheus service. We will put the file under /etc/systemd/system directory. The name of the file has to end with .service

$ vi /etc/systemd/system/prometheus.service

[Unit]
Description=Prometheus systemd service unit
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

SyslogIdentifier=prometheus
Restart=always

[Install]
WantedBy=multi-user.target

Start and enable Prometheus service

Start and enable Prometheus service to start on boot.

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

Once it starts, use a browser to view Prometheus web interface, which is available at http://your_server_ip:9090