Install and configure Prometheus on Debian 10/11
Prometheus is a free and open source monitoring system that allows you to collect time-series data metrics. Let's see how to install and configure it.
Prepare the installation
Create Prometheus system user / group
sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheusCreate configuration and data directories
sudo mkdir /var/lib/prometheus
for i in rules rules.d files_sd; do sudo mkdir -p /etc/prometheus/${i}; done
Installation
Install cURL, then download the latest version of Prometheus
sudo apt-get update
sudo apt-get -y install wget curl
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 -Extract the file
tar xvf prometheus*.tar.gz
cd prometheus*/Finish the installation
sudo mv prometheus promtool /usr/local/bin/
sudo mv prometheus.yml /etc/prometheus/prometheus.yml
sudo mv consoles/ console_libraries/ /etc/prometheus/
cd ~/
rm -rf /tmp/prometheus
Configuration
The configuration file can be found in the path below. Edit it to suit your needs
nano /etc/prometheus/prometheus.yml
To be able to manage the Prometheus service with systemd, you need to explicitly define this unit file (it's a single command!)
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
EOFEdit permissions
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/Reload, enable and start the Prometheus service in systemd
sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheusConfirm that the service is up and running
systemctl status prometheus
Access Prometheus web interface on URL http://[ip_hostname]:9090
- That's all. If you have any comments/questions, leave them below.
Comments