How to install Prometheus on Centos 8

How to install Prometheus on CentOS8 1

On this article we are going to discuss about Prometheus version 2.24.1 installation on CentOS 8 operating system.

Introduction

Prometheus is a free software application used for event monitoring and alerting. Prometheus fundamentally stores all data as time series: streams of timestamped values belonging to the same metric and the same set of labeled dimensions. Besides stored time series, Prometheus may generate temporary derived time series as the result of queries. Prometheus was developed at SoundCloud starting in 2012. On this article we will discuss how to install the latest stable of Prometheus on CentOS 8 operating system.

Prometheus Installation on CentOS 8

The installation will be consiste of several steps, as summarize below :

  1. Prerequisite
  2. Create promeutheus user on CentOS 8 system
  3. Download and Extract Promotheus Binary Files
  4. Create Prometheus Configuration file
  5. Creating SystemD and Running Prometheus Service
  6. Accessing Prometheus from Web Interface

1. Prerequisite

  • CentOS 8 opearting system with root or user account with sudo privilege.
  • Sufficient space and good internet connection.

2. Create promeutheus user on CentOS 8 system

Prometheus System User and Group. We have to create the user and group called as prometheus and also the directory called as prometheus. For this purpose we submit the command line below:

$ sudo groupadd --system prometheus
$ sudo useradd -s /sbin/nologin --system -g prometheus prometheus

Output :
[ramans@otodiginet ~]$ sudo groupadd --system prometheus
[sudo] password for ramans: 
[ramans@otodiginet ~]$ sudo useradd -s /sbin/nologin --system -g prometheus prometheus

Then we will create a new directory where prometheus application files will be located, by using root account :

[root@otodiginet ~]# useradd -m -s /bin/false prometheus
[root@otodiginet ~]# id prometheus
uid=1002(prometheus) gid=1002(prometheus) groups=1002(prometheus)
[root@otodiginet ~]# 
[root@otodiginet ~]# mkdir /etc/prometheus
[root@otodiginet ~]# mkdir /var/lib/prometheus
[root@otodiginet ~]# chown prometheus /var/lib/prometheus/

3. Download and Extract Promotheus Binary Files

On this step, we will download Promethesu source file. For this purpose, we will use wget command line.

wget https://github.com/prometheus/prometheus/releases/download/v2.24.1/prometheus-2.24.1.linux-amd64.tar.gz -P /tmp

Output :

[root@otodiginet ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.24.1/prometheus-2.24.1.linux-amd64.tar.gz -P /tmp
--2021-02-13 08:13:47-- https://github.com/prometheus/prometheus/releases/download/v2.24.1/prometheus-2.24.1.linux-amd64.tar.gz
Resolving github.com (github.com)... 52.74.223.119
Connecting to github.com (github.com)|52.74.223.119|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-releases.githubusercontent.com/6838921/60936500-5acd-11eb-99bb-1403e7a1010d?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210213%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210213T161347Z&X-Amz-Expires=300&X-Amz-Signature=c59b25d958ef5f5ae5982a4c75d513ba1d0de24af33eeb6eed236e5e8a09769a&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=6838921&response-content-disposition=attachment%3B%20filename%3Dprometheus-2.24.1.linux-amd64.tar.gz&response-content-type=application%2Foctet-stream [following]
--2021-02-13 08:13:47-- https://github-releases.githubusercontent.com/6838921/60936500-5acd-11eb-99bb-1403e7a1010d?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210213%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210213T161347Z&X-Amz-Expires=300&X-Amz-Signature=c59b25d958ef5f5ae5982a4c75d513ba1d0de24af33eeb6eed236e5e8a09769a&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=6838921&response-content-disposition=attachment%3B%20filename%3Dprometheus-2.24.1.linux-amd64.tar.gz&response-content-type=application%2Foctet-stream
Resolving github-releases.githubusercontent.com (github-releases.githubusercontent.com)... 185.199.109.154, 185.199.111.154, 185.199.110.154, ...
Connecting to github-releases.githubusercontent.com (github-releases.githubusercontent.com)|185.199.109.154|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 65509305 (62M) [application/octet-stream]
Saving to: ‘/tmp/prometheus-2.24.1.linux-amd64.tar.gz’

prometheus-2.24.1.linux-amd 100%[========================================>] 62.47M 417KB/s in 1m 48s

2021-02-13 08:15:36 (592 KB/s) - ‘/tmp/prometheus-2.24.1.linux-amd64.tar.gz’ saved [65509305/65509305]

4. Extract Prometheus Source File

After download was completed done, then we will extract it by using command line:

# tar -zxpvf prometheus-2.24.1.linux-amd64.tar.gz

Output :

[root@otodiginet tmp]# tar -zxpvf prometheus-2.24.1.linux-amd64.tar.gz
prometheus-2.24.1.linux-amd64/
prometheus-2.24.1.linux-amd64/consoles/
prometheus-2.24.1.linux-amd64/consoles/index.html.example
prometheus-2.24.1.linux-amd64/consoles/node-cpu.html
prometheus-2.24.1.linux-amd64/consoles/node-disk.html
prometheus-2.24.1.linux-amd64/consoles/node-overview.html
prometheus-2.24.1.linux-amd64/consoles/node.html
prometheus-2.24.1.linux-amd64/consoles/prometheus-overview.html
prometheus-2.24.1.linux-amd64/consoles/prometheus.html
prometheus-2.24.1.linux-amd64/console_libraries/
prometheus-2.24.1.linux-amd64/console_libraries/menu.lib
prometheus-2.24.1.linux-amd64/console_libraries/prom.lib
prometheus-2.24.1.linux-amd64/prometheus.yml
prometheus-2.24.1.linux-amd64/LICENSE
prometheus-2.24.1.linux-amd64/NOTICE
prometheus-2.24.1.linux-amd64/prometheus
prometheus-2.24.1.linux-amd64/promtool

The Application structure file will be as shown below.

[root@otodiginet tmp]# tree prometheus-2.24.1.linux-amd64
prometheus-2.24.1.linux-amd64
├── console_libraries
│   ├── menu.lib
│   └── prom.lib
├── consoles
│   ├── index.html.example
│   ├── node-cpu.html
│   ├── node-disk.html
│   ├── node.html
│   ├── node-overview.html
│   ├── prometheus.html
│   └── prometheus-overview.html
├── LICENSE
├── NOTICE
├── prometheus
├── prometheus.yml
└── promtool

2 directories, 14 files

[root@otodiginet prometheus-2.24.1.linux-amd64]# cp prometheus /usr/local/bin
[root@otodiginet prometheus-2.24.1.linux-amd64]# cp promtool /usr/local/bin

5. Create Prometheus Configuration file

On this stage we will create a Prometheus configuration file. The configuration file will be located on /etc/prometheus/prometheus.yml.   The prometheus configuration file is call ed as prometheus.yml. And the sample Prometheus configuration file has been prepared and available on the extracted archive folder, just copy it to Prometheus configuration directory (/etc/prometheus). The content of promethues.yml file will be shown below.

# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'

# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.

static_configs:
- targets: ['localhost:9090']
~

On our tutorial, we will let the Prometheus configuration file will be as default.

6. Setting Prometheus systemd unit File

On this stage, we will set up Prometheus systemd file, the file will be located on /etc/systemd/system/prometheus.service. For this purposer we will create a new file and the content will be as follow :

# vi /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Time Series Collection and Processing Server
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

7. Running Prometheus Service

After all are set, then we will start Prometheus service. After it has been starting, we can access Prometheus by web browser which was defined on configuration file above.

Starting Prometheus Service by submitting command line :

# systemctl daemon-reload
# systemctl start prometheus
# systemctl enable prometheus

Output :

[root@otodiginet prometheus-2.24.1.linux-amd64]# vi /etc/systemd/system/prometheus.service
[root@otodiginet prometheus-2.24.1.linux-amd64]# systemctl daemon-reload
[root@otodiginet prometheus-2.24.1.linux-amd64]# systemctl start prometheus
[root@otodiginet prometheus-2.24.1.linux-amd64]# systemctl enable prometheus
Created symlink /etc/systemd/system/multi-user.target.wants/prometheus.service → /etc/systemd/system/prometheus.service.

Then we will check if Prometheus service is already running by submit following command line :’

# systemctl status prometheus

Output :

[root@otodiginet prometheus-2.24.1.linux-amd64]# systemctl status prometheus
● prometheus.service - Prometheus Time Series Collection and Processing Server
Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2021-02-13 08:51:27 PST; 17s ago
Main PID: 4325 (prometheus)
Tasks: 9 (limit: 49605)
Memory: 27.9M
CGroup: /system.slice/prometheus.service
└─4325 /usr/local/bin/prometheus --config.file /etc/prometheus/prometheus.yml --storage.tsdb.path /var/lib/prometheus/ --we>

Feb 13 08:51:27 otodiginet prometheus[4325]: level=info ts=2021-02-13T16:51:27.933Z caller=head.go:645 component=tsdb msg="Replaying o>
Feb 13 08:51:27 otodiginet prometheus[4325]: level=info ts=2021-02-13T16:51:27.933Z caller=head.go:659 component=tsdb msg="On-disk mem>
Feb 13 08:51:27 otodiginet prometheus[4325]: level=info ts=2021-02-13T16:51:27.933Z caller=head.go:665 component=tsdb msg="Replaying W>
Feb 13 08:51:27 otodiginet prometheus[4325]: level=info ts=2021-02-13T16:51:27.982Z caller=head.go:717 component=tsdb msg="WAL segment>
Feb 13 08:51:27 otodiginet prometheus[4325]: level=info ts=2021-02-13T16:51:27.982Z caller=head.go:722 component=tsdb msg="WAL replay >
Feb 13 08:51:27 otodiginet prometheus[4325]: level=info ts=2021-02-13T16:51:27.983Z caller=main.go:758 fs_type=XFS_SUPER_MAGIC
Feb 13 08:51:27 otodiginet prometheus[4325]: level=info ts=2021-02-13T16:51:27.983Z caller=main.go:761 msg="TSDB started"
Feb 13 08:51:27 otodiginet prometheus[4325]: level=info ts=2021-02-13T16:51:27.983Z caller=main.go:887 msg="Loading configuration file>
Feb 13 08:51:27 otodiginet prometheus[4325]: level=info ts=2021-02-13T16:51:27.984Z caller=main.go:918 msg="Completed loading of confi>
Feb 13 08:51:27 otodiginet prometheus[4325]: level=info ts=2021-02-13T16:51:27.984Z caller=main.go:710 msg="Server is ready to receive>

8. Accessing Prometheus from Web Interface

On this stage we have already install and configure Prometheus monitoring system properly, then the next step is accessing Prometheus service. The Prometheus service can be accessed by its web portal on http://<ip_address_or_serveranme>:9090. On this tutorial, Prometheus will be binding on port 9090.

Prometheuson web

Prometheus on CentOS 8
Prometheus version 2.24.1

How to install Prometheus on CentOS 8

Conclusion

On this article, we have already learnt how to install and configure Prometheus monitoring tools on CentOS 8 server operating system. I hope this article can be helpful.

(Visited 375 times, 1 visits today)

You may also like