How to Install Prometheus Server on Debian 11 Open Source Monitoring

How to install Prometheus server on Debian 11 open source monitoring. Prometheus is a free and open source monitoring system with a dimensional data model, a flexible query language, an efficient time series database, and a contemporary alerting methodology.

It is a flexible tool that can collect data from almost any infrastructure component, such as the Linux kernel, Docker containers, Kubernetes pods, and more. It is presented in a format that’s easy to query and visualize. Our content of  monitoring section is very interesting so please take a look also. 

This tutorial will go through the features, benefits, installation, and configuration process of the Prometheus server on Debian 11. This article will also discuss how you can run the Prometheus server securely with the help of the Nginx reverse proxy.

What is Prometheus

System monitoring tools are the way to go in a world where businesses need to monitor and analyse the performance of their apps and infrastructure using metrics.

Prometheus is one such system monitoring and alerting tool, built on top of Zookeeper. It can be used to monitor a variety of types of services and data stores, such as operating system metrics, service discovery, load balancers, and application metrics.

SoundCloud was the original creator of Prometheus. It is now a self contained open source project managed by the Cloud Native Computing Foundation (CNCF).

With Prometheus there is a flexible schema and it can store almost any kind of metric. It collects metrics from different kinds of system components (e.g., applications, libraries, daemons) and exposes them in a publish and monitor way so that they can be analysed by external tools such as graphd and Grafana.

Numerous Prometheus server configuration options are available to customize how data is collected and stored for analysis purposes.

Additionally, Prometheus is designed to easily be extended by anyone writing plugins that implement the metrics schema and publish their data to Prometheus.

It has since been adopted by many organizations, including Twitter, Facebook, and Digital Ocean.

Features of Prometheus

Some of the key features of Prometheus are as follows:

  • Time series data is identifiable by metric name and key value pairs in a multidimensional data model.
  • PromQL is a versatile querying language that can make use of multidimensional data architecture.
  • There is no dependency on distributed storage because all single server nodes are autonomous.
  • Prometheus may gather time-series data by actively “pulling” data via HTTP.
  • Pushing time series data is possible with the use of an intermediate gateway.
  • Monitoring Target Discovery is possible via static configuration or by service discovery.
  • Prometheus provides great visualization, including a variety of graphs and dashboards.

Advantages of Prometheus

Here are some benefits of using the Prometheus server.

  • It helps with reducing project planning complexity.
  • Promentues automated tasks so time and effort are spared.
  • There are numerous data visualization modes.
  • An expression browser is built in, as is Grafana connectivity and a console template language.
  • Allow for the bridging of third party data.
  • PromQL enables the slicing and dicing of time-series data.
  • The Alert System in  Prometheus  records and documents the various control techniques.
  • Implementation, commissioning and deployment no longer require extensive knowledge.
  • All standards, regardless of manufacturer or device type, may be handled centrally.

Let’s move to How to install Prometheus server on Debian 11 open source monitoring.

How to Install Prometheus Server on Debian 11

Prerequisites

You will need:

  • Debian 11 system.
  • A user with root or sudo privileges.
  • A network connection.

Update Server Packages

Run the following commands to ensure all the packages are up to date and the server is ready for the Prometheus installation.

				
					sudo apt update -y
sudo apt upgrade -y
				
			

Create Prometheus Data and Configuration Directories

Before you begin, run the following commands to set up the Prometheus data and configuration directories.

				
					sudo mkdir /var/lib/prometheus
sudo mkdir -p /etc/prometheus/rules /etc/prometheus/rules.d /etc/prometheus/files_sd

				
			

Download and Install Prometheus Server

Once the directories are created, you can go ahead and download the latest version of Prometheus, either directly from the Prometheus downloads page or using the following command.

				
					sudo curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi -
				
			

Once the download is complete, use the following command to extract the downloaded file.

				
					sudo tar xvf prometheus*.tar.gz
				
			

Now, navigate to the extracted directory and copy the contents of the Prometheus binary to the system directory /usr/local/bin/.

				
					cd prometheus*/
sudo mv prometheus promtool /usr/local/bin/

				
			

Move the following configuration files and directories to the /etc/prometheus directory:

				
					sudo mv prometheus.yml /etc/prometheus/prometheus.yml
sudo mv consoles/ console_libraries/ /etc/prometheus/

				
			

Verify Prometheus and Promtool Version 

You can verify the Prometheus version using the following commands.

				
					prometheus --version
				
			

Output:

				
					prometheus, version 2.37.0 (branch: HEAD, revision: b41e0750abf5cc18d8233161560731de05199330)
  build user:       root@0ebb6827e27f
  build date:       20220714-15:13:18
  go version:       go1.18.4
  platform:         linux/amd64
				
			

Similarly, check the Promtool version with the following command.

				
					promtool --version

				
			

Output:

				
					promtool, version 2.37.0 (branch: HEAD, revision: b41e0750abf5cc18d8233161560731de05199330)
  build user:       root@0ebb6827e27f
  build date:       20220714-15:13:18
  go version:       go1.18.4
  platform:         linux/amd64

				
			

Set Up Authentication

Prometheus can be accessed without a password by default, which poses a significant security risk. So, use the following steps to secure Prometheus with the password.

To generate a safe password, install the Python Bcrypt utility with the following command.

				
					sudo apt install python3-bcrypt gnupg2 -y
				
			

Output:

				
					Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
gnupg2 is already the newest version (2.2.27-2+deb11u2).
The following NEW packages will be installed:
  python3-bcrypt python3-cffi-backend
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
...
				
			

Here you will need to run the Python script to generate the password, so create a Python file.

				
					nano gen-pass.py
				
			

And add the following code.

				
					import getpass
import bcrypt

password = getpass.getpass("password: ")
hashed_password = bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt())
print(hashed_password.decode())

				
			

Finally, save and exit the file before running the script to generate a password.

				
					sudo python3 gen-pass.py
				
			

Output:

				
					password: 
$2b$12$I1vOrKmkp69aHqC0Cxy/cevXAxwJ8z.jp1VIKFTfN/OFKrCZEbh7q

				
			

Now, create a web.yml configuration file to define the generated password.

				
					sudo nano /etc/prometheus/web.yml
				
			

Add the following code to the file.

				
					basic_auth_users:
       admin: '$2b$12$I1vOrKmkp69aHqC0Cxy/cevXAxwJ8z.jp1VIKFTfN/OFKrCZEbh7q'

				
			

Save and exit the file. Use the following command to validate the web.yml file:

				
					promtool check web-config /etc/prometheus/web.yml
				
			

Output:

				
					/etc/prometheus/web.yml SUCCESS
				
			

Set Up Prometheus user and group

Create a dedicated Prometheus user and group with the following commands.

				
					sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus

				
			

 Next, use the following command to configure directory permissions and ownership.

				
					sudo chown -R prometheus:prometheus /etc/prometheus
sudo chmod -R 775 /etc/prometheus/
sudo chown -R prometheus:prometheus /var/lib/prometheus/

				
			

Configure the Prometheus Service File

To administer the Prometheus service through systemd, you must first create and open the Prometheus service file.

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

And add the following code.

				
					[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.config.file=/etc/prometheus/web.yml \
  --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
				
			

Save and exit the file. Then, restart the systemd daemon to apply the changes.

				
					sudo systemctl daemon-reload
				
			

Now, you can manage the Prometheus services with the following systemctl commands.

				
					sudo systemctl start prometheus
sudo systemctl enable prometheus
sudo systemctl status prometheus

				
			

Install and Configure Nginx as a Reverse Proxy

You can use and communicate with the Prometheus server through the port directly, but it is not secure or practical for the server. So next, you need to set up a reverse proxy for the Prometheus server so that the server does not have to communicate with the users directly.

Install the Nginx Web Server

For that purpose, install the Nginx server using the following command.

				
					sudo apt-get install nginx -y
				
			

Output:

				
					Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  geoip-database libgeoip1 libnginx-mod-http-geoip libnginx-mod-http-image-filter
  libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream
  libnginx-mod-stream-geoip nginx-common nginx-core
Suggested packages:
  geoip-bin fcgiwrap nginx-doc
The following NEW packages will be installed:
  geoip-database libgeoip1 libnginx-mod-http-geoip libnginx-mod-http-image-filter
  libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream
  libnginx-mod-stream-geoip nginx nginx-common nginx-core
0 upgraded, 11 newly installed, 0 to remove and 0 not upgraded.
...
				
			

Configure the Nginx Web Server

Once the Nginx package has been installed, use the following command to build an Nginx virtual host configuration file:

				
					sudo nano /etc/nginx/conf.d/prometheus.conf
				
			

Add the following lines of code to the file.

				
					server {
    listen 80;
    server_name  10.0.2.15;
    location / {
        proxy_pass           http://localhost:9090/;
    }
}

				
			

Save and close the file. Next, check the Nginx configuration.

				
					sudo nginx -t
				
			

You should see the following output.

				
					nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

				
			

Now restart and ensure the Nginx service is running properly using the following commands.

				
					sudo systemctl restart nginx
sudo systemctl status nginx

				
			

Access the Prometheus Server Dashboard

Now, open your web browser and navigate to the Prometheus dashboard using the following URL.

				
					http://
				
			

You will be prompted to enter your username and password.

Enter your admin login and password, then click the Sign in button. Once logged in, you should see the Prometheus dashboard on the screen below:

That’s it for How to install Prometheus server on Debian 11 open source monitoring.

How to Install Prometheus Server on Debian 11 Open Source Monitoring Conclusion

In this article, you have learned how to install and configure the Prometheus server for system monitoring in Debian 11. Moreover, how to utilize a reverse proxy as a cover to run the Prometheus server securely.

Prometheus is an open source monitoring and alerting system that collects metrics from various system components.

It provides monitoring and alerting features for cloud-native systems such as Kubernetes. Prometheus gathers and stores measurements as time-series data, collects information with a timestamp and stores labels, which are optional key value pairs, and compiles all this information and presents it in its aggregated form.

Learn more about other system monitoring tools and solutions like this in our monitoring section.

Avatar for Sobia Arshad
Sobia Arshad

Information Security professional with 4+ years of experience. I am interested in learning about new technologies and loves working with all kinds of infrastructures.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x