CentOSLinuxTutorials

How To Install Prometheus on CentOS 8

Install Prometheus on CentOS 8

In this tutorial, we will show you how to install Prometheus on CentOS 8. For those of you who didn’t know, Prometheus is an excellent open-source monitoring system that allows us to collect metrics from our applications and store them in a database, especially a time-series-based DB. The biggest advantage of Prometheus is the query language it provides for data processing.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of Prometheus on a CentOS 8 server.

Prerequisites

  • A server running one of the following operating systems: CentOS 8.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Prometheus on CentOS 8

Step 1. First, let’s start by ensuring your system is up-to-date.

sudo dnf clean all
sudo dnf update

Step 2. Add system user and group for Prometheus.

Run the command below to create Prometheus system user and group:

useradd -M -r -s /bin/false prometheus

Step 3. Create a data directory for Prometheus.

Create a directory that will be used to store Prometheus data:

mkdir /etc/prometheus
mkdir /var/lib/prometheus

Step 3. Installing Prometheus on CentOS 8.

We need to download the latest release of the Prometheus archive and extract it to get binary files:

wget https://github.com/prometheus/prometheus/releases/download/v2.14.0/prometheus-2.14.0.linux-amd64.tar.gz -P /tmp
cd /tmp
tar -xzf prometheus-2.14.0.linux-amd64.tar.gz

Next, copy the two Prometheus files, Prometheus and promtool, under the extracted Prometheus archive directory to the /usr/local/bin directory:

cp prometheus-2.14.0.linux-amd64/{prometheus,promtool} /usr/local/bin/
cp -r prometheus-2.14.0.linux-amd64/{consoles,console_libraries} /etc/prometheus/

Configure Prometheus:

Configurations should be added to the “/etc/prometheus/prometheus.yml”, Open the configuration file for modification and adjust it such that it looks like:

nano /etc/prometheus/prometheus.yml
# my 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 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']

Step 4. Create systemd Service unit.

You need to create a systemd service file, /etc/systemd/system/prometheus.service, configured as follows:

nano /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Time Series Collection and Processing Server
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

Reload the systemd service:

systemctl daemon-reload
systemctl enable --now prometheus
systemctl status prometheus

Step 5. Configure firewall for Prometheus.

Allow Prometheus through the firewall:

sudo firewall-cmd --add-port=9090/tcp --permanent
sudo firewall-cmd --reload

Step 6. Set Ownership on Configuration Files and Directories.

Run the command below to set the ownership of Prometheus configuration files and directories to Prometheus:

chown -R prometheus:prometheus /etc/prometheus
chown -R prometheus:prometheus /var/lib/prometheus
chown prometheus.prometheus /usr/local/bin/{prometheus,promtool}

Step 7. Accessing Prometheus.

Prometheus will be available on HTTP port 9090 by default. Open your favorite browser and navigate to http://your-domain.com:9090 or http://server-ip-address:9090 and complete the required steps to finish the installation.

Install Prometheus on CentOS 8

Congratulations! You have successfully installed Prometheus. Thanks for using this tutorial for installing Prometheus on CentOS 8 system. For additional help or useful information, we recommend you check the official Prometheus website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button