Step-by-Step Guide to Manually Install Prometheus on RedHat-Based Systems

Introduction:

Prometheus is a robust open-source monitoring and alerting system used to keep your systems healthy and efficient. In this step-by-step guide, we will show you how to manually install Prometheus on RedHat-based systems, such as CentOS, RedHat, or Rocky Linux 9. This guide provides detailed instructions to set up Prometheus from scratch.

Step 1: Update Your System

Before we start, it’s essential to ensure that your system is up-to-date. Open a terminal and run the following commands:

yum update -y
yum install
wget -y
reboot

Step 2: Download Prometheus

Download the latest version of Prometheus from the official GitHub repository. You can replace the URL with the latest release if needed:

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

Step 3: Create a Prometheus User

For security reasons, create a dedicated Prometheus user with no login privileges:

useradd --no-create-home --shell /bin/false prometheus

Step 4: Create Directories

Create directories for Prometheus in /etc and /var/lib. These directories will store the configuration and data:

mkdir /etc/prometheus /var/lib/prometheus

Step 5: Extract Prometheus

Navigate to the directory where you downloaded Prometheus, and extract it:

tar -xvzf prometheus-2.45.1.linux-amd64.tar.gz

Step 6: Rename Prometheus Directory

Rename the extracted directory to a simpler name for convenience:

mv prometheus-2.45.1.linux-amd64 prometheus

Step 7: Copy Binaries

Copy the Prometheus and promtool binaries to the /usr/local/bin directory:

cp prometheus/prometheus /usr/local/bin/ cp prometheus/promtool /usr/local/bin/

Step 8: Set Permissions

Set ownership of these binary files to the Prometheus user:

chown prometheus:prometheus /usr/local/bin/prometheus chown prometheus:prometheus /usr/local/bin/promtool

Step 9: Copy Web Files

Copy the console and console library files from Prometheus to /etc/prometheus:

cp -r prometheus/consoles /etc/prometheus cp -r prometheus/console_libraries /etc/prometheus

Step 10: Set Permissions for Web Files

Set ownership of these web files to the Prometheus user:

chown -R prometheus:prometheus /etc/prometheus/consoles chown -R prometheus:prometheus /etc/prometheus/console_libraries

Step 11: Configure Prometheus

Create a Prometheus configuration file at /etc/prometheus/prometheus.yml and edit it:

vi /etc/prometheus/prometheus.yml

Add the following basic configuration:

global:
  scrape_interval: 10s

scrape_configs:
  - job_name: 'prometheus_master'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']

Set ownership for the configuration file:

chown prometheus:prometheus /etc/prometheus/prometheus.yml

Step 12: Create a Systemd Service

Create a Systemd service file for Prometheus:

vi /etc/systemd/system/prometheus.service

Add the following content to the service file:

[Unit]
Description=Prometheus
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

Step 13: Reload Systemd and Start Prometheus

Reload Systemd to load the Prometheus service:

systemctl daemon-reload

Start Prometheus and enable it to run at system startup:

systemctl enable --now prometheus

Step 14: Check Prometheus Status

To verify if Prometheus is running, run the following command:

systemctl status prometheus

Step 15: Access Prometheus Web Interface

You can access the Prometheus web interface using your server’s IP address or domain name followed by port 9090 (e.g., http://your_server_ip:9090).

Conclusion:

By following these detailed steps, you have successfully installed Prometheus on your RedHat-based system, whether it’s CentOS, RedHat, or Rocky Linux 9. This installation allows you to effectively monitor your infrastructure and ensure its health and efficiency.

Similar Posts

Leave a Reply

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