How to install Prometheus on CentOS 8

Share on Social Media

Prometheus is an open-source systems monitoring and alerting tool. Here, You will learn how to install Prometheus on CentOS 8 or similar Linux distributions. #centlinux #linux #prometheus

What is Prometheus? :

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.

A typical monitoring platform with Prometheus is composed of multiple tools.

  • Multiple exporters that typically run on the monitored host to export local metrics.
  • Prometheus to centralize and store the metrics.
  • Alertmanager to trigger alerts based on those metrics.
  • Grafana to produce dashboards.
  • PromQL is the query language used to create dashboards and alerts.

Environment Specification:

We are using a minimal RHEL 8 virtual machine with following specifications.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 2 GB
  • Storage – 20 GB
  • Operating System – Red Hat Enterprise Linux 8.4 
  • Hostname –
  • IP Address – /24

Update Linux Operating System:

Connect with as root user by using a ssh client.

Update your Linux operating system by using dnf command.

# dnf update -y

If the above command updates your Linux Kernel, then reboot your Linux operating system with new Kernel.

# reboot

Verify the Linux operating system and Kernel versions, that are being used in this article.

# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.4 (Ootpa)

# uname -r

Switch SELinux Target Policy to Permissive Mode:

Prometheus currently does not includes an official SELinux policy. Therefore, your have to disable SELinux or switch it into permissive mode for proper functioning of your network monitoring software.

You can execute following commands at Linux Bash prompt to switch SELinux target policy to permissive mode.

# sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/sysconfig/selinux
# setenforce permissive

Create Prometheus User and Directories:

Create a Linux user to own Prometheus software and processes.

# useradd --no-create-home -s /bin/false prometheus

Create required Prometheus directories and adjust the ownership.

# mkdir /etc/prometheus
# mkdir /var/lib/prometheus
# chown prometheus:prometheus /etc/prometheus
# chown prometheus:prometheus /var/lib/prometheus

Install Prometheus on CentOS 8:

You can free download systems monitoring tool from Prometheus official website.

You can use wget command to download Prometheus tarball directly from the Linux CLI. If you don’t have wget command, then install Prometheus on CentOS 8 by using dnf command.

# wget -P /tmp
--2021-09-05 14:30:50--
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 73175122 (70M) [application/octet-stream]
Saving to: ‘/tmp/prometheus-2.29.2.linux-amd64.tar.gz’

prometheus-2.29.2.l 100%[===================>]  69.79M   300KB/s    in 5m 21s

2021-09-05 14:36:13 (222 KB/s) - ‘/tmp/prometheus-2.29.2.linux-amd64.tar.gz’ saved [73175122/73175122]

Extract the downloaded tarball into the /var/lib/prometheus directory.

# tar -xf /tmp/prometheus-2.29.2.linux-amd64.tar.gz -C /var/lib/prometheus/ --strip-components=1

Adjust the ownership of the extracted files.

# chown -R prometheus:prometheus /var/lib/prometheus

Move Prometheus configuration file to /etc/prometheus directory.

# mv /var/lib/prometheus/prometheus.yml /etc/prometheus/

Check the default configurations in prometheus.yml file.

# grep -v '#' /etc/prometheus/prometheus.yml

    - static_configs:
        - targets:


  - job_name: "prometheus"

      - targets: ["localhost:9090"]

Create symbolic links for Prometheus commands at /usr/bin directory to make them globally executable from any path.

# cp -s /var/lib/prometheus/prometheus /usr/bin
# cp -s /var/lib/prometheus/promtool /usr/bin

Create Systemd Service Unit for Prometheus:

To enable autostart of Prometheus server, you are required to create systemd service unit.

# vi /usr/lib/systemd/system/prometheus.service

Add following directives in this file.


--config.file /etc/prometheus/prometheus.yml 
--storage.tsdb.path /var/lib/prometheus/ 


Enable and start Prometheus service.

# systemctl enable --now prometheus.service
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/prometheus.service.

Configure Linux Firewall for Prometheus:

This network monitoring server uses default port 9090/tcp. Therefore, it is necessary to allow it Linux firewall to make it accessible accross the network.

# firewall-cmd --permanent --add-port=9090/tcp
# firewall-cmd --reload

Open URL in a web browser.

Prometheus Dashboard

Open Status > Targets from top menu.

Prometheus Targets

Install Node Exporter on Linux:

Node Exporter is a Prometheus exporter for server level and  level metrics with configurable metric collectors. It helps us in measuring various server resources such as RAM, disk space, and CPU utilization.

You need to install node_exporter on your Prometheus server to gather metrics.

Create directory for Node Exporter software.

# mkdir -p /var/lib/prometheus/node_exporter

Download Node Exporter tarball from Prometheus website.

# wget -P /tmp
--2021-09-05 15:09:51--
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8898481 (8.5M) [application/octet-stream]
Saving to: ‘/tmp/node_exporter-1.2.2.linux-amd64.tar.gz’

node_exporter-1.2.2.linux-amd6 100%[==================================================>]   8.49M  74.0KB/s    in 2m 12s

2021-09-05 15:12:07 (65.7 KB/s) - ‘/tmp/node_exporter-1.2.2.linux-amd64.tar.gz’ saved [8898481/8898481]

Extract downloaded tarball into /var/lib/prometheus/node_exporter/ directory.

# tar xf /tmp/node_exporter-1.2.2.linux-amd64.tar.gz -C /var/lib/prometheus/node_exporter/ --strip-components=1

Adjust directory ownership.

# chown -R prometheus:prometheus /var/lib/prometheus/node_exporter/

Create a symbolic link for node_exporter at /usr/bin directory.

# cp -s /var/lib/prometheus/node_exporter/node_exporter /usr/bin/

Enable autostart of node_exporter process, create a systemd service unit.

# vi /usr/lib/systemd/system/node_exporter.service

Add following lines of code in this file.

Description=Node Exporter



Enable and start Node Exporter service.

# systemctl enable --now node_exporter.service
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/node_exporter.service.

Configure Linux firewall to allow node_exporter default port 9100/tcp.

# firewall-cmd --permanent --add-port=9100/tcp
# firewall-cmd --reload

Edit Prometheus configuration file in vim text editor.

# vi /etc/prometheus/prometheus.yml

Add the node_exporter endpoint configuration in this file.

 - job_name: 'node_exporter'
    - targets: ['localhost:9100']

Restart Prometheus service to load new configurations.

# systemctl restart prometheus.service

Open Status > Targets or refresh the web page, if already opened.

Prometheus Add Targets


In this article, you have learned how to install Prometheus on CentOS 8 or similar Linux distributions. If you want to learn more about Prometheus software than you should read Prometheus: Up & Running (PAID LINK) by O’Reilly Media.