Install Prometheus in Linux CentOS 7

From Gejoreuy
Revision as of 21:06, 7 November 2020 by Gejor (talk | contribs)
Jump to navigation Jump to search

Introduction

Prometheus is an open-source systems monitoring and alerting tool.
Refer to Prometheus page to know more about this tools : https://prometheus.io/docs/introduction/overview

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 https://api.github.com/repos/prometheus/prometheus/releases/latest | 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 :

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
Environment="GOMAXPROCS=1"
User=prometheus
Group=prometheus
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=0.0.0.0:9090 \
  --web.external-url=

SyslogIdentifier=prometheus
Restart=always

[Install]
WantedBy=multi-user.target

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=5000/tcp
[root@monitoring-server ~]# firewall-cmd --reload