How to install Prometheus on CentOS 8

How To install Prometheus on Centos 8

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 Prometheus on CentOS 8 operating system.

Prometheus’s Main Features

  • As state on Prometheus official web site, the Prometheus’s main features are:
  • a multi-dimensional data model with time series data identified by metric name and key/value pairs
  • PromQL, a flexible query language to leverage this dimensionality
  • no reliance on distributed storage; single server nodes are autonomous
  • time series collection happens via a pull model over HTTP
  • pushing time series is supported via an intermediary gateway
  • targets are discovered via service discovery or static configuration
  • multiple modes of graphing and dashboarding support

Prometheus Installation On CentOS 8

After knowing a little about Prometheus, in this section, we will discuss how to install Promeutheus on a CentOS 8 operating system. There installation will be consiste of several steps, as summarize below :

  1. Prerequisites
  2. Create prometheus user on CentOS 8 system
  3. Download and Extract Prometheus Binary Files
  4. Create Prometheus Configuration File & Setting Prometheus systemd Service unit File
  5. Running Prometheus
  6. Accessing Prometheus from Web Interface

Prerequisites

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

Create promeutheus use account

The Prometheus application will be using a special user account to run called as prometheus, so we will create u group and a user with this user.

[root@otodiginet ~]# useradd -m -s /bin/false prometheus
[root@otodiginet ~]# id prometheus
 uid=1002(prometheus) gid=1002(prometheus) groups=1002(prometheus)
install prometheus | Add prometheus user
Add prometheus user

Download and Extract Prometheus Binary Files

To install the Prometheus, we have to prepare a new directory for its package and configuration file. Then we will download the latest stable of Prometheus package then extract to a new created directory.

[root@otodiginet ~]# mkdir /etc/prometheus
[root@otodiginet ~]# mkdir /var/lib/prometheus
[root@otodiginet ~]# chown prometheus /var/lib/prometheus/
Crate new directory for Prometheus
Crate new directory for Prometheus

We download the Prometheus package from official Prometheus’s github site. The package is downloaded to /tmp directory for a time being, until extraction is done.

[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]
Downloading Prometheus package
Downloading Prometheus package

Then we extract its package by submitting command line as shown below :

[root@otodiginet ~]# cd /tmp
[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

We verify the Prometheus extraction result by using tree command line, 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
Prometheus tree
Prometheus tree

There will be prometheus, promtool and prometheus.yml files, which are the core of Prometheus packages. We will move or copy these file to CentOS 8 binary files are located. We have to move down on directory to /tmp/prometheus-2.24.1.linux-amd64 directory, as shown below :

[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
[root@otodiginet prometheus-2.24.1.linux-amd64]# mv prometheus.yml /etc/prometheus/

Create Prometheus Configuration File & Setting Prometheus systemd Service unit File

The Prometheus configuration file is called as prometheus.yml. By default, the sample Prometheus configuration file has been prepared and available on the extracted archive folder, just copy or move it to Prometheus configuration directory (/etc/prometheus). The prometheus content is as shown below :

[root@otodiginet prometheus-2.24.1.linux-amd64]# vi /etc/prometheus/prometheus.yml 

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'] 
Prometheus Configuration file
Prometheus Configuration file

By default, at the configuration file there is only a single job, called prometheus , which scrapes the time series data exposed by the Prometheus server. The job contains a single, statically configured, target, the localhost on port 9090. We can edit the file to the requirement parameters that suitable with our needs.

The next step is to set up the Prometheus systemd Service unit file, this step is done by creating a file called as /etc/systemd/system/prometheus.service and reload the CentOS 8 services.

[root@otodiginet prometheus-2.24.1.linux-amd64]# 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
Prometheus systemd file
Prometheus systemd file

Running Prometheus

After file was created, the we reload the services and startup the 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.
Reload services
Reload services

Then we verify Prometheus service by querying its status by submitting command line below :

[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>
Prometheus service is running
Prometheus service is running

Accessing Prometheus

After all process are done, we now can access the Prometheus service by accessing it via web interface. As configure before, the Prometheus service is binding on port 9090.

http://ip_address_server_alias:9090

Prometheus web interface
Prometheus Runtime information
Prometheus Runtime information | Prometheus version 2.24.1
Prometheus in collecting time series data from local host

Conclusion

The Prometheus version 2.24.1 (the latest stable version) installation on CentOS 8 has been completed done. For more resource about Prometheus usage and integration with other application can be found on prometheus.io or other relevant website. Have a nice day, stay safe at home.

Share this article via :

Leave a Reply

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