Install Prometheus Server on Debian 10/9 and Ubuntu 20.04 / 18.04

How to install Prometheus on Debian 10/9 and Ubuntu 20.04 / 18.04 Linux? Prometheus is a monitoring tool designed to record real-time metrics in a time series database. This is an open source software project written in Go. Prometheus metrics are collected using HTTP pull to achieve higher performance and scalability. In this tutorial, we will discuss how to install Prometheus Server on Debian and Ubuntu Linux systems.

Other tools that make Prometheus a complete monitoring tool are:

  • Exporter: These libraries help export metrics from third-party systems as Prometheus metrics.
  • PromQL: Prometheus query language can be used to filter multi-dimensional time series data.

Grafana is a tool commonly used to visualize data polled by Prometheus for monitoring and analysis. It is used to create a dashboard with a panel that represents a specific indicator for a set period of time.

Step 1: Create a Prometheus system group

First create Prometheus system users and groups.

sudo groupadd --system prometheus

Groups with ID <1000 are system groups. After adding a system group, create a Prometheus system user and assign the primary group created.

sudo useradd -s /sbin/nologin --system -g prometheus prometheus

Step 2: Create data and configuration directories for Prometheus

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

sudo mkdir /var/lib/prometheus

Prometheus main configuration file directory is / etc / prometheus /. It will have some subdirectories:

for i in rules rules.d files_sd; do sudo mkdir -p /etc/prometheus/${i}; done

Step 3: Download Prometheus

We need to download the latest version of Prometheus archive and unzip it to get the binary. You can check the release Prometheus releases Github page.

Install wget.

sudo apt update
sudo apt -y install wget curl vim

Then download the latest binary archive of Prometheus.

mkdir -p /tmp/prometheus && cd /tmp/prometheus
curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi -

Unzip the file:

tar xvf prometheus*.tar.gz
cd prometheus*/

Move the binary to the / usr / local / bin / directory.

sudo mv prometheus promtool /usr/local/bin/

Check the installed version:

$ prometheus --version
prometheus, version 2.15.2 (branch: HEAD, revision: d9613e5c466c6e9de548c4dae1b9aabf9aaf7c57)
  build user:       [email protected]
  build date:       20200106-14:50:51
  go version:       go1.13.5

$ promtool --version
promtool, version 2.15.2 (branch: HEAD, revision: d9613e5c466c6e9de548c4dae1b9aabf9aaf7c57)
  build user:       [email protected]
  build date:       20200106-14:50:51
  go version:       go1.13.5

Move the Prometheus configuration template to the / etc directory.

sudo mv prometheus.yml /etc/prometheus/prometheus.yml

Also move the console and console_libraries to the / etc / prometheus directory:

sudo mv consoles/ console_libraries/ /etc/prometheus/

Step 4: Configure Prometheus on Debian / Ubuntu

Create or edit a configuration file for Prometheus-/etc/prometheus/prometheus.yml.

sudo vim /etc/prometheus/prometheus.yml

The template configuration should look similar to the following:

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']

You can edit the file to the default settings and save it.

Create Prometheus systemd service unit file

To be able to use systemd to manage Prometheus services, you need to explicitly define this unit file.

sudo tee /etc/systemd/system/prometheus.service<

Change directory permissions.

Change the ownership of these directories to Prometheus users and groups.

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
sudo chown -R prometheus:prometheus /var/lib/prometheus/

Reload the systemd daemon and start the service:

sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus

Use the systemctl status prometheus command to check the status:

$ systemctl status prometheus
● prometheus.service - Prometheus
   Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2020-01-19 14:36:08 UTC; 14s ago
     Docs: https://prometheus.io/docs/introduction/overview/
 Main PID: 1397 (prometheus)
    Tasks: 7 (limit: 2377)
   Memory: 21.7M
   CGroup: /system.slice/prometheus.service
           └─1397 /usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus --web.console.templates

Jan 19 14:36:08 deb10 prometheus[1397]: level=info ts=2020-01-19T14:36:08.959Z caller=main.go:334 vm_limits="(soft=unlimited, hard=unlimited)"
Jan 19 14:36:08 deb10 prometheus[1397]: level=info ts=2020-01-19T14:36:08.960Z caller=main.go:648 msg="Starting TSDB ..."
Jan 19 14:36:08 deb10 prometheus[1397]: level=info ts=2020-01-19T14:36:08.964Z caller=head.go:584 component=tsdb msg="replaying WAL, this may take awhil
Jan 19 14:36:08 deb10 prometheus[1397]: level=info ts=2020-01-19T14:36:08.964Z caller=web.go:506 component=web msg="Start listening for connections" add
Jan 19 14:36:08 deb10 prometheus[1397]: level=info ts=2020-01-19T14:36:08.965Z caller=head.go:632 component=tsdb msg="WAL segment loaded" segment=0 maxS
Jan 19 14:36:08 deb10 prometheus[1397]: level=info ts=2020-01-19T14:36:08.966Z caller=main.go:663 fs_type=EXT4_SUPER_MAGIC
Jan 19 14:36:08 deb10 prometheus[1397]: level=info ts=2020-01-19T14:36:08.966Z caller=main.go:664 msg="TSDB started"
Jan 19 14:36:08 deb10 prometheus[1397]: level=info ts=2020-01-19T14:36:08.966Z caller=main.go:734 msg="Loading configuration file" filename=/etc/prometh
Jan 19 14:36:08 deb10 prometheus[1397]: level=info ts=2020-01-19T14:36:08.967Z caller=main.go:762 msg="Completed loading of configuration file" filename
Jan 19 14:36:08 deb10 prometheus[1397]: level=info ts=2020-01-19T14:36:08.967Z caller=main.go:617 msg="Server is ready to receive web requests."

If your server has a firewall service running, you need to open port 9090.

sudo ufw allow 9090/tcp

Confirm that you can connect to port 9090 by accessing the Prometheus server IP address / DNS name in a web browser.

Next, we will introduce the method of installing the exporter on the node to be monitored, and configuring the target on the Prometheus server so that we can use Grafana to delete indicators and visualize them.

Prometheus Monitoring Guide

Monitoring Ceph clusters with Prometheus and Grafana

Monitoring Apache web server with Prometheus and Grafana

How to monitor Linux server performance with Prometheus and Grafana in 5 minutes

How to monitor BIND DNS server with Prometheus and Grafana

How to monitor Redis server with Prometheus and Grafana in 5 minutes

Monitor MySQL / MariaDB with Prometheus in five minutes

Monitoring Etcd clusters with Prometheus

Sidebar