Install and configure Prometheus on Debian 10/11

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

  1. Create Prometheus system user / group
    sudo groupadd --system prometheus

    sudo useradd -s /sbin/nologin --system -g prometheus prometheus
  2. Create 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

  1. 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 -
  2. Extract the file
    tar xvf prometheus*.tar.gz

    cd prometheus*/
  3. 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

  1. The configuration file can be found in the path below. Edit it to suit your needs
    nano /etc/prometheus/prometheus.yml
  2. 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
    EOF
  3. Edit 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/
  4. Reload, enable and start the Prometheus service in systemd
    sudo systemctl daemon-reload

    sudo systemctl start prometheus

    sudo systemctl enable prometheus
  5. Confirm that the service is up and running
    systemctl status prometheus
  6. Access Prometheus web interface on URL http://[ip_hostname]:9090
  7. That's all. If you have any comments/questions, leave them below.

Comments