How to Install Grafana with Prometheus on Centos 7

SHORT INTRODUCTION

Grafana with Prometheus

----First, Setup For Prometheus----

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/consoles_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

----Now, Setup For Grafana----

Login to the Grafana-server – 192.168.33.31

Step 1: Insert the Grafana's repository file

Copy Paste the below lines in the file –

[root@grafana ~]# vim /etc/yum.repos.d/grafana.repo
 
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt

Step 2 : Install Grafana

[root@grafana ~]# yum install grafana -y

Start & Enable the grafana services

[root@grafana ~]# systemctl start grafana-server
[root@grafana ~]# systemctl enable grafana-server
[root@grafana ~]# systemctl status grafana-server

Open your browser & type the url with port “3000”  as shown below

http://192.168.33.31:3000/

Default “Username/Password” is “admin/admin”

After login from default Id, You can change your password or you can skip it as you choice

Here’s the Dashboard of Grafana –

Add the Data Source & Select the Prometheus as shown below –

Insert your Prometheus-Server-IP with port “9090” & Save it-

Here’s the Grafana Monitoring Dashboard

You may also like...

Leave a Reply

Your email address will not be published.