Install Prometheus in Linux CentOS 7

From Gejoreuy
Jump to navigation Jump to search


Prometheus is an open-source systems monitoring and alerting tool.
Prometheus will work as monitoring server if monitoring target already set with Prometheus exporter.
There are many types of exporter : node-exporter, nginx-exporter, postgres-exporter, etc.
Refer to Prometheus page to know more about this tools :

Step by Step

Step 1 : Prepare User & Group for Prometheus

[root@monitoring-server ~]# groupadd --system prometheus
[root@monitoring-server ~]# useradd -s /sbin/nologin --system -g prometheus prometheus

Step 2 : Prepare Directories for Prometheus

[root@monitoring-server ~]# mkdir /var/lib/prometheus
[root@monitoring-server ~]# for i in rules rules.d files_sd; do sudo mkdir -p /etc/prometheus/${i}; done

Step 3 : Download Prometheus

[root@monitoring-server ~]# cd Temp
[root@monitoring-server Temp]# curl -s | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4  | wget -qi -
[root@monitoring-server Temp]# tar xvf prometheus*.tar.gz
[root@monitoring-server Temp]# cd prometheus*
[root@monitoring-server Temp]# mv prometheus promtool /usr/local/bin/
[root@monitoring-server Temp]# mv prometheus.yml  /etc/prometheus/prometheus.yml
[root@monitoring-server Temp]# mv consoles/ console_libraries/ /etc/prometheus/

Step 4 : Set System Service

Create service file :

[root@monitoring-server ~]# vi /etc/systemd/system/prometheus.service

Fill with below value :


ExecReload=/bin/kill -HUP $MAINPID
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 \
  --web.listen-address= \



Make sure GOMAXPROCS value is same with real vcpus count in our prometheus server.

Step 5 : Set Prometheus Files Owner

[root@monitoring-server ~]# for i in rules rules.d files_sd; do sudo chown -R prometheus:prometheus /etc/prometheus/${i}; done
[root@monitoring-server ~]# for i in rules rules.d files_sd; do sudo chmod -R 775 /etc/prometheus/${i}; done
[root@monitoring-server ~]# chown -R prometheus:prometheus /var/lib/prometheus/

Step 6 : Start and Enable Prometheus

[root@monitoring-server ~]# systemctl daemon-reload
[root@monitoring-server ~]# systemctl start prometheus
[root@monitoring-server ~]# systemctl enable prometheus
[root@monitoring-server ~]# systemctl status prometheus

Step 7 : Enable Prometheus Port

[root@monitoring-server ~]# firewall-cmd --zone=public --permanent --add-port=9090/tcp
[root@monitoring-server ~]# firewall-cmd --reload

After all the steps above done, we access prometheus from browser : http://monitoring-server:9090

How to Use

If we have done all the steps correctly, we can see the Prometheus page without any metric because Prometheus server will get data from an exporter.
Next, we'll install node-exporter into a target server that need to be monitored and connect it to this Prometheus.
For installing node-exporter, follow : Install Node Exporter in Linux CentOS 7 and Connect It to Prometheus Server