Prometheus is a powerful monitoring tool that allows you to collect and store time-series data from various sources. It offers flexibility through its query language, PromQL, which enables you to retrieve and analyze the collected data.
In this tutorial, we will focus on installing Prometheus on AlmaLinux 9, a popular Linux distribution. Prometheus can be installed on traditional Unix/Linux servers using pre-compiled packages, container technologies like Docker and Kubernetes, or configuration management tools such as Ansible, Chef, Puppet, and Saltstack.
Prerequisites
Before we begin, make sure you have the following:
- Two AlmaLinux 9 servers – one for the Prometheus server and another for the Node Exporter.
- A non-root user with sudo privileges on both servers.
- Basic knowledge of Linux command-line interface (CLI).
Now that we have everything we need, let’s proceed with the installation.
Installing Prometheus
Setting Up User and Directories
To start, we need to create a new system user and directories on your AlmaLinux server. This user will be used to run Prometheus, and the directories will store the configuration files and data.
Run the following command to create a new system user named prometheus
:
sudo adduser -M -r -s /sbin/nologin prometheus
Next, create the necessary directories:
sudo mkdir /etc/prometheus sudo mkdir /var/lib/prometheus
Change the ownership of the directories to the prometheus
user:
sudo chown prometheus:prometheus /etc/prometheus sudo chown prometheus:prometheus /var/lib/prometheus
Downloading Prometheus
Now, let’s download and install Prometheus on your AlmaLinux server.
First, install the wget
package if it’s not already installed:
sudo dnf install wge t -y
Move to the /usr/src
directory and download the pre-compiled binary file of Prometheus:
cd /usr/src wget https://github.com/prometheus/prometheus/releases/download/v2.44.0/prometheus-2.44.0.linux-amd64.tar.gz
Extract the downloaded file:
tar -xf prometheus-2.44.0.linux-amd64.tar.gz
Copy the default Prometheus configuration file, console templates, and console libraries to the appropriate directories:
sudo cp /usr/src/prometheus-*/prometheus.yml /etc/prometheus/ sudo cp -r /usr/src/prometheus-*/consoles /etc/prometheus/ sudo cp -r /usr/src/prometheus-*/console_libraries /etc/prometheus/
Change the ownership of the /etc/prometheus
directory:
sudo chown -R prometheus:prometheus/etc/prometheus
Copy the Prometheus binary files to the /usr/bin
directory:
sudo cp /usr/src/prometheus-*/prometheus /usr/bin/ sudo cp /usr/src/prometheus-*/promtool /usr/bin/
Verify the installation:
which prometheus prometheus --version which promtool promtool --version
Configuring Prometheus
Now that Prometheus is installed, let’s configure it.
Open the Prometheus configuration file using a text editor:
sudo nano /etc/prometheus/prometheus.yml
Add the following configuration to scrape the Prometheus server itself:
scrape_configs: - job_name: "prometheus" static_configs: - targets: ["localhost:9090"]
Save and close the file.
Running Prometheus as a Systemd Service
To run Prometheus as a systemd service, create a new service file:
sudo nano /etc/systemd/system/prometheus.service
Add the following configuration:
[Unit] Description=Prometheus Wants=network-online.target After=network-online.target [Service] User=prometheus Group=prometheus Type=simple ExecStart=/usr/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 [Install] WantedBy=multi-user.target
Save and close the file.
Reload the systemd manager to apply the changes:
sudo systemctl daemon-reload
Start and enable the Prometheus service:
sudo systemctl start prometheus sudo systemctl enable prometheus
Verify the status of the Prometheus service:
sudo systemctl status prometheus
Verifying Prometheus Installation
To verify the Prometheus installation, open your web browser and visit the Prometheus server’s IP address followed by port 9090 (e.g., http://yourserverip:9090/).
You should see the Prometheus web interface, where you can explore the available metrics and create custom queries using PromQL.
Conclusion
In this tutorial, we have learned how to install Prometheus on AlmaLinux 9. We started by setting up user and directories, downloading Prometheus, configuring it, and running it as a systemd service. Finally, we verified the installation by accessing the Prometheus web interface.
Prometheus is a powerful monitoring tool that can help you gain insights into your server’s performance and troubleshoot issues. Combined with other components like the Node Exporter, you can create a comprehensive monitoring system for your infrastructure.
If you’re looking for reliable and scalable cloud hosting solutions, consider Shape.host. They offer Cloud VPS services that ensure high performance, security, and flexibility for your business needs. Visit Shape.host to learn more about their hosting services.
Happy monitoring with Prometheus!