Easily install Prometheus software on Rocky Linux 9 with our step-by-step guide. Optimize your monitoring capabilities and ensure seamless performance tracking for your system today! #centlinux #linux #prometheus
Table of Contents
What is Prometheus Software?
Prometheus is an open-source software project, a monitoring and alerting toolkit originally developed by SoundCloud in 2012 and later donated to the Cloud Native Computing Foundation (CNCF) in 2016.
Prometheus is designed to monitor the health and performance of computer systems and applications. It follows a time-series data model, where metrics (such as CPU usage, memory consumption, network traffic, etc.) are collected and stored over time. These metrics can then be analyzed, graphed, and used for alerting purposes.
Key features of Prometheus include:
- Metrics Collection: Prometheus provides various libraries and integrations that allow developers to instrument their applications and collect metrics. It supports multiple data formats, including a specialized query language called PromQL.
- Data Storage: Prometheus uses its custom time-series database for efficient storage and retrieval of metrics. The collected data is stored locally, making it easy to scale and operate.
- Alerting: Prometheus supports rule-based alerting, allowing users to define alert conditions based on metric thresholds or complex expressions. When an alert is triggered, notifications can be sent through various channels, such as email, PagerDuty, or webhooks.
- Visualization: Prometheus has a built-in graphical interface called the Prometheus Expression Browser, which allows users to explore and graph metrics in real-time. Additionally, it can be integrated with visualization tools like Grafana for more advanced data visualization.
Prometheus has gained popularity in the realm of cloud-native applications and is often used in conjunction with other technologies like Kubernetes for monitoring and observability purposes. Its flexibility, scalability, and active community support have made it a widely adopted monitoring solution in the software development community.
Environment Specification:
We are using a minimal Rocky Linux 9 virtual machine with following specifications.
- CPU – 3.4 Ghz (2 cores)
- Memory – 4 GB
- Storage – 40 GB
- Operating System – Rocky Linux release 9.2 (Blue Onyx)
- Hostname – prometheus-01.centlinux.com
- IP Address – 192.168.116.133/24
Read Also: How to install Prometheus on CentOS 8
Prepare your Rocky Linux Server:
Login as root user on your Rocky Linux server with the help of a SSH client.
Set a Fully Qualified Domain Name (FQDN) and configure Local DNS resolution for your Linux machine.
# hostnamectl set-hostname prometheus-01.centlinux.com
# echo "192.168.116.133 prometheus-01 prometheus-01.centlinux.com" >> /etc/hosts
To confirm your Local DNS settings, execute ping command on Linux terminal.
# ping prometheus-01 PING prometheus-01 (192.168.116.133) 56(84) bytes of data. 64 bytes from prometheus-01 (192.168.116.133): icmp_seq=1 ttl=64 time=0.128 ms 64 bytes from prometheus-01 (192.168.116.133): icmp_seq=2 ttl=64 time=0.143 ms ^C --- prometheus-01 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1051ms rtt min/avg/max/mdev = 0.128/0.135/0.143/0.007 ms
Update software packages in your Linux OS by executing following command at Linux terminal.
# dnf update -y
Sometimes, the above dnf command updates software packages related to Linux Kernel. If this happens then you should reboot your Linux OS before installing Prometheus software.
# reboot
Note down the Linux OS and Kernel versions, that are being used in this tutorial.
# cat /etc/rocky-release Rocky Linux release 9.2 (Blue Onyx) # uname -r 5.14.0-284.11.1.el9_2.x86_64
Install required software packages as follows.
# dnf install -y wget tar grubby
Disable SELinux:
Prometheus software does not have an official SELinux policy. Therefore, you have to permanently disable SELinux for proper functioning of your network monitoring tool.
In most Linux distributions, SELinux by default runs in Enforcing mode.
You can verify this with the help of getenforce command.
# getenforce Enforcing
Execute following command to permanently disable SELinux.
# grubby --update-kernel ALL --args selinux=0
Reboot your machine now.
# reboot
Again, check the status of SELinux by using getenforce command.
# getenforce Disabled
SELinux has been permanently disabled.
Create Linux Users & Directories:
Create a Linux user to own Prometheus software and processes.
# useradd --no-create-home -s /bin/false prometheus
Create required Prometheus directories and change the ownership.
# mkdir /etc/prometheus # mkdir /var/lib/prometheus # chown prometheus:prometheus /etc/prometheus # chown prometheus:prometheus /var/lib/prometheus
Installing Prometheus Software on Rocky Linux 9:
You can install Prometheus software on Linux by downloading the setup from their official website.
Copy the URL of your required version of Network monitoring software and then use wget command to download Prometheus tarball.
# wget https://github.com/prometheus/prometheus/releases/download/v2.44.0/prometheus-2.44.0.linux-amd64.tar.gz ... Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.108.133, 185.199.111.133, 185.199.110.133, ... Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.108.133|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 90577277 (86M) [application/octet-stream] Saving to: ‘prometheus-2.44.0.linux-amd64.tar.gz’ prometheus-2.44.0.l 100%[===================>] 86.38M 834KB/s in 76s 2023-05-21 22:14:38 (1.13 MB/s) - ‘prometheus-2.44.0.linux-amd64.tar.gz’ saved [90577277/90577277]
After download, extract the tarball by using tar command.
# tar xf prometheus-2.44.0.linux-amd64.tar.gz -C /var/lib/prometheus/ --strip-components=1
Adjust the ownership of Prometheus installation directory.
# chown -R prometheus:prometheus /var/lib/prometheus
Move Prometheus default configuration file to /etc/prometheus directory.
# mv /var/lib/prometheus/prometheus.yml /etc/prometheus/
Edit prometheus.yml in vim text editor.
# vi /etc/prometheus/prometheus.yml
Find following directives therein.
static_configs: - targets: ["localhost:9090"]
And change it as follows.
static_configs: - targets: ["192.168.116.133:9090"]
Create symbolic links for Prometheus commands at /usr/bin directory, to make them globally executable from any path.
# ln -s /var/lib/prometheus/prometheus /usr/bin # ln -s /var/lib/prometheus/promtool /usr/bin
To enable auto-start of Prometheus server, you are required to create a systemd service unit.
Create a systemd unit file by using vim text editor.
# vi /usr/lib/systemd/system/prometheus.service
Add following directives in this file.
[Unit] Description=Prometheus Wants=network-online.target After=network-online.target [Service] User=prometheus Group=prometheus Type=simple ExecStart=/usr/bin/prometheus --config.file /etc/prometheus/prometheus.yml --storage.tsdb.path /var/lib/prometheus/ --web.console.templates=/var/lib/prometheus/consoles --web.console.libraries=/var/lib/prometheus/console_libraries [Install] WantedBy=multi-user.target
Enable and start Prometheus service.
# systemctl enable --now prometheus.service Created symlink /etc/systemd/system/multi-user.target.wants/prometheus.service → /usr/lib/systemd/system/prometheus.service.
Verify the status of Prometheus service for any errors.
# systemctl status prometheus.service
● prometheus.service - Prometheus
Loaded: loaded (/usr/lib/systemd/system/prometheus.service; enabled; prese>
Active: active (running) since Sun 2023-05-21 22:22:35 PKT; 56s ago
Main PID: 1692 (prometheus)
Tasks: 8 (limit: 23011)
Memory: 26.0M
CPU: 515ms
CGroup: /system.slice/prometheus.service
└─1692 /usr/bin/prometheus --config.file /etc/prometheus/prometheu>
May 21 22:22:35 prometheus-01.centlinux.com prometheus[1692]: ts=2023-05-21T17:>
May 21 22:22:35 prometheus-01.centlinux.com prometheus[1692]: ts=2023-05-21T17:>
May 21 22:22:35 prometheus-01.centlinux.com prometheus[1692]: ts=2023-05-21T17:>
Prometheus network monitoring server uses default port 9090/tcp. Therefore, it is necessary to allow it in Linux firewall, to make your service accessible across the network.
# firewall-cmd --permanent --add-port=9090/tcp success # firewall-cmd --reload success
Open URL http://prometheus-01.centlinux.com:9090 in your favorite web browser.
Open Status > Targets from top menu.
Prometheus has been installed on your Rocky Linux server.
Install Node Exporter on Rocky Linux 9:
Node Exporter is a Prometheus exporter for server level and OS level metrics with configurable metric collectors. It helps us in measuring various server resources such as RAM, disk space, and CPU utilization.
After you install Prometheus software on Linux, You should also install node_exporter on your Prometheus server to gather metrics.
Create a directory for Node Exporter software.
# mkdir -p /var/lib/prometheus/node_exporter
You can also copy the URL of Node Exporter from Prometheus official download page.
Use wget command with copied URL to download Node Exporter.
# wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz ... Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.111.133, 185.199.109.133, 185.199.108.133, ... Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.111.133|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 10181045 (9.7M) [application/octet-stream] Saving to: ‘node_exporter-1.5.0.linux-amd64.tar.gz’ node_exporter-1.5.0 100%[===================>] 9.71M 1.12MB/s in 8.7s 2023-05-21 22:33:56 (1.11 MB/s) - ‘node_exporter-1.5.0.linux-amd64.tar.gz’ saved [10181045/10181045]
Extract downloaded tarball by using tar command.
# tar xf node_exporter-1.5.0.linux-amd64.tar.gz -C /var/lib/prometheus/node_exporter/ --strip-components=1
Adjust the ownership of node_exporter directory.
# chown -R prometheus:prometheus /var/lib/prometheus/node_exporter/
Create a symbolic link for node_exporter at /usr/bin directory.
# ln -s /var/lib/prometheus/node_exporter/node_exporter /usr/bin/
Enable auto-start of node_exporter process, create a systemd service unit.
# vi /usr/lib/systemd/system/node_exporter.service
Add following lines of code in this file.
[Unit] Description=Node Exporter Wants=network-online.target After=network-online.target [Service] User=prometheus ExecStart=/usr/bin/node_exporter [Install] WantedBy=default.target
Enable and start node_exporter service.
# systemctl enable --now node_exporter.service Created symlink /etc/systemd/system/default.target.wants/node_exporter.service → /usr/lib/systemd/system/node_exporter.service.
Configure Linux firewall to allow node_exporter default port 9100/tcp.
# firewall-cmd --permanent --add-port=9100/tcp success # firewall-cmd --reload success
Edit Prometheus configuration file in vim text editor.
# vi /etc/prometheus/prometheus.yml
Add the node_exporter endpoint configuration in this file. As you see, it is a .yml file, so you should be very careful with the spaces and indention while editing this file.
- job_name: 'node_exporter' static_configs: - targets: ['localhost:9100']
Restart Prometheus service to load new configurations.
# systemctl restart prometheus.service
Open Status > Targets or refresh the web page, if already opened.
Final Thoughts
As you embark on the journey to install Prometheus software on Rocky Linux 9, empower your monitoring capabilities and ensure the seamless performance of your system. With our comprehensive guide, navigating the installation process becomes effortless, allowing you to leverage Prometheus to its fullest potential. Let’s elevate your monitoring infrastructure together and unlock new insights into your system’s health and performance. To start building an amazing Network Monitoring System for your Data Center, we suggest that you should attend online training Prometheus Alerting and Monitoring