Installation Guides 4d ago 4 views 4 min read

How to deploy Prometheus on Ubuntu 24.04

Install Prometheus monitoring server, configure node_exporter, and set up basic scraping rules on Ubuntu 24.04 LTS with exact commands.

Roy S
Updated 8h 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.

You will install the Prometheus monitoring system and the node_exporter agent to collect system metrics. This guide targets Ubuntu 24.04 LTS and uses the official Debian packages for Prometheus 2.54.0 and node_exporter 1.8.1.

Prerequisites

  • Ubuntu 24.04 LTS server with root or sudo access.
  • Internet connection to download packages from the official Prometheus repository.
  • At least 512 MB of free RAM for the Prometheus server process.
  • Open ports 9090 (Prometheus HTTP) and 9100 (node_exporter HTTP) on the firewall.

Step 1: Add the Prometheus APT repository

You need to import the official GPG key and add the repository to your package sources. This ensures you install the latest stable version directly from the Prometheus team.

curl -sSL https://raw.githubusercontent.com/prometheus/prometheus/main/contrib/debian/prometheus-release/debian-12/keyring.gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/prometheus.gpg
curl -sSL https://raw.githubusercontent.com/prometheus/prometheus/main/contrib/debian/prometheus-release/debian-12/sources.list.d/prometheus.list | sudo tee /etc/apt/sources.list.d/prometheus.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
deb [arch=amd64] https://prometheus-release.s3.amazonaws.com/debian/12/ prometheus main

Step 2: Install Prometheus and node_exporter

Update your package index and install both the Prometheus server and the node_exporter agent. These packages will be installed in the /usr/local/bin directory by default.

sudo apt update
sudo apt install prometheus node-exporter -y
Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
  node-exporter prometheus
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.

Step 3: Configure Prometheus for local scraping

Edit the default configuration file to ensure the server scrapes the local node_exporter instance. This is essential for monitoring the server itself immediately after installation.

sudo nano /etc/prometheus/prometheus.yml

Add the following global scrape interval and job configuration inside the file:

global:
  scrape_interval: 15s
  evaluation_interval: 15s

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

  - job_name: 'node'
    static_configs:
      - targets: ['localhost:9100']

Save the file and exit the editor. Ensure the file permissions are correct so the prometheus user can read it.

sudo chown -R prometheus:prometheus /etc/prometheus/
sudo chmod 644 /etc/prometheus/prometheus.yml

Step 4: Enable and start the services

Create systemd service files or use the existing ones to manage the processes. The official packages usually create /etc/systemd/system/prometheus.service and /etc/systemd/system/node_exporter.service. Reload the daemon and start both services.

sudo systemctl daemon-reload
sudo systemctl enable prometheus
sudo systemctl enable node_exporter
sudo systemctl start prometheus
sudo systemctl start node_exporter
prometheus.service is a service that runs prometheus
node_exporter.service is a service that runs node_exporter
prometheus.service is enabled
node_exporter.service is enabled

Verify the installation

Check the status of both services to ensure they are running without errors. Then open the Prometheus web interface in your browser at http://your-server-ip:9090. You should see the Prometheus dashboard with the "node" job data populated.

sudo systemctl status prometheus
sudo systemctl status node_exporter

You will see "active (running)" for both services. To verify the web UI is accessible, run a curl command against the metrics endpoint:

curl -s http://localhost:9090/metrics | head -n 5
# HELP prometheus_build_info Prometheus build information
# TYPE prometheus_build_info gauge
prometheus_build_info{version="2.54.0",branch="main",revision="..."} 1
# HELP prometheus_tsdb_head_chunks_total Total number of active chunks in the head block
# TYPE prometheus_tsdb_head_chunks_total gauge
prometheus_tsdb_head_chunks_total 0

For the node_exporter, verify it is exposing metrics:

curl -s http://localhost:9100/metrics | head -n 5

You should see system metrics like node_cpu_seconds_total or node_memory_MemTotal_bytes. If the web UI shows "no targets" or "no data", check the service logs for connection errors.

Troubleshooting

If the Prometheus service fails to start, check the journal logs for specific errors. Common issues include missing directories or permission denied errors.

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

If you see "Failed to create directory", ensure /etc/prometheus exists and is owned by the prometheus user. If you see "bind: permission denied", ensure port 9090 is not blocked by a firewall or another service.

sudo mkdir -p /etc/prometheus
sudo chown prometheus:prometheus /etc/prometheus

If node_exporter fails, check if port 9100 is in use. You can kill the process or change the port in the service file.

sudo lsof -i :9100

To restart services after fixing configuration errors, run the following commands:

sudo systemctl restart prometheus
sudo systemctl restart node_exporter

Always verify the status after restarting to ensure the fixes resolved the issue.

Sponsored

Windows Dedicated Server

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

Tags: LinuxUbuntuMonitoringprometheussops
0
Was this helpful?

Related tutorials

Comments 0

Login to leave a comment.

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