How to install and configure Prometheus on Ubuntu 20.04?

Prometheus is a popular open-source monitoring and alerting system that is widely used to collect and store time-series data. It is highly customizable and provides a flexible query language to query and visualize metrics. In this blog post, we will guide you on how to install and configure Prometheus on Ubuntu 20.04.

Step 1: Update Ubuntu

Before you begin the installation process, update the Ubuntu system by running the following command

sudo apt update

sudo apt upgrade

Step 2: Download and Install Prometheus

To download and install Prometheus, follow the steps below

Visit the Prometheus download page and download the latest stable version of Prometheus.

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

Extract the downloaded tarball using the following command

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

Copy the extracted directory to /opt:

sudo cp -r prometheus-2.32.0.linux-amd64 /opt/prometheus

Step 3: Create a Prometheus User

It is recommended to create a Prometheus user to run the Prometheus service.

Create the Prometheus user using the following command

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

Change the ownership of the /opt/prometheus directory to the Prometheus user

sudo chown -R prometheus:prometheus /opt/prometheus

Step 4: Configure Prometheus

Create the prometheus.yml file in the /opt/prometheus directory

sudo nano /opt/prometheus/prometheus.yml

Paste the following configuration in the file

global:

  scrape_interval: 15s

scrape_configs:

  - job_name: 'prometheus'

    static_configs:

      - targets: ['localhost:9090']

Save the file and exit the editor.

Step 5: Create a Prometheus Systemd Service

Create a new service file

sudo nano /etc/systemd/system/prometheus.service

Paste the following configuration in the file

[Unit]

Description=Prometheus

Wants=network-online.target

After=network-online.target


[Service]

User=prometheus

Group=prometheus

Type=simple

ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml


[Install]

WantedBy=multi-user.target

Save the file and exit the editor.

Reload the systemd daemon

sudo systemctl daemon-reload

Start the Prometheus service

sudo systemctl start prometheus

Enable the Prometheus service to start automatically at boot

sudo systemctl enable prometheus

Step 6: Verify Prometheus

Open the Prometheus web interface by visiting http://your-server-ip:9090 in your web browser.

If the web interface loads, it means Prometheus has been successfully installed and configured.

Conclusion

In this blog post, we have shown you how to install and configure Prometheus on Ubuntu 20.04. Once Prometheus is set up, you can begin monitoring your system's metrics and create alerts and dashboards for your applications. It is a powerful tool that can help you keep your systems running smoothly and detect issues before they turn into major problems.


How to install and configure Prometheus on Ubuntu 18.04?

How to install and configure Prometheus on Ubuntu 22.04?

Comments

Popular posts from this blog

How to update build number in Azure DevOps pipeline?

How to get latest build ID from Azure DevOps pipeline?

How to install AWS System Manager (SSM) Agent on windows using PowerShell?