This tutorial will demonstrate installing Prometheus on Debian 12|Debian11. Prometheus is a free and open-source monitoring system for collecting time-series data metrics from any target system.
Its web interface allows you to run powerful queries, visualize collected data and set up alerts.
Table of Contents
Step 1: Prepare your System
Follow the below steps to install Prometheus on Debian 12|Debian 11 on a Linux machine.
Make sure your system is up to date by running the following apt commands in the terminal before we begin installing any software:
sudo apt update -y
sudo apt upgrade -y
Step 2: Create Prometheus system User/Group
A special group and user will be created for the Prometheus system. This is accomplished by using the -r or -system option.
sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
As a result, we used the option -s /sbin/nologin to create a system user that doesn’t require the /bin/bash shell.
Prometheus requires directories to store data and configuration files. Use the instructions below to create each and every necessary directory.
sudo mkdir /var/lib/prometheus
for i in rules rules.d files_sd; do sudo mkdir -p /etc/prometheus/${i}; done
Step 3: Install Prometheus on Debian 12|Debian11
The Prometheus packages installer is now downloaded from the official website; Prometheus releases Github:
mkdir -p /tmp/prometheus && cd /tmp/prometheus
curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest|grep browser_download_url|grep linux-amd64|cut -d '"' -f 4|wget -qi -
Then, extract the Prometheus packages file as follows:
tar xvf prometheus*.tar.gz
cd prometheus*/
We will relocate the files to the correct directory after file extraction:
sudo mv prometheus promtool /usr/local/bin/
sudo mv prometheus.yml /etc/prometheus/prometheus.yml
Consoles and console libraries should also be moved to the /etc/prometheus directory:
sudo mv consoles/ console_libraries/ /etc/prometheus/
cd ~/
rm -rf /tmp/prometheus
Step 4: Create the Prometheus Configuration File
The Prometheus.yml configuration file can be found in the /etc/prometheus directory.
cat /etc/prometheus/prometheus.yml
Output:
# 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).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# 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 5: Creating Prometheus Systemd Service
Now use the command below to create a Prometheus systemd service file:
sudo tee /etc/systemd/system/prometheus.service<<EOF
[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
EOF
Then we’ll modify its permission:
for i in rules rules.d files_sd; do sudo chown -R prometheus:prometheus /etc/prometheus/${i}; done
for i in rules rules.d files_sd; do sudo chmod -R 775 /etc/prometheus/${i}; done
sudo chown -R prometheus:prometheus /var/lib/prometheus/
Now, reload systemd
daemon and start the service:
sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus
Verify the service is active.
$ systemctl status prometheus
● prometheus.service - Prometheus
Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2023-02-22 07:33:01 EST; 32s ago
Docs: https://prometheus.io/docs/introduction/overview/
Main PID: 3834 (prometheus)
Tasks: 7 (limit: 4662)
Memory: 76.8M
CPU: 315ms
CGroup: /system.slice/prometheus.service
└─3834 /usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus --we>
Step 6: Accessing Prometheus Web Interface
Once the installation has been completed successfully, launch your preferred browser, go to http://your-domain.com:9090 or http://your-ip-address:9090, and follow the on-screen instructions to complete the setup.
![](https://i0.wp.com/tutornix.com/wp-content/uploads/2023/02/Screenshot-from-2023-02-22-07-45-37.png?resize=700%2C220&ssl=1)
Conclusion
Congratulations! Prometheus has been successfully installed. We appreciate you utilizing this guide to install Prometheus’ most recent version on Debian 12|Debian11. We advise you to visit the official Prometheus website. If you need any extra assistance or relevant information.
Other tutors: