top of page
Search

How to Install and Configure Prometheus on Linux


Introduction to Prometheus


Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. Since its inception, it has become a widely adopted monitoring solution, especially in cloud-native environments. Prometheus excels at collecting and storing time-series data, offering powerful querying capabilities via its own language, PromQL. It integrates seamlessly with cloud infrastructure, container orchestration platforms like Kubernetes, and many third-party applications. Its reliability and scalability make it a preferred choice for monitoring complex distributed systems.


Features of Prometheus:


  • Time-Series Data: Collects metrics as time-series data, i.e., metrics information is stored with a timestamp.

  • PromQL: A flexible query language that allows you to query and aggregate metrics in real-time.

  • Service Discovery: Automatically discovers targets to monitor based on the environment.

  • Multi-dimensional Data Model: Allows tagging of metrics with key/value pairs called labels.

  • Alerting: Features an integrated alerting system that enables the creation of sophisticated alerts.


Prometheus is an essential tool for anyone looking to monitor and manage the performance and health of their systems efficiently. Its ecosystem, including exporters, alert manager, and visualization tools, provides a comprehensive monitoring solution.


Step 1: Add a Prometheus User

Create a user for Prometheus with no login privileges to enhance security.

sudo useradd --no-create-home --shell /bin/false prometheus

Step 2: Create Prometheus Directories

Set up directories to store Prometheus data and configuration files.


sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus

Step 3: Download and Install Prometheus

Visit the [Prometheus Download Page](https://prometheus.io/download/) to get the latest version.

tar -xvf prometheus-2.42.0.linux-amd64.tar.gz

Step 4: Move Files to the Appropriate Directories

Move the binaries and configuration files to their respective directories.


sudo mv prometheus /usr/local/bin/
sudo mv promtool /usr/local/bin/
sudo mv prometheus.yml /etc/prometheus/
sudo mv consoles /etc/prometheus/
sudo mv console_libraries /etc/prometheus/

Step 5: Set Ownership and Permissions

Change ownership of the directories and files to the Prometheus user.


sudo chown -R prometheus:prometheus /etc/prometheus
sudo chown -R prometheus:prometheus /var/lib/prometheu

Step 6: Create a Systemd Service File

Create a systemd service file for Prometheus to manage it as a service.

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

Add the following content:

[Unit]
Description=Prometheus Monitoring
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus/
[Install]
WantedBy=multi-user.target

Step 7: Start and Enable Prometheus

Start the Prometheus service and enable it to run at boot.


sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus

Step 8: Configure Firewall

If you have a firewall enabled, allow access to Prometheus's default port (9090).


sudo firewall-cmd --zone=public --add-port=9090/tcp --permanent
sudo firewall-cmd --reload

Step 9: Access Prometheus Web Interface


Open your web browser and navigate to `http://<your-server-ip>:9090` to access the Prometheus dashboard.


Prometheus Project:



Conclusion

You have successfully installed and configured Prometheus on your Linux server. Prometheus is now set up to monitor your infrastructure, and you can explore its powerful features for monitoring and alerting.


 
 
 

Comments


bottom of page