Prometheus is a powerful and versatile open-source monitoring application that collects metrics from various services and stores them in a time-series database. With its multi-dimensional data model, flexible querying language, and extensive visualization capabilities, Prometheus is widely used by organizations to monitor the performance and health of their systems. In this tutorial, we will guide you through the process of installing Prometheus on Debian 11, step by step.
Prerequisites
Before we begin, make sure you have the following:
- A server running Debian 11.
- Root access to the server.
Step 1: Create a Dedicated User and Group for Prometheus
To ensure proper security and isolation, it is recommended to create a dedicated user and group for running the Prometheus service. Let’s create the user and group using the following commands:
sudo groupadd --system prometheus sudo useradd -s /sbin/nologin --system -g prometheus prometheus
Step 2: Download and Install Prometheus
Next, we need to download the latest version of Prometheus from the official website. We can do this by running the following commands:
wget https://github.com/prometheus/prometheus/releases/latest/download/prometheus-2.30.3.linux-amd64.tar.gz tar -xvf prometheus-2.30.3.linux-amd64.tar.gz
This will download the Prometheus binary and extract it into a directory named prometheus-2.30.3.linux-amd64
.
Step 3: Configure Prometheus
Now that we have Prometheus installed, we need to configure it to collect metrics from the services we want to monitor. Prometheus uses a configuration file to define its scraping targets, alerting rules, and other settings. Let’s create the configuration file using the following command:
nano /etc/prometheus/prometheus.yml
In this file, you can specify the targets you want Prometheus to scrape for metrics. For example, to scrape metrics from the node_exporter, you can add the following configuration:
scrape_configs: - job_name: 'node_exporter' static_configs: - targets: ['localhost:9100']
Save and close the file when you’re done.
Step 4: Set Up Prometheus as a Systemd Service
To run Prometheus as a service and ensure it starts automatically on system boot, we need to create a systemd service unit file. Let’s create the file using the following command:
sudo nano /etc/systemd/system/prometheus.service
In this file, add the following content:
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/path/to/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus
Restart=always
[Install]
WantedBy=multi-user.target
Replace /path/to/prometheus
with the actual path to the Prometheus binary, which should be /path/to/prometheus-2.30.3.linux-amd64/prometheus
.
Save and close the file when you’re done.
Step 5: Start and Enable Prometheus Service
Now that we have the Prometheus service unit file in place, we can start the service and enable it to start automatically on system boot. Run the following commands to do so:
sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus
You can verify the status of the Prometheus service by running:
sudo systemctl status prometheus
If everything is set up correctly, you should see the service as active and running.
Step 6: Configure Firewall for Prometheus
To allow incoming connections to the Prometheus web interface, we need to configure the firewall to allow traffic on port 9090. Run the following command to open port 9090:
sudo ufw allow 9090
If you’re using a different firewall management tool, make sure to open port 9090 accordingly.
Step 7: Access Prometheus Web Interface
With Prometheus running and the firewall configured, you can now access the Prometheus web interface from your browser. Open your preferred browser and enter the following URL:
http://your_server_ip:9090
Replace your_server_ip
with the actual IP address or domain name of your server running Prometheus.
You should see the Prometheus web interface, where you can explore metrics, create queries, and set up visualizations.
Step 8: Install and Configure Node Exporter
Node Exporter is an exporter for Prometheus that collects various system-level metrics from Linux servers. To install and configure Node Exporter, follow these steps:
Download and Extract Node Exporter
Download the latest version of Node Exporter using the following commands:
wget https://github.com/prometheus/node_exporter/releases/latest/download/node_exporter-1.2.2.linux-amd64.tar.gz tar -xvf node_exporter-1.2.2.linux-amd64.tar.gz
This will download the Node Exporter binary and extract it into a directory named node_exporter-1.2.2.linux-amd64
.
Create a Systemd Service for Node Exporter
To run Node Exporter as a service, create a systemd service unit file using the following command:
sudo nano /etc/systemd/system/node_exporter.service
Add the following content to the file:
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
ExecStart=/path/to/node_exporter
[Install]
WantedBy=default.target
Replace /path/to/node_exporter
with the actual path to the Node Exporter binary, which should be /etc/prometheus/node_exporter/node_exporter
.
Save and close the file when you’re done.
Start and Enable Node Exporter Service
Start the Node Exporter service and enable it to start automatically on system boot by running the following commands:
sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl enable node_exporter
You can verify the status of the Node Exporter service by running:
sudo systemctl status node_exporter
If everything is set up correctly, you should see the service as active and running.
Step 9: Add Node Exporter to Prometheus Configuration
To make Prometheus scrape metrics from Node Exporter, we need to update the Prometheus configuration file. Open the Prometheus configuration file using the following command:
sudo nano /etc/prometheus/prometheus.yml
Under the scrape_configs
section, add a new job for Node Exporter with the following configuration:
scrape_configs: - job_name: 'node_exporter' static_configs: - targets: ['localhost:9100']
Save and close the file when you’re done.
Step 10: Verify Prometheus and Node Exporter Integration
To verify that Prometheus is successfully scraping metrics from Node Exporter, go back to the Prometheus web interface and click on Status >Targets. You should see the Node Exporter target listed as UP.
Conclusion
Congratulations! You have successfully installed Prometheus and configured it to monitor your Debian 11 server. You have also set up Node Exporter to collect system-level metrics for Prometheus. With Prometheus and Node Exporter working together, you can now monitor the performance and health of your server in real-time.
Prometheus offers a wide range of features and integrations, allowing you to create custom dashboards, set up alerts, and gain valuable insights into your system. Explore the official Prometheus documentation for more information and advanced configuration options.
If you’re looking for a reliable and scalable hosting solution for your Prometheus setup, consider Shape.host’s Linux SSD VPS services. With their high-performance infrastructure and expert support, Shape.host can provide you with the ideal environment to run Prometheus and ensure its optimal performance. Visit Shape.host for more information.