top of page
Recent Posts

How to install and configure Prometheus & grafana in Red Hat Enterprise Linux 7

Updated: Oct 3, 2021

Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. The Prometheus ecosystem consists of multiple components, many of which are optional:

  • the main Prometheus server which scrapes and stores time series data

  • client libraries for instrumenting application code

  • a push gateway for supporting short-lived jobs

  • special-purpose exporters for services like HAProxy, StatsD, Graphite, etc.

  • an alertmanager to handle alerts

  • various support tools

Grafana is open source visualization and analytics software. It allows you to query, visualize, alert on, and explore your metrics no matter where they are stored. In plain English, it provides you with tools to turn your time-series database (TSDB) data into beautiful graphs and visualizations. Grafana supports querying Prometheus.


The architecture of Prometheus and some of its ecosystem components:

And Prometheus + Grafana could be the complementary services that consider as a tools to build up a monitoring system. Lets start the configuration.


Installing Prometheus Server:

Step:1 To download Prometheus binaries for Linux from https://prometheus.io/download/

# cd /tmp/ 
# wget https://github.com/prometheus/prometheus/releases/download/v2.20.0/prometheus-2.20.0.linux-amd64.tar.gz 

::::::::::::: CUT SOME OUTPUT :::::::::::::

100%[========================================================================================================>] 65,312,139   287KB/s   in 5m 25s 
2020-07-25 18:16:23 (196 KB/s) - ‘prometheus-2.20.0.linux-amd64.tar.gz’ saved [65312139/65312139]

Step:2 To prepared prerequisite configurations for Prometheus.

# ueradd --no-create-home -s /bin/false prometheus
# mkdir /etc/prometheus
# mkdir /var/lib/prometheus
# chown prometheus:prometheus /etc/prometheus
# chown prometheus:prometheus /var/lib/prometheus

Step:3 To extract downloaded zip file & configure Prometheus.

# tar -zxvf /root/prometheus-2.20.0.linux-amd64.tar.gz 
prometheus-2.20.0.linux-amd64/
::::::::::::: CUT SOME OUTPUT :::::::::::::
prometheus-2.20.0.linux-amd64/LICENSE

# mv /var/lib/prometheus/prometheus.yml /etc/prometheus/
# chown -R prometheus:prometheus /var/lib/prometheus

# mv /var/lib/prometheus/prometheus.yml /etc/prometheus/
# ln -s /var/lib/prometheus/prometheus /usr/local/bin/prometheus

Step:4 To create a systemd configuration file for Prometheus.

# vi /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus
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=/var/lib/prometheus/consoles \
--web.console.libraries=/var/lib/prometheus/console_libraries

[Install]
WantedBy=multi-user.target

Step:5 To start the Prometheus service.

# systemctl enable --now prometheus
Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /usr/lib/systemd/system/prometheus.service.
# systemctl status prometheus

Step:6 To open port in firewall, if firewall service is running.

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

Step:7 To verify the Prometheus service, open the URL http://<prometheus_ipaddress>:9090 using a client's browser.

OK, good to go for the next.



Installing Node_Exporter:

Prometheus receives metrics from many sources like machines, databases, applications, etc. But the most common Exporter that we prefer to install on each node to collect machine metrics is the node_exporter. Let's install the Node_Exporter.


Step:1 To download Node_Exporter from Prometheus Download Page.

# cd /tmp
# wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
--2020-07-27 13:19:58--  https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz 

::::::::::::: CUT SOME OUTPUT :::::::::::::

100%[========================================================================================================>] 9,520,728    149KB/s   in 57s    
::::::::::::: CUT SOME OUTPUT :::::::::::::
2020-07-27 13:20:57 (164 KB/s) - ‘node_exporter-1.0.1.linux-amd64.tar.gz’ saved [9520728/9520728]

Step:2 To prepared prerequisite configurations for Node_Exporter.

# ueradd --no-create-home -s /bin/false prometheus
# mkdir -p /var/lib/prometheus/node_exporter

Step:3 To extract downloaded zip file & configure Node_Exporter.

# tar xvf node_exporter-1.0.1.linux-amd64.tar.gz 
node_exporter-1.0.1.linux-amd64/
node_exporter-1.0.1.linux-amd64/NOTICE
node_exporter-1.0.1.linux-amd64/node_exporter
node_exporter-1.0.1.linux-amd64/LICENSE
# mv node_exporter-1.0.1.linux-amd64/* /var/lib/prometheus/node_exporter
# chown -R prometheus:prometheus /var/lib/prometheus/node_exporter/

Step:4 To create a systemd configuration file for Node_Exporter.