How to install and configure Prometheus on CentOS 7

SHORT INTRODUCTION

Prometheus is a free open source application used for event monitoring and awareness. Collects and records real-time metrics in a series of data areas. Prometheus is written on Go and distributed under Apache License 2.0.

Prometheus requires many exports to be targeted. The issuer releases and publishes metrics to the appropriate port in the target area. The Prometheus monitoring server will capture these instruments and store them in the timeline. Following the masterpiece from Prometheus, Texts clarifies the concept and flow of the program.

We need two servers: Main-server (192.168.33.25) &  Client-server (192.168.33.30), Make sure both are accessible

Login to fosnix servers – 192.168.33.25

Step 1: Update & Disable SELinux

[root@fosnix ~]# yum update -y
[root@fosnix ~]# vim /etc/sysconfig/selinux

Replace “SELINUX=disabled” from “SELINUX=enforcing”

Save & Exit from file

Then, Reboot the System

Step 2 : Download Prometheus package

Run the below command to download the package- 

[root@fosnix ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.8.1/prometheus-2.8.1.linux-amd64.tar.gz

Step 3 : Configure Prometheus

Add a Prometheus user

[root@fosnix ~]# useradd --no-create-home --shell /bin/false prometheus

Create directories & change the owner of them

[root@fosnix ~]# mkdir /etc/prometheus
[root@fosnix ~]# mkdir /var/lib/prometheus
[root@fosnix ~]# chown prometheus:prometheus /etc/prometheus
[root@fosnix ~]# chown prometheus:prometheus /var/lib/prometheus

Now Extract the Prometheus downloaded file & Rename it- 

[root@fosnix ~]# tar -xvzf prometheus-2.8.1.linux-amd64.tar.gz
[root@fosnix ~]# mv prometheus-2.8.1.linux-amd64 prometheuspackage

Copy “prometheus” and “promtool” binary from the “prometheuspackage” directory to “/usr/local/bin” & Change the ownership of them to prometheus user

[root@fosnix ~]# cp prometheuspackage/prometheus /usr/local/bin/
[root@fosnix ~]# cp prometheuspackage/promtool /usr/local/bin/
[root@fosnix ~]# chown prometheus:prometheus /usr/local/bin/prometheus
[root@fosnix ~]# chown prometheus:prometheus /usr/local/bin/promtool

Copy “consoles” and “console_libraries” directories from the “prometheuspackage” to “/etc/prometheus” directory & Change the ownership of them to prometheus user

[root@fosnix ~]# cp -r prometheuspackage/consoles /etc/prometheus
[root@fosnix ~]# cp -r prometheuspackage/console_libraries /etc/prometheus
[root@fosnix ~]# chown -R prometheus:prometheus /etc/prometheus/consoles
[root@fosnix ~]# chown -R prometheus:prometheus /etc/prometheus/console_libraries

Now, to configure the prometheus file you have to create the prometheus.yml file & add the below lines in it

[root@fosnix ~]# vim /etc/prometheus/prometheus.yml
global:
  scrape_interval: 10s

scrape_configs:
  - job_name: 'prometheus_master'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']

Save & Exit from file

Change the Ownership of the File

[root@fosnix ~]# chown prometheus:prometheus /etc/prometheus/prometheus.yml

Configure the Prometheus Service File-
Create a file and Copy paste the below lines into it

[root@fosnix ~]# vim /etc/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=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target

Save & Exit from file,

Restart the systemd file & Prometheus service

[root@fosnix ~]# systemctl daemon-reload
[root@fosnix ~]# systemctl start prometheus
[root@fosnix ~]# systemctl status prometheus

If your firewall is on, so stop it from the below command- 

[root@fosnix ~]# systemctl stop firewalld

Step 4 : Access Prometheus Web Interface

Open your browser & type the below URL with your SERVER-IP

http://Your-Server-IP:9090/graph

Step 5 : Monitor Client Server Using Prometheus

Login to Client servers – 192.168.33.30

You need to download node exporter first by run the command below – 

[root@fosnix ~]# wget https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz

Now, Extract the package

[root@fosnix ~]# tar -xvzf node_exporter-0.17.0.linux-amd64.tar.gz

Next, Create a user for node-exporter & move to /usr/local/bin

[root@fosnix ~]# useradd -rs /bin/false nodeusr
[root@fosnix ~]# mv node_exporter-0.17.0.linux-amd64/node_exporter /usr/local/bin/

Create a file for node-exporter & copy paste the lines below in it

[root@fosnix ~]# vim /etc/systemd/system/node_exporter.service
 
[Unit]
Description=Node Exporter
After=network.target
[Service]
User=nodeusr
Group=nodeusr
Type=simple
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.target

Save & Exit from file,

Restart the system daemon,  also start & enable the node exporter

[root@fosnix ~]# systemctl daemon-reload
[root@fosnix ~]# systemctl start node_exporter
[root@fosnix ~]# systemctl enable node_exporter

If your firewall is on, so stop it from the below command- 

Open your browser & type the below URL with your SERVER-IP

http://Your-IP-Address:9100/metrics

Login back to the main-servers – 192.168.33.25

To configure the node exporter modify the prometheus.yml file

Add the below lines in the file as shown below –

[root@fosnix ~]# vim /etc/prometheus/prometheus.yml
  - job_name: 'node_exporter_centos'
    scrape_interval: 5s
    static_configs:
      - targets: ['192.168.33.30:9100']

Restart the prometheus service –

[root@fosnix ~]# systemctl restart prometheus

Open your browser & type the below URL with your SERVER-IP

http://Main-Server-IP:9090/targets

You may also like...

Leave a Reply

Your email address will not be published.