How to install Prometheus on CentOS 7 / Redhat

Prometheus is an open source monitoring and alerting tool, which is used to monitor the servers and applications. It scrapes metrics from instrumented jobs, either directly or via an intermediary push gateway for short-lived jobs. It stores all scraped samples locally and runs rules over this data to either aggregate and record new time series from existing data or generate alerts. It has multiple exporters for multiple use, through the exporters we can get different kind of metrics.

Open selinux configuration and disable selinux

vim /etc/sysconfig/selinux

Download Prometheus Package, go to Prometheus.io/download/

wget  https://github.com/prometheus/prometheus/releases/download/v2.18.0-rc.1/prometheus-2.18.0-rc.1.linux-amd64.tar.gz

Now extract the downloaded package

tar   -xvzf   XXXXXXXX.tar.gz

add Prometheus user

useradd   –no-create-home   –shell   /bin/false   prometheus

create directories

mkdir    /etc/prometheus
mkdir   /var/lib/prometheus

change the owner and group of the directory                                                      

chown prometheus:prometheus  /etc/Prometheus
chown prometheus:prometheus  /var/lib/Prometheus

Copy “prometheus” and “promtool” binary from the “prometheus-2.18.1.linux-amd64” folder to “/usr/local/bin”

cp prometheus-2.18.1.linux-amd64/promtool /usr/local/bin/
cp prometheus-2.18.1.linux-amd64/prometheus /usr/local/bin/

Change the ownership to Prometheus user

chown prometheus:prometheus /usr/local/bin/prometheus
chown prometheus:prometheus /usr/local/bin/promtool

Copy “consoles” and “console_libraries” directories from the “prometheus-2.18.1.linux-amd64” to “/etc/prometheus folder”

cp -r prometheus-2.18.1.linux-amd64/consoles /etc/prometheus
cp -r prometheus-2.18.1.linux-amd64/console_libraries /etc/prometheus

Change the ownership to Prometheus user

chown -R prometheus:prometheus /etc/prometheus/consoles
chown -R prometheus:prometheus /etc/prometheus/console_libraries

Add and modify Prometheus configuration file

Configurations should be added to the  “/etc/prometheus/prometheus.yml”

Now we will create the prometheus.yml file

vim /etc/prometheus/prometheus.yml

Add the following configuration to the file

global:
  scrape_interval: 10s

scrape_configs:
  – job_name: ‘prometheus_master’
    scrape_interval: 5s
    static_configs:
      – targets: [‘localhost:9090’]

Change the ownership of the file

chown prometheus:prometheus /etc/prometheus/prometheus.yml

Configure and create the prometheus service file.

vim /etc/systemd/system/prometheus.service

Copy the following content to the file.

[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

Now  reload and start the prometheus service.

systemctl daemon-reload
systemctl start prometheus

 Check the status of prometheus.

systemctl status prometheus

Use the following URL to access UI.

http://Server-IP:9090/graph

Your Prometheus server is ready

Note port numbers:-

Prometheus port: 9090

node_exporter port: 9100

alertmanager port: 9093

wmi_exporter: 9182

 

 

How to install Prometheus on CentOS 7 / Redhat

Leave a Reply

Your email address will not be published. Required fields are marked *