Welcome to our guide on How to Install Prometheus on CentOS 8 / RHEL 8. Prometheus is an open-source time series monitoring and alerting toolkit originally developed at SoundCloud. It has very active development and community and has seen wide adoption by many organizations and companies.
Prometheus is the defacto monitoring tool for Cloud native applications and microservices. You can’t talk Docker and Kubernetes infrastructure monitoring without mentioning Prometheus. To achieve complete monitoring, alerting and visualization, Grafana usually comes into the mix.
Below are the steps to install Prometheus monitoring tool on RHEL 8.
Step 1: Add system user and group for prometheus
Let’s kick off the installation of Prometheus on RHEL 8 by creating a dedicated user that will run and manage Prometheus service. This is a system user that doesn’t have access to console/shell login.
sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
Note that this user doesn’t have /bin/bash shell, that’s why we used -s /sbin/nologin.
Step 2: Set NTP Server
To avoid any time drift, configure NTP server on Prometheus server to provide accurate time.
Step 3: Create data directory for Prometheus
Once the system user and group has been created, proceed to create a directory that will be used to store Prometheus data. This includes the metrics collected from the agents being monitored.
sudo mkdir /var/lib/prometheus
You can choose to use a different path, e.g separate partition.
Step 4: Create configuration directories for Prometheus
Prometheus primary configuration files directory is /etc/prometheus/. It will have some sub-directories.
for i in rules rules.d files_sd; do
sudo mkdir -p /etc/prometheus/${i};
done
Step 5: Download Prometheus on CentOS 8 / RHEL 8
We need to download the latest release of Prometheus archive and extract it to get binary files. You can check releases from Prometheus releases Github page.
You can use curl or wget to download from the command line.
curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest \
| grep browser_download_url \
| grep linux-amd64 \
| cut -d '"' -f 4 \
| wget -qi -
Extract the file and move it to directory in your $PATH
tar xvf prometheus-*.tar.gz
cd prometheus-*/
sudo cp prometheus promtool /usr/local/bin/
Also copy consoles and console_libraries to /etc/prometheus directory:
sudo cp -r prometheus.yml consoles/ console_libraries/ /etc/prometheus/
Step 6: Create a Prometheus configuration file.
Prometheus configuration file will be located under /etc/prometheus/prometheus.yml. Create simple configurations using content:
# 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: 15s # scrape_timeout is set to the global default (10s).
# 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']
Make changes to the file to fit your initial setting and save the file.
Step 7: Create systemd Service unit
To be able to manage Prometheus service with systemd, you need to explicitly define this unit file.
Create a file
sudo vi /etc/systemd/system/prometheus.service
Add the following contents to it.
[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
Set correct directory permissions.
sudo chown -R prometheus:prometheus /etc/prometheus
sudo chmod -R 775 /etc/prometheus/
sudo chown -R prometheus:prometheus /var/lib/prometheus/
Start Prometheus service.
sudo systemctl daemon-reload
sudo systemctl start prometheus
Enable the service to start at system boot:
sudo systemctl enable prometheus
Check status using systemctl status prometheus command:
$ systemctl status prometheus
● prometheus.service - Prometheus
Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2023-08-16 10:28:19 UTC; 9s ago
Docs: https://prometheus.io/docs/introduction/overview/
Main PID: 2010 (prometheus)
Tasks: 6 (limit: 10843)
Memory: 19.6M
CGroup: /system.slice/prometheus.service
└─2010 /usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus --web.console.templates=/etc/prometheus/consoles --web.console.libra>
Aug 16 10:28:19 cent8.mylab.io prometheus[2010]: ts=2023-08-16T10:28:19.160Z caller=tls_config.go:274 level=info component=web msg="Listening on" address=[::]:9090
Aug 16 10:28:19 cent8.mylab.io prometheus[2010]: ts=2023-08-16T10:28:19.160Z caller=tls_config.go:277 level=info component=web msg="TLS is disabled." http2=false address=[::]:9090
Aug 16 10:28:19 cent8.mylab.io prometheus[2010]: ts=2023-08-16T10:28:19.160Z caller=head.go:755 level=info component=tsdb msg="WAL segment loaded" segment=0 maxSegment=0
Aug 16 10:28:19 cent8.mylab.io prometheus[2010]: ts=2023-08-16T10:28:19.161Z caller=head.go:792 level=info component=tsdb msg="WAL replay completed" checkpoint_replay_duration=59.227µs wal_replay_d>
Aug 16 10:28:19 cent8.mylab.io prometheus[2010]: ts=2023-08-16T10:28:19.162Z caller=main.go:1047 level=info fs_type=EXT4_SUPER_MAGIC
Aug 16 10:28:19 cent8.mylab.io prometheus[2010]: ts=2023-08-16T10:28:19.162Z caller=main.go:1050 level=info msg="TSDB started"
Aug 16 10:28:19 cent8.mylab.io prometheus[2010]: ts=2023-08-16T10:28:19.162Z caller=main.go:1231 level=info msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
Aug 16 10:28:19 cent8.mylab.io prometheus[2010]: ts=2023-08-16T10:28:19.164Z caller=main.go:1268 level=info msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml tot>
Aug 16 10:28:19 cent8.mylab.io prometheus[2010]: ts=2023-08-16T10:28:19.164Z caller=main.go:1011 level=info msg="Server is ready to receive web requests."
Aug 16 10:28:19 cent8.mylab.io prometheus[2010]: ts=2023-08-16T10:28:19.164Z caller=manager.go:1009 level=info component="rule manager" msg="Starting rule manager..."
Step 8: Configure firewalld
I’ll allow access to Prometheus management interface port 9090
from my trusted network using Firewalld rich rules.
sudo firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" \
source address="192.168.122.0/24" \
port protocol="tcp" port="9090" accept'
sudo firewall-cmd --reload
If you want to allow from any IP, use:
sudo firewall-cmd --add-port=9090/tcp --permanent
sudo firewall-cmd --reload
Open Prometheus Server IP/Hostname and port 9090
Step 9: Secure Web console with Password
We have a guide dedicated to using basic http authentication to access Prometheus Metrics. Use below link to access it.
You now have Prometheus Server installed on CentOS 8 / RHEL 8 Linux system. Also check our Prometheus monitoring guides below.
- Monitoring Ceph Cluster with Prometheus and Grafana
- Monitoring Ceph Cluster with Prometheus and Grafana
- How to Monitor Linux Server Performance with Prometheus and Grafana in 5 minutes
- How to Monitor BIND DNS server with Prometheus and Grafana
- How to Monitor Redis Server with Prometheus and Grafana in 5 minutes
- Monitoring MySQL / MariaDB with Prometheus in five minutes
- How to Monitor Apache Web Server with Prometheus and Grafana in 5 minutes