Prometheus Server installation and configuration:

Saleem Pasha
2 min readJun 4, 2021

Prometheus is a free software application used for event monitoring and alerting. It records real-time metrics in a time series database (allowing for high dimensionality) built using a HTTP pull model, with flexible queries and real-time alerting.The project is written in Go and licensed under the Apache 2 License, with source code available on GitHub, and is a graduated project of the Cloud Native Computing Foundation, along with Kubernetes and Envoy.

Pre-Requisites :

Create a Cloud Playground server:

  • Distribution: Ubuntu 18.04 Bionic Beaver LTS
  • Size: Small
  • Tag: Prometheus

Step 1 : Create a user, group, and directories for Prometheus:

#sudo useradd -M -r -s /bin/false prometheus

#sudo mkdir /etc/prometheus /var/lib/prometheus

Step 2:Download and extract the pre-compiled binaries:

#wget https://github.com/prometheus/prometheus/releases/download/v2.16.0/prometheus-2.16.0.linux-amd64.tar.gz

#tar xzf prometheus-2.16.0.linux-amd64.tar.gz prometheus-2.16.0.linux-amd64/

Step 3: Move the files from the downloaded archive to the appropriate locations and set ownership:

#sudo cp prometheus-2.16.0.linux-amd64/{prometheus,promtool} /usr/local/bin/

#sudo chown prometheus:prometheus #/usr/local/bin/{prometheus,promtool}

#sudo cp -r prometheus-2.16.0.linux-amd64/{consoles,console_libraries} /etc/prometheus/

#sudo cp prometheus-2.16.0.linux-amd64/prometheus.yml /etc/prometheus/prometheus.yml

#sudo chown -R prometheus:prometheus /etc/prometheus

#sudo chown prometheus:prometheus /var/lib/prometheus

Step 4: Briefly test your setup by running Prometheus in the foreground:

#prometheus — config.file=/etc/prometheus/prometheus.yml

Step 5: Create a systemd unit file for Prometheus:

#sudo vi /etc/systemd/system/prometheus.service

Define the Prometheus service in the unit file:

[Unit]

Description=Prometheus Time Series Collection and Processing Server

Wants=network-online.target

After=network-online.target

[Service]

User=prometheus

Group=prometheus

Type=simple

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

[Install]

WantedBy=multi-user.target

Step 6: Start and enable the Prometheus service:

#sudo systemctl daemon-reload

#sudo systemctl start prometheus

#sudo systemctl enable prometheus

Step 7: Make an HTTP request to Prometheus to verify it is able to respond:

curl localhost:9090

Step 8: You can also access Prometheus in a browser using the server’s public IP address: http://<PROMETHEUS_SERVER_PUBLIC_IP>:9090.

--

--