Hero Image

Install Prometheus on RHEL 9

Install Prometheus on RHEL 9

Step 1 – Install Prometheus

dnf install -y prometheus node_exporter 2>/dev/null || \
# Download from https://github.com/prometheus/prometheus/releases
VERSION=2.51.2
wget https://github.com/prometheus/prometheus/releases/download/v${VERSION}/prometheus-${VERSION}.linux-amd64.tar.gz
tar xvf prometheus-${VERSION}.linux-amd64.tar.gz
cp prometheus-${VERSION}.linux-amd64/prometheus /usr/local/bin/
cp prometheus-${VERSION}.linux-amd64/promtool  /usr/local/bin/

Step 2 – Create user and directories

useradd -r -s /sbin/nologin prometheus 2>/dev/null || useradd -r -s /usr/sbin/nologin prometheus
mkdir -p /etc/prometheus /var/lib/prometheus
chown prometheus:prometheus /etc/prometheus /var/lib/prometheus

Step 3 – Basic /etc/prometheus/prometheus.yml

global:
  scrape_interval: 15s
  evaluation_interval: 15s

alerting:
  alertmanagers:
    - static_configs:
        - targets: []

rule_files: []

scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]

  - job_name: "node"
    static_configs:
      - targets:
          - "localhost:9100"
          - "192.168.1.11:9100"
          - "192.168.1.12:9100"

  - job_name: "nginx"
    static_configs:
      - targets: ["localhost:9113"]

  - job_name: "mysql"
    static_configs:
      - targets: ["localhost:9104"]

Step 4 – systemd unit (/etc/systemd/system/prometheus.service)

[Unit]
Description=Prometheus
After=network.target

[Service]
User=prometheus
Group=prometheus
ExecStart=/usr/local/bin/prometheus \
    --config.file=/etc/prometheus/prometheus.yml \
    --storage.tsdb.path=/var/lib/prometheus \
    --storage.tsdb.retention.time=30d \
    --web.listen-address=:9090
Restart=on-failure

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable --now prometheus

Step 5 – Verify

curl http://localhost:9090/-/healthy

Access the web UI at http://your-server:9090.