Install Prometheus Server on AlmaLinux 8 From CLI

This tutorial intends to teach you to Install Prometheus Server on AlmaLinux 8 From CLI. Also, you can use any RHEL 8 distro such as Rocky Linux 8 or Centos 8. Prometheus is used to monitor microservices and containers that provide flexible queries and real-time notifications.

In this guide, you will learn to download the latest Prometheus and install it on your AlmaLinux server step by step.

Steps To Install Prometheus Server on AlmaLinux 8 From CLI

To set up the Prometheus server on AlmaLinux, you need to have access to your server as a non-root user with sudo privileges and set up a basic firewall. For this purpose, you can check the Initial Server Setup with AlmaLinux 8.

Now follow the steps below to complete your Prometheus server setup.

Step 1 – Create Prometheus System Group and User on AlmaLinux 8

First, you need to run the system update with the following command:

sudo dnf update -y

Then, you must create a system group and user for Prometheus. To do this, you can run the following commands in your Linux terminal:

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

Step 2 – Create Prometheus Data and Config Directories

At this point, you need to create a data directory for Prometheus to store its data and create a config directory for it. To do this, run the following commands:

# sudo mkdir /var/lib/prometheus
# for i in rules rules.d files_sd; do sudo mkdir -p /etc/prometheus/${i}; done

Step 3 – Download the Latest Prometheus Binary Package from GitHub

Now you need to visit the GitHub Prometheus release page and download the latest binary package under /tmp/prometheus directory with the following curl command:

# sudo mkdir -p /tmp/prometheus 
# sudo cd /tmp/prometheus
# curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi -

When your download is completed, extract it by using the command below:

sudo tar xvf prometheus*.tar.gz

Next, switch to your Prometheus directory:

cd prometheus*/

Move the binary files to /usr/local/bin/ directory:

sudo mv prometheus promtool /usr/local/bin/

Verify your Prometheus installation by checking its version on AlmaLinux 8:

prometheus --version
Output
prometheus, version 2.44.0 (branch: HEAD, revision: 1ac5131f698ebc60f13fe2727f89b115a41f6558)
  build user:       root@739e81
  build date:       20230514-06:18:11
  go version:       go1.20.4
  platform:         linux/amd64
  tags:             netgo,builtinassets,stringlabels

Step 4 – Prometheus Configuration on AlmaLinux 8

At this point, you need to move the Prometheus configuration template to the /etc directory with the following command:

sudo mv prometheus.yml /etc/prometheus/prometheus.yml

Also, move consoles and console_libraries to the /etc/prometheus directory:

sudo mv consoles/ console_libraries/ /etc/prometheus/

Then, switch back to your home directory:

cd $HOME

Step 5 – Create Prometheus Systemd Unit File

To manage the Prometheus service with systemd, you need to create a systemd unit file for Prometheus. To do this, you can use your favorite text editor, we use the vi editor:

sudo vi /etc/systemd/system/prometheus.service

Add the following content to the file:

[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

When you are done, save and close the file.

Set Correct Prometheus Directory Permissions

At this point, you need to change the ownership of these directories to Prometheus user and group by using the following commands:

# for i in rules rules.d files_sd; do sudo chown -R prometheus:prometheus /etc/prometheus/${i}; done 
# for i in rules rules.d files_sd; do sudo chmod -R 775 /etc/prometheus/${i}; done 
# sudo chown -R prometheus:prometheus /var/lib/prometheus/

How To Start Prometheus Server?

Now you can start and enable Prometheus service on AlmaLinux 8 with the following commands:

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

Verify your Prometheus service is active and running on AlmaLinux 8:

sudo systemctl status prometheus
Output
● prometheus.service - Prometheus
   Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor pres>
   Active: active (running) since Wed 2023-06-07 07:07:06 EDT; 16s ago
     Docs: https://prometheus.io/docs/introduction/overview/
 Main PID: 48384 (prometheus)
    Tasks: 7 (limit: 23668)
   Memory: 17.3M
   CGroup: /system.slice/prometheus.service
           └─48384 /usr/local/bin/prometheus --config.file=/etc/prometheus/prom>
...

Step 6 – Configure Firewall For Prometheus

At this point, you have an active firewall, you must allow Prometheus port which is 9090 through the firewall. To do this, you can run the command below:

sudo firewall-cmd --zone=public --permanent --add-port 9090/tcp

Reload the firewall to apply the new rules:

sudo firewall-cmd --reload

Step 7 – How To Access Prometheus Server?

Now you can confirm that you can connect to port 9090 by accessing the Prometheus server IP address or domain name in your web browser:

http://server-ip-or-domain-name:9090
Prometheus server almalinux 8

That’s it, you are done. With Prometheus, you can monitor application metrics like throughput (TPS) and response times. Also, you can use the Node exporter to monitor host hardware and kernel metrics.

Conclusion

Prometheus is a reliable tool for collecting and processing metrics from machines and applications. At this point, you have learned to download the latest Prometheus and install it on your AlmaLinux server step by step. You can use this instruction for any RHEL 8 distro like Rocky Linux 8.

Hope you enjoy it. Please subscribe to us on Facebook and Twitter.

Also, you may like to read the following guides:

Discuss dnf vs yum

Python execute shell command

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular