Prometheus is a free software application used for event monitoring and alerting. It records real-time metrics in a time series database 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.
Update System
Update your Linux operating system with
# dnf update -y
Prometheus currently does not includes an official SELinux policy. So you have to disable SELinux or switch it into permissive mode.
# sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/sysconfig/selinux
# setenforce permissive
Create Prometheus User and Directories
To own Prometheus software and processes.
# useradd --no-create-home -s /bin/false prometheus
Create required Prometheus directories and edit the ownership.
# mkdir /etc/prometheus
# mkdir /var/lib/prometheus
# chown prometheus:prometheus /var/lib/prometheus
# chown prometheus:prometheus /etc/prometheus
Install Prometheus
You can download it from Prometheus official website.
Download Prometheus tarball with wget command as following below.
[root@unixcop ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.29.2/prometheus-2.29.2.linux-amd64.tar.gz -P /tmp
--2021-09-09 11:02:11-- https://github.com/prometheus/prometheus/releases/download/v2.29.2/prometheus-2.29.2.linux-amd64.tar.gz
Resolving github.com (github.com)... 140.82.121.3
Connecting to github.com (github.com)|140.82.121.3|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-releases.githubusercontent.com/6838921/17d3d453-5a8e-47aa-844f-d4ff56f5c1cb?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210909%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210909T150118Z&X-Amz-Expires=300&X-Amz-Signature=04f95de9924949000d3cf5b51d508db4a101e6741d13540d60b0b8c7618421bc&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=6838921&response-content-disposition=attachment%3B%20filename%3Dprometheus-2.29.2.linux-amd64.tar.gz&response-content-type=application%2Foctet-stream [following]
--2021-09-09 11:02:13-- https://github-releases.githubusercontent.com/6838921/17d3d453-5a8e-47aa-844f-d4ff56f5c1cb?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210909%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210909T150118Z&X-Amz-Expires=300&X-Amz-Signature=04f95de9924949000d3cf5b51d508db4a101e6741d13540d60b0b8c7618421bc&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=6838921&response-content-disposition=attachment%3B%20filename%3Dprometheus-2.29.2.linux-amd64.tar.gz&response-content-type=application%2Foctet-stream
Resolving github-releases.githubusercontent.com (github-releases.githubusercontent.com)... 185.199.111.154, 185.199.108.154, 185.199.110.154, ...
Connecting to github-releases.githubusercontent.com (github-releases.githubusercontent.com)|185.199.111.154|: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.linux-amd64.tar.gz 100%[=======================================================================>] 69.79M 169KB/s in 6m 30s
2021-09-09 11:08:43 (183 KB/s) - '/tmp/prometheus-2.29.2.linux-amd64.tar.gz' saved [73175122/73175122]
[root@unixcop ~]#
Then extract the downloaded Prometheus tarball into the /var/lib/prometheus as shown.
tar -xf /tmp/prometheus-2.29.2.linux-amd64.tar.gz -C /var/lib/prometheus/ --strip-components=1
Give the ownership of the extracted files to Prometheus user with:
chown -R prometheus:prometheus /var/lib/prometheus
Move Prometheus configuration file to /etc/prometheus with:
mv /var/lib/prometheus/prometheus.yml /etc/prometheus/
Also check the configurations of prometheus.yml file as shown below:
[root@unixcop ~]# grep -v '#' /etc/prometheus/prometheus.yml
global:
alerting:
alertmanagers:
- static_configs:
- targets:
rule_files:
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
[root@unixcop ~]#
Also create symbolic links for Prometheus to make them executable from any path.
# cp -s /var/lib/prometheus/promtool /usr/bin
# cp -s /var/lib/prometheus/prometheus /usr/bin
Create Systemd Service Unit for Prometheus
You are required to create systemd service unit for enabling an Autostart of Prometheus.
Follow these steps:
# vim /usr/lib/systemd/system/prometheus.service
Then add the following.
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/var/lib/prometheus/consoles \
--web.console.libraries=/var/lib/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
Then enable and start Prometheus with:
[root@unixcop ~]# systemctl enable --now prometheus.service
Created symlink /etc/systemd/system/multi-user.target.wants/prometheus.service → /usr/lib/systemd/system/prometheus.service.
[root@unixcop ~]#
Also configure Firewall for Prometheus
The default port 9090/tcp. So it is necessary to allow it to.
[root@unixcop ~]# firewall-cmd --permanent --add-port=9090/tcp
success
[root@unixcop ~]# firewall-cmd --reload
success
[root@unixcop ~]#
Open URL http://localhost:9090 in a web browser as shown in below screenshot
Install Node Exporter
Node Exporter is a Prometheus exporter for server level and level metrics with configurable metric collectors. It helps us in measuring server resources such as disk space, RAM and CPU utilization.
You need to install node_exporter on your Prometheus server .
Firstly, make a directory for Node Exporter as follow:
# mkdir -p /var/lib/prometheus/node_exporter
Download Node_Exporter from Prometheus website.
[root@unixcop ~]# wget https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz -P /tmp
--2021-09-09 11:42:18-- https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz
Resolving github.com (github.com)... 140.82.121.4
Connecting to github.com (github.com)|140.82.121.4|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-releases.githubusercontent.com/9524057/28598a7c-d8ad-483d-85ba-8b2c9c08cf57?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210909%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210909T154012Z&X-Amz-Expires=300&X-Amz-Signature=2581f24124ad04eeb9d7ead72729c4afbcfe08ade2e37a8d3ffa0eb876ab0091&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=9524057&response-content-disposition=attachment%3B%20filename%3Dnode_exporter-1.2.2.linux-amd64.tar.gz&response-content-type=application%2Foctet-stream [following]
--2021-09-09 11:42:19-- https://github-releases.githubusercontent.com/9524057/28598a7c-d8ad-483d-85ba-8b2c9c08cf57?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210909%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210909T154012Z&X-Amz-Expires=300&X-Amz-Signature=2581f24124ad04eeb9d7ead72729c4afbcfe08ade2e37a8d3ffa0eb876ab0091&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=9524057&response-content-disposition=attachment%3B%20filename%3Dnode_exporter-1.2.2.linux-amd64.tar.gz&response-content-type=application%2Foctet-stream
Resolving github-releases.githubusercontent.com (github-releases.githubusercontent.com)... 185.199.108.154, 185.199.110.154, 185.199.109.154, ...
Connecting to github-releases.githubusercontent.com (github-releases.githubusercontent.com)|185.199.108.154|: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-amd64.tar.g 100%[=======================================================================>] 8.49M 204KB/s in 42s
2021-09-09 11:43:02 (207 KB/s) - '/tmp/node_exporter-1.2.2.linux-amd64.tar.gz' saved [8898481/8898481]
[root@unixcop ~]#
Then extract downloaded tarball to /var/lib/prometheus/node_exporter/ with the following command.
# tar xf /tmp/node_exporter-1.2.2.linux-amd64.tar.gz -C /var/lib/prometheus/unixcop_node_exporter/ --strip-components=1
Modify the ownership.
# chown -R prometheus:prometheus /var/lib/prometheus/unixcop_node_exporter/
Also create a symbolic link for node_exporter with:
[root@unixcop ~]# cp -s /var/lib/prometheus/unixcop_node_exporter/node_exporter /usr/bin/
Enable autostart of node_exporter process, create a systemd service unit.
vim /usr/lib/systemd/system/unixcop_node_exporter.service
Then add the following:
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
ExecStart=/usr/bin/node_exporter
[Install]
WantedBy=default.target
Enable and start Node Exporter with command below:
[root@unixcop ~]# systemctl enable --now unixcop_node_exporter.service
Created symlink /etc/systemd/system/default.target.wants/node_exporter.service → /usr/lib/systemd/system/node_exporter.service.
[root@unixcop ~]#
Also configure firewall to allow node_exporter port 9100/tcp.
[root@unixcop ~]# firewall-cmd --permanent --add-port=9100/tcp
success
[root@unixcop ~]# firewall-cmd --reload
success
[root@unixcop ~]#
Then edit Prometheus configuration file.
# vi /etc/prometheus/prometheus.yml
And add the unixcop_node_exporter endpoint configuration in this file.
- job_name: 'unixcop_node_exporter'
static_configs:
- targets: ['localhost:9100']
Then restart Prometheus.
# systemctl restart prometheus.service
Open your browser then go to prometheus.
Open Status
Then click on Targets .
Conclusion
In this article, we explained how to install Prometheus systems monitoring tool on CentOS / RHEL 8.
Also we illustrated how to install Node Exporter for server level and level metrics that helps us to measure server resources such as disk space, RAM and CPU utilization.
There is an error in the mkdir instruction for node_exporter
mkdir -p /var/lib/prometheus/node_exporter
# tar xf /tmp/node_exporter-1.2.2.linux-amd64.tar.gz -C /var/lib/prometheus/unixcop_node_exporter/ –strip-components=1
So the mkdir should be:
mkdir -p /var/lib/prometheus/unixcop_node_exporter