База на знаења

Prometheus Print

  • 0

How to Install Prometheus 2.55.1 and Node Exporter 1.10.2 on Ubuntu 24.04

This beginner-friendly guide explains how to manually install and configure Prometheus 2.55.1 and Node Exporter 1.10.2 on an Ubuntu 24.04 server.

The manual installation steps below follow the same configuration provided in the Prometheus Ansible deployment.

What will be installed:
  • Prometheus 2.55.1
  • Prometheus configuration
  • Prometheus systemd service
  • Node Exporter 1.10.2
  • Node Exporter systemd service
  • Prometheus data storage
Requirements:
  • Ubuntu 24.04 LTS
  • Root or sudo access
  • Internet connection
  • SSH access to the server

Step 1: Connect to Your Ubuntu Server

Open PowerShell, Windows Terminal, PuTTY, or another SSH client. Connect to your Ubuntu server using:

ssh username@SERVER-IP

Replace username with your Ubuntu username and SERVER-IP with your server IP address.

Example:

ssh ubuntu@203.0.113.10

Step 2: Check the Ubuntu Version

Confirm that the server is running Ubuntu 24.04:

lsb_release -a

You should see Ubuntu 24.04 information in the output.


Step 3: Update Ubuntu

First update the Ubuntu package list:

sudo apt update

Upgrade the installed packages:

sudo apt upgrade -y

Step 4: Install Required Packages

The Ansible playbook requires wget and tar. Install them:

sudo apt install -y wget tar

Check that they are installed:

wget --version
tar --version

Step 5: Create the Prometheus Group

Prometheus will run using a dedicated system user. First create the Prometheus system group:

sudo groupadd --system prometheus

Step 6: Create the Prometheus User

Create the Prometheus system user:

sudo useradd --system --no-create-home --shell /usr/sbin/nologin --gid prometheus prometheus

Verify the user:

id prometheus

Step 7: Create Prometheus Directories

Create the Prometheus configuration directory:

sudo mkdir -p /etc/prometheus

Create the Prometheus data directory:

sudo mkdir -p /var/lib/prometheus

The directories are used as follows:

  • /etc/prometheus - Prometheus configuration files
  • /var/lib/prometheus - Prometheus monitoring data

Step 8: Download Prometheus 2.55.1

Move to the temporary directory:

cd /tmp

Download Prometheus version 2.55.1:

wget https://github.com/prometheus/prometheus/releases/download/v2.55.1/prometheus-2.55.1.linux-amd64.tar.gz

Check that the file exists:

ls -lh /tmp/prometheus-2.55.1.linux-amd64.tar.gz

Step 9: Extract Prometheus

Extract the Prometheus archive into /tmp:

sudo tar -xzf /tmp/prometheus-2.55.1.linux-amd64.tar.gz -C /tmp

Check the extracted files:

ls -lah /tmp/prometheus-2.55.1.linux-amd64

The directory should contain the Prometheus and Promtool binaries.


Step 10: Install the Prometheus Binary

Copy the Prometheus binary to /usr/local/bin:

sudo cp /tmp/prometheus-2.55.1.linux-amd64/prometheus /usr/local/bin/prometheus

Set the owner:

sudo chown prometheus:prometheus /usr/local/bin/prometheus

Make the binary executable:

sudo chmod 755 /usr/local/bin/prometheus

Verify the installation:

/usr/local/bin/prometheus --version

Step 11: Install Promtool

Copy Promtool:

sudo cp /tmp/prometheus-2.55.1.linux-amd64/promtool /usr/local/bin/promtool

Set ownership:

sudo chown prometheus:prometheus /usr/local/bin/promtool

Set executable permissions:

sudo chmod 755 /usr/local/bin/promtool

Verify Promtool:

/usr/local/bin/promtool --version

Step 12: Copy Prometheus Console Files

Prometheus includes console files used by its web interface. Copy the console directory:

sudo cp -r /tmp/prometheus-2.55.1.linux-amd64/consoles /etc/prometheus/

Copy the console libraries:

sudo cp -r /tmp/prometheus-2.55.1.linux-amd64/console_libraries /etc/prometheus/

Step 13: Create the Prometheus Configuration

Create the Prometheus configuration file:

sudo nano /etc/prometheus/prometheus.yml

Paste the following configuration:

global:
  scrape_interval: 15s

scrape_configs:

  - job_name: "prometheus"
    static_configs:
      - targets:
          - "localhost:9090"

  - job_name: "node_exporter"
    static_configs:
      - targets:
          - "localhost:9100"

Save the file:

  • Press Ctrl + O
  • Press Enter
  • Press Ctrl + X

Step 14: Set Prometheus Ownership

Make the Prometheus user the owner of the configuration directory:

sudo chown -R prometheus:prometheus /etc/prometheus

Set ownership of the data directory:

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

Step 15: Validate the Prometheus Configuration

Use Promtool to check the configuration before starting Prometheus:

sudo -u prometheus promtool check config /etc/prometheus/prometheus.yml
Success: If Promtool reports that the configuration is valid, continue to the next step.

Step 16: Create the Prometheus systemd Service

Create the Prometheus service file:

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

Paste:

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
Restart=on-failure
RestartSec=5s
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 \
  --web.listen-address=0.0.0.0:9090 \
  --web.enable-lifecycle \
  --log.level=info

[Install]
WantedBy=multi-user.target

Save the file:

  • Press Ctrl + O
  • Press Enter
  • Press Ctrl + X

Step 17: Download Node Exporter 1.10.2

Node Exporter collects system and hardware metrics that Prometheus can monitor.

Move to the temporary directory:

cd /tmp

Download Node Exporter 1.10.2:

wget https://github.com/prometheus/node_exporter/releases/download/v1.10.2/node_exporter-1.10.2.linux-amd64.tar.gz

Check the downloaded file:

ls -lh /tmp/node_exporter-1.10.2.linux-amd64.tar.gz

Step 18: Extract Node Exporter

Extract the archive:

sudo tar -xzf /tmp/node_exporter-1.10.2.linux-amd64.tar.gz -C /tmp

Check the extracted files:

ls -lah /tmp/node_exporter-1.10.2.linux-amd64

Step 19: Install Node Exporter

Copy Node Exporter to /usr/local/bin:

sudo cp /tmp/node_exporter-1.10.2.linux-amd64/node_exporter /usr/local/bin/node_exporter

Set executable permissions:

sudo chmod 755 /usr/local/bin/node_exporter

Verify the binary:

/usr/local/bin/node_exporter --version

Step 20: Create the Node Exporter User

Create a dedicated system user for Node Exporter:

sudo useradd --system --no-create-home --shell /bin/false node_exporter

Verify the user:

id node_exporter

Step 21: Create the Node Exporter systemd Service

Create the service:

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

Paste:

[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=node_exporter
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=multi-user.target

Save the file:

  • Press Ctrl + O
  • Press Enter
  • Press Ctrl + X

Step 22: Reload systemd

Tell systemd about the new Prometheus and Node Exporter services:

sudo systemctl daemon-reload

Step 23: Enable Prometheus

Enable Prometheus so it automatically starts when the server boots:

sudo systemctl enable prometheus

Start Prometheus:

sudo systemctl start prometheus

Step 24: Enable Node Exporter

Enable Node Exporter:

sudo systemctl enable node_exporter

Start Node Exporter:

sudo systemctl start node_exporter

Step 25: Check Prometheus Status

Check whether Prometheus is running:

sudo systemctl status prometheus --no-pager

Look for:

Active: active (running)

Step 26: Check Node Exporter Status

Check Node Exporter:

sudo systemctl status node_exporter --no-pager

You should see:

Active: active (running)

Step 27: Check Prometheus Port 9090

The Prometheus web interface listens on port 9090. Check that the port is listening:

sudo ss -tulpn | grep 9090

Test Prometheus from the server:

curl -I http://localhost:9090

A successful response should contain an HTTP 200 status.


Step 28: Check Node Exporter Port 9100

Node Exporter listens on port 9100. Check the port:

sudo ss -tulpn | grep 9100

Test the metrics endpoint:

curl http://localhost:9100/metrics

You should see many lines of Prometheus metric information.


Step 29: Find Your Server IP Address

Run:

hostname -I

Copy the server's IP address.


Step 30: Open Prometheus in Your Browser

From your computer, open a web browser and enter:

http://YOUR_SERVER_IP:9090

For example:

http://203.0.113.10:9090

Replace 203.0.113.10 with your actual server IP.

Success: If the Prometheus web interface opens, Prometheus is accessible.

Step 31: Open the Prometheus Targets Page

Prometheus has a targets page where you can check the monitoring targets:

http://YOUR_SERVER_IP:9090/targets

The configuration supplied in the playbook monitors two targets:

  • Prometheus: localhost:9090
  • Node Exporter: localhost:9100

Both targets should eventually show a healthy status.


Step 32: Open Node Exporter Metrics

Node Exporter exposes its metrics on port 9100. Open:

http://YOUR_SERVER_IP:9100/metrics

For example:

http://203.0.113.10:9100/metrics

The page should contain Prometheus metric information.


Step 33: Configure the Firewall

If UFW is enabled on your Ubuntu server and you need to access Prometheus from another computer, allow port 9090:

sudo ufw allow 9090/tcp

If you also need direct external access to Node Exporter, allow port 9100:

sudo ufw allow 9100/tcp

Reload UFW:

sudo ufw reload

Check the firewall:

sudo ufw status
Security note: Node Exporter exposes server monitoring information. In a production environment, avoid exposing port 9100 publicly unless this is specifically required.

Step 34: Check Prometheus Logs

If Prometheus is not running, check its logs:

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

To follow the logs continuously:

sudo journalctl -u prometheus -f

Press Ctrl + C to stop viewing the logs.


Step 35: Check Node Exporter Logs

Check Node Exporter logs:

sudo journalctl -u node_exporter -n 100 --no-pager

To follow the logs:

sudo journalctl -u node_exporter -f

Press Ctrl + C to stop viewing the logs.


Step 36: Troubleshooting Prometheus

Prometheus is not running

Check the service:

sudo systemctl status prometheus --no-pager -l

Check the logs:

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

Check the configuration:

sudo -u prometheus promtool check config /etc/prometheus/prometheus.yml

Node Exporter is not running

Check:

sudo systemctl status node_exporter --no-pager -l

Then check its logs:

sudo journalctl -u node_exporter -n 100 --no-pager

Prometheus cannot reach Node Exporter

Test Node Exporter directly:

curl http://localhost:9100/metrics

If metrics are returned, check the Prometheus configuration:

sudo cat /etc/prometheus/prometheus.yml

The Node Exporter target should be:

localhost:9100

Step 37: Restart Prometheus

To restart Prometheus:

sudo systemctl restart prometheus

Check the service again:

sudo systemctl status prometheus --no-pager

Step 38: Restart Node Exporter

To restart Node Exporter:

sudo systemctl restart node_exporter

Check the service:

sudo systemctl status node_exporter --no-pager

Step 39: Stop and Start Prometheus

Stop Prometheus:

sudo systemctl stop prometheus

Start it again:

sudo systemctl start prometheus

Step 40: Stop and Start Node Exporter

Stop Node Exporter:

sudo systemctl stop node_exporter

Start it again:

sudo systemctl start node_exporter

Step 41: Final Verification

Run the following commands to perform a final check:

sudo systemctl status prometheus --no-pager

sudo systemctl status node_exporter --no-pager

sudo ss -tulpn | grep -E '9090|9100'

curl -I http://localhost:9090

curl http://localhost:9100/metrics

If both services are running and the ports respond, the Prometheus deployment is operating.


Installation Complete

Congratulations!

Prometheus and Node Exporter have been installed and configured on Ubuntu 24.04.

  • Prometheus 2.55.1 is installed.
  • Node Exporter 1.10.2 is installed.
  • Prometheus runs as the prometheus system user.
  • Node Exporter runs as the node_exporter system user.
  • Prometheus listens on port 9090.
  • Node Exporter listens on port 9100.
  • Prometheus configuration is stored in /etc/prometheus.
  • Prometheus data is stored in /var/lib/prometheus.
  • Both services are managed by systemd.

Configuration Summary

Component Configuration
Operating System Ubuntu 24.04 LTS
Prometheus Version 2.55.1
Prometheus Port 9090
Prometheus Binary /usr/local/bin/prometheus
Promtool Binary /usr/local/bin/promtool
Prometheus Configuration /etc/prometheus/prometheus.yml
Prometheus Data /var/lib/prometheus
Prometheus User prometheus
Node Exporter Version 1.10.2
Node Exporter Binary /usr/local/bin/node_exporter
Node Exporter Port 9100
Node Exporter User node_exporter

Quick Access URLs

Prometheus Web Interface:
http://YOUR_SERVER_IP:9090

Prometheus Targets:
http://YOUR_SERVER_IP:9090/targets

Node Exporter Metrics:
http://YOUR_SERVER_IP:9100/metrics


Important Security Notice

Security Recommendation:

Prometheus and Node Exporter provide information about the server and its resources. Avoid exposing these services directly to the public Internet unless this is required.

Where possible, restrict access to the monitoring ports using firewall rules, a private network, VPN, or another appropriate access-control mechanism.


This knowledgebase article follows the supplied Prometheus Ansible deployment, including Prometheus 2.55.1, Node Exporter 1.10.2, the Prometheus and Node Exporter systemd services, ports 9090 and 9100, the Prometheus configuration directory /etc/prometheus, the data directory /var/lib/prometheus, and the configured Prometheus scrape targets.


Дали Ви помогна овој одговор?
Back