How To Install Prometheus on Ubuntu 20.04

Install Prometheus on Ubuntu 20.04

In this article, we will have explained the necessary steps to install and configure Prometheus on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Prometheus is used for monitoring and alerts. Prometheus provides system and application monitoring which is essential for microservices architecture. Prometheus is also part of cloud-native computing foundation (CNCF). Using Prometheus you can optimize monitor the microservice and optimize them.

Install Prometheus on Ubuntu 20.04

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade

Step 2. Create a Prometheus system group

We have to create the user and group called Prometheus and also the directory called Prometheus:

sudo useradd -s /sbin/nologin --system -g prometheus prometheus
sudo mkdir /var/lib/prometheus

Step 3. Install Prometheus on the Ubuntu system.

We need to download the latest release of Prometheus:

mkdir -p /tmp/prometheus && cd /tmp/prometheus
curl -s | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi -
tar xvf prometheus*.tar.gz

Use the following commands to copy the “prometheus” binary files to the /usr/local/bin:

sudo mv prometheus promtool /usr/local/bin/

Check installed version:

$ prometheus --version
prometheus, version 2.15.2 (branch: HEAD, revision: d9613e5c466c6bmw48c4dae1b9aabf9aaf7c57)
  build user:       root@688433cf4ff7
  build date:       20200906-14:50:51
  go version:       go1.13.5

Step 4. Configure Prometheus.

We will create the configuration file named prometheus.yml in the /etc/prometheus directory created in the previous steps. Issue the following command to edit the prometheus.yml file:

sudo mv prometheus.yml /etc/prometheus/prometheus.yml
sudo mv consoles/ console_libraries/ /etc/prometheus/
sudo nano /etc/prometheus/prometheus.yml

Configure basic settings:

my global config
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
static_configs: targets:
# - alertmanager:9093
Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
# - "first_rules.yml"
# - "second_rules.yml"
A scrape configuration containing exactly one endpoint to scrape:
Here it's Prometheus itself.
# 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'.
targets: ['localhost:9090']

Step 5. Create a Prometheus systemd Service unit file.

Now, we will create another file for the systemd service:

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

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= \



Once you are done with the above configurations, reload systemd using the following command:

sudo systemctl daemon-relaod
sudo systemctl start prometheus
sudo systemctl enable prometheus

Step 6. Configure Firewall.

Open Prometheus port on the firewall (UFW) if it is running. By default, it listens on TCP port 9090:

sudo ufw allow 9090/tcp

Step 7. Accessing Prometheus.

The Prometheus application is now has been ready to receive web requests. We can access it via a web browser using the address, http://server-IP-address:9090.

That’s all you need to do to install Prometheus on Ubuntu 20.04 LTS Focal Fossa. I hope you find this quick tip helpful. For further reading on Prometheus, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.