HomeHOWTOSInstall Prometheus on Rocky Linux 9|AlmaLinux 9

Install Prometheus on Rocky Linux 9|AlmaLinux 9

Welcome to our today’s guide on how to Install Prometheus on Rocky Linux 9|AlmaLinux 9. Prometheus is an open-source time series collection and monitoring system with a dimensional data model, a flexible query language, an efficient time series database, and a modern alerting approach.

SoundCloud initially developed Prometheus in 2012. Since then, the Prometheus project, which was embraced by a number of well-known businesses, has grown and attracted a large developer and community. And the Cloud Native Computing Foundation graduated with the Prometheus project in 2016. (CNCF).

Install Prometheus on Rocky Linux 9|AlmaLinux 9

Follow the instructions below to install Prometheus on your Rocky Linux 9|AlmaLinux 9.

Step 1~ Create Prometheus System User & Group

To create a user and group for the Prometheus system, use the command below.

sudo useradd -M -r -s /bin/false prometheus

Step 2~ Create Prometheus Directories

You must make the necessary configuration directories because we are installing Prometheus from the source.

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

Step 3~ Download Prometheus

Go to the Download Page and download the appropriate Prometheus binary for your platform to install the most recent version of Prometheus, in this guide we use 2.37.6.

To download the most recent version for Linux systems as of this writing, you can just use the command below.

wget https://github.com/prometheus/prometheus/releases/download/v2.37.6/prometheus-2.37.6.linux-amd64.tar.gz

Extract the archive after the download is complete.

$ tar -xzf prometheus-2.37.6.linux-amd64.tar.gz

$ ls prometheus-2.37.6.linux-amd64
console_libraries  consoles  LICENSE  NOTICE  prometheus  prometheus.yml  promtool  tsdb

Transfer the prometheus and promtool binary files from the Prometheus archive directory that have been extracted to the /usr/local/bin/ directory.

sudo cp prometheus-2.37.6.linux-amd64/{prometheus,promtool} /usr/local/bin/

Then copy the consoles/ and console libraries/ directories to the /etc/prometheus directory generated above.

sudo cp -r prometheus-2.37.6.linux-amd64/{consoles,console_libraries} /etc/prometheus/

Step 4~ Create a configuration file

The extracted archive directory contains the prometheus.yml sample Prometheus configuration file.

We will duplicate the configuration file and make the following changes to it so that it can only scrape the local system (Prometheus server).

sudo cp prometheus-2.37.6.linux-amd64/prometheus.yml /etc/prometheus/

Next, open the configuration file and make the necessary changes to make it appear as follows:

sudo vim /etc/prometheus/prometheus.yml

Output:

# 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"]   

Provide Prometheus access to the firewall.

sudo firewall-cmd --add-port=9090/tcp --permanent
sudo firewall-cmd --reload

Use the command below to give Prometheus’ configuration files and directories the Prometheus ownership (owner and group).

sudo chown -R prometheus:prometheus /etc/prometheus
sudo chown -R prometheus:prometheus /var/lib/prometheus
sudo chown prometheus:prometheus /usr/local/bin/{prometheus,promtool}

Start Prometheus using our default configuration file by executing the command below:

$ prometheus --config.file=/etc/prometheus/prometheus.yml
..........
wal_replay_duration=18.337778ms total_replay_duration=18.604276ms
ts=2023-02-24T15:06:17.467Z caller=main.go:993 level=info fs_type=XFS_SUPER_MAGIC
ts=2023-02-24T15:06:17.467Z caller=main.go:996 level=info msg="TSDB started"
ts=2023-02-24T15:06:17.467Z caller=main.go:1177 level=info msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
ts=2023-02-24T15:06:17.501Z caller=main.go:1214 level=info msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml totalDuration=33.891686ms db_storage=126.505µs remote_storage=2.643µs web_handler=703ns query_engine=1.232µs scrape=33.116413ms scrape_sd=64.606µs notify=73.695µs notify_sd=30.844µs rules=2.288µs tracing=9.575µs
ts=2023-02-24T15:06:17.501Z caller=main.go:957 level=info msg="Server is ready to receive web requests."

Step 6~ Create a file for the Prometheus Systemd Service.

You must make a systemd service file named /etc/systemd/system/prometheus.service with the following configuration in order to start Prometheus as a service.

It should be noted that this assumes the Prometheus server is listening on the default port 9090.

$ sudo tee /etc/systemd/system/prometheus.service<<EOF
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
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
EOF

Reload the configuration of the systemd daemon.

sudo systemctl daemon-reload

Start and enable the Prometheus service to run at startup.

sudo systemctl enable --now prometheus

Verify its status;

$ systemctl status prometheus
 prometheus.service - Prometheus
     Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor p>
     Active: active (running) since Fri 2023-02-24 19:06:52 EAT; 34s ago
       Docs: https://prometheus.io/docs/introduction/overview/
   Main PID: 3138 (prometheus)
      Tasks: 8 (limit: 23004)
     Memory: 75.2M
        CPU: 370ms
     CGroup: /system.slice/prometheus.service
             └─3138 /usr/local/bin/prometheus --config.file=/etc/prometheus/pr>

Feb 24 19:06:57 localhost.localdomain prometheus[3138]: ts=2023-02-24T16:06:57>
Feb 24 19:06:57 localhost.localdomain prometheus[3138]: ts=2023-02-24T16:06:57>
Feb 24 19:06:57 localhost.localdomain prometheus[3138]: ts=2023-02-24T16:06:57>

Step 6~ Using the Prometheus Web Interface

If you are contacting the server locally, you should be able to access the Prometheus status page at http://localhost:9090 or http://server-IP>:9090 if you are accessing remotely.

Install Prometheus on Rocky Linux 9|AlmaLinux 9

Conclusion

So far, you’ve discovered how to install and configure Prometheus on Rocky Linux 9|AlmaLinux 9. Please feel free to learn more about Prometheus here.

Other tutorials:

- Advertisment -

Recent posts

LEAVE A REPLY

Please enter your comment!
Please enter your name here