DevOps & Linux 3d ago 8 views 4 min read

How to Install and Configure Prometheus on Ubuntu 24.04

Install Prometheus 2.54.0 on Ubuntu 24.04 using the official binary. Configure basic metrics collection, start the service, and verify it is listening on port 9090.

Master Sensei
Updated 19h ago
Sponsored

Cloud VPS — scale in minutes

Instantly deploy SSD cloud VPS with guaranteed resources, snapshots and per-hour billing. Pay only for what you use.

Install Prometheus 2.54.0 on Ubuntu 24.04 to collect and visualize system metrics. These steps target Ubuntu 24.04 LTS with a non-root user who has sudo privileges.

Prerequisites

  • Ubuntu 24.04 LTS operating system.
  • A non-root user account with sudo privileges.
  • At least 512 MB of free RAM.
  • Unstable network connection during download (optional).

Step 1: Create the Prometheus User

Create a dedicated system user to run Prometheus. This separates metrics collection from your main application accounts. Create the user and add it to the sudo group.

sudo useradd -r -m -s /bin/false prometheus
sudo usermod -aG sudo prometheus

Verify the user exists and belongs to the sudo group.

id prometheus

You will see output similar to this:

uid=1001(prometheus) gid=1001(prometheus) groups=1001(prometheus),27(sudo)

Step 2: Download Prometheus Binary

Download the official Prometheus binary for Linux x86_64. Use the latest stable release available at the time of writing. This version is 2.54.0.

cd /tmp
wget https://github.com/prometheus/prometheus/releases/download/v2.54.0/prometheus-2.54.0.linux-amd64.tar.gz

Extract the archive and move the binary to a system directory.

tar xvf prometheus-2.54.0.linux-amd64.tar.gz
sudo mv prometheus-2.54.0.linux-amd64/prometheus /usr/local/bin/
sudo mv prometheus-2.54.0.linux-amd64/CONTRIBUTING.md /usr/local/share/doc/prometheus/
sudo mv prometheus-2.54.0.linux-amd64/LICENSE /usr/local/share/doc/prometheus/
sudo mv prometheus-2.54.0.linux-amd64/README.md /usr/local/share/doc/prometheus/
sudo mv prometheus-2.54.0.linux-amd64/RELEASE.md /usr/local/share/doc/prometheus/
sudo mv prometheus-2.54.0.linux-amd64/MAINTAINERS.md /usr/local/share/doc/prometheus/

Step 3: Create Configuration Directory

Create a directory for Prometheus configuration files. Set ownership to the prometheus user. This keeps config separate from binaries.

sudo mkdir /etc/prometheus
sudo chown prometheus:prometheus /etc/prometheus

Create a configuration file to define scrape targets. Edit this file to add your own nodes later.

sudo nano /etc/prometheus/prometheus.yml

Add the following content to the file:

global:
  scrape_interval: 15s
  evaluation_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

Save and exit the editor. Ensure the file permissions are correct.

sudo chown prometheus:prometheus /etc/prometheus/prometheus.yml

Step 4: Create the Service Unit

Create a systemd service unit file to manage Prometheus. This file defines how the system starts and stops the application.

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

Paste the following content into the file:

[Unit]
Description=Prometheus
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.listen-address=0.0.0.0:9090 \
  --web.enable-lifecycle
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target

Reload the systemd daemon to apply changes.

sudo systemctl daemon-reload

Verify the installation

Start the Prometheus service and check its status. Ensure it is active and running without errors.

sudo systemctl start prometheus
sudo systemctl status prometheus

You will see output indicating the service is active (running).

● prometheus.service - Prometheus
   Loaded: loaded (/etc/systemd/system/prometheus.service; enabled)
   Active: active (running) since Wed 2024-01-01 10:00:00 UTC; 1min ago

Open a web browser and navigate to http://localhost:9090. You will see the Prometheus UI with the "Targets" tab showing the local node as "UP".

Troubleshooting

If the service fails to start, check the logs for specific errors. Run the following command to view recent logs:

sudo journalctl -u prometheus -n 50 --no-pager

Error: Permission denied
Fix: Ensure the config file and storage directory are owned by the prometheus user. Run sudo chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus.

Error: Port 9090 already in use
Fix: Another process is using port 9090. Kill the process with sudo lsof -i :9090 | grep PID or change the port in the service file.

Error: Configuration file not found
Fix: Verify the path in the service file matches the actual location. Run ls -l /etc/prometheus/prometheus.yml to confirm existence.

Error: TSDB not initialized
Fix: Prometheus creates the storage directory automatically. If it is missing, create it with sudo mkdir -p /var/lib/prometheus and set ownership.

Restart the service after fixing any errors to apply changes.

sudo systemctl restart prometheus
Sponsored

Windows Dedicated Server

High-performance Windows dedicated servers with licensed Windows Server, Remote Desktop access and enterprise-grade hardware.

Tags: LinuxDevOpsUbuntuMonitoringprometheus
0
Was this helpful?

Related tutorials

Comments 0

Login to leave a comment.

No comments yet — be the first to share your thoughts.