
Setting up Prometheus on Ubuntu 24.04 is a fundamental step for implementing a robust monitoring system. This guide covers the essential process to get Prometheus up and running efficiently.
The first crucial step is to enhance security and organization by creating a dedicated system user and necessary directories. You should create a user specifically for Prometheus with no login shell and its own group:
sudo useradd --no-create-home --shell /bin/false prometheus
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus
Next, you need to download the latest Prometheus release. Always obtain the correct architecture for your server. Once downloaded, extract the contents of the tarball.
After extraction, move the key components into their designated system paths. The core binaries, prometheus and promtool, should reside in /usr/local/bin. The configuration files and example consoles should go into /etc/prometheus. Ensure correct ownership is set for security:
# Assuming extraction directory is named prometheus-VERSION.linux-amd64
sudo mv prometheus-VERSION.linux-amd64/prometheus /usr/local/bin/
sudo mv prometheus-VERSION.linux-amd64/promtool /usr/local/bin/
sudo chown prometheus:prometheus /usr/local/bin/prometheus
sudo chown prometheus:prometheus /usr/local/bin/promtool
sudo mv prometheus-VERSION.linux-amd64/consoles /etc/prometheus
sudo mv prometheus-VERSION.linux-amd64/console_libraries /etc/prometheus
sudo mv prometheus-VERSION.linux-amd64/prometheus.yml /etc/prometheus
sudo chown -R prometheus:prometheus /etc/prometheus/consoles
sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries
sudo chown prometheus:prometheus /etc/prometheus/prometheus.yml
Replace VERSION
with the actual version number.
With the files in place, configure Prometheus to run as a systemd service. Create a service file at /etc/systemd/system/prometheus.service. This file tells systemd how to start and manage the Prometheus process. A typical configuration includes specifying the user, group, working directory, configuration file location, and storage path:
[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/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
Save the file, then reload the systemd manager configuration to recognize the new service:
sudo systemctl daemon-reload
Now you can start the Prometheus service and enable it to launch automatically at boot:
sudo systemctl start prometheus
sudo systemctl enable prometheus
Verify the service status to ensure it is running without errors:
sudo systemctl status prometheus
Finally, access the Prometheus web UI by navigating to your server’s IP address or hostname on port 9090 (http://yourserverip:9090). This confirms a successful installation and allows you to begin configuring targets for Prometheus to scrape metrics from.
Source: https://kifarunix.com/how-to-install-prometheus-on-ubuntu-24-04/