Installing Prometheus Server with custom Configuration on Ubuntu 22.04

Prerequisites

  • Root user account with sudo privileges
  • Prometheus system user and group
  • Sufficient Storage on the system and a good internet connectivity
  • port 9090 for Prometheus, port 3000 for Grafana, and optionally port 9100 for node exporter (If needed / wanted)

Step 1: Creating Prometheus system user and directory

Create a system user for Prometheus

sudo useradd –system -M -s /bin/false prometheus

Create a directory in which we will be storing our configuration files and libraries:

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

Set ownership of /var/lib/prometheus directory

sudo chown prometheus:prometheus /var/lib/prometheus

Step 2: Download the Prometheus Binary File

Change directory to /tmp

cd /tmp

Download the Prometheus setup using wget

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

Extract the files

tar -xvf prometheus-2.46.0.linux-amd64.tar.gz
ls /tmp

cd prometheus-2.46.0.linux-amd64

Move the configuration file and change the owner to the prometheus user

sudo mv console* /etc/prometheus
sudo mv prometheus.yml /etc/prometheus
sudo chown -R prometheus:prometheus /etc/prometheus

Move the binaries and set the owner to prometheus user

sudo mv prometheus /usr/local/bin
sudo chown prometheus:prometheus /usr/local/bin/prometheus

Step3: Prometheus configuration file

Use editing tools of your preference, we will be using vi.

Verify if the file exist on the /etc/prometheus directory, and modify the prometheus.yml file as per your requirement.

sudo vi /etc/prometheus/prometheus.yml

Step4: Creating Prometheus Systemd file

Create the service file

sudo vi /etc/systemd/system/prometheus.yml

Input the configuration below to the prometheus.yml 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

Reload Systemd

sudo systemctl daemon-reload

Start and Enable Prometheus service

sudo systemctl start prometheus.service
sudo systemctl enable prometheus.service
sudo systemctl status prometheus.service

Verify Prometheus Installation

Open your web browser and access http://<your machine IP>:9090. If Prometheus is running correctly, you will see Prometheus Web Interface.

Leave a Reply

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