Illustrative WIUNIX Academy IT engineering workspace with server/network equipment and an instructional board: Build a Prometheus + Grafana monitoring stack

WIUNIX ACADEMY

Build a Prometheus + Grafana monitoring stack

Install Prometheus, node_exporter and Grafana with private access, validated configuration and checks that prove metrics reach your dashboard.

Intermediate70 min readUpdated
Make this guide yours

YOUR SYSTEM. YOUR STEPS.

Where are you working?

Choose your OS and version. The prerequisites, commands and troubleshooting follow your environment.

Ubuntu 22.04 LTSReviewed against official documentation ·

USE YOUR OWN VALUES

Configure this tutorial

Set the example values for your environment; related explanations and copy panels update together. Never enter passwords, private keys or tokens. Values stay in this tab and are not sent to the server or share links. Check actual DNS, certificates and network policy before running commands.

Different IP addresses, domains or ports? Open the settings below, change the values and select “Apply to tutorial”, then copy the updated commands.

Set values for my environment2 editable values

THE OUTCOME

What will you have at the end?

Build a self-hosted monitoring stack that stores local system metrics in Prometheus, visualizes them in Grafana and leaves you with a clean path for adding more Linux nodes later.

01Linux nodesRun node_exporter to expose host metrics in Prometheus format.
02Prometheus serverScrapes targets on a schedule and stores time-series data locally.
03GrafanaUses Prometheus as a data source and renders dashboards.
04Browser accessAdministrators sign in to Grafana and explore metrics visually.
05Future growthAdd more exporters and alerting later without redesigning the base stack.
Supported operating systems and versions

Fourteen environment paths reviewed against official documentation on 2026-11-05, retaining Ubuntu 22.04. No fresh VM or complete installation matrix was run. Historical isolated Ubuntu 22.04.5 container checks used Prometheus 3.15.0, node_exporter 1.12.1 and Grafana 13.2.4; they do not test APT/systemd or this new Prometheus version. Arch/Manjaro uses distribution community packages, not a Grafana vendor-supported OS. Photographs and sample outputs are illustrative.

Before you begin

  • A fresh disposable x86_64 systemd VM on the selected distribution, sudo, internet and at least 2 GB RAM plus 10 GB free disk for this small lab. Size real deployments for active series, scrape volume and retention.
  • An existing SSH account and SSH client on your workstation. All three HTTP listeners stay on loopback; Grafana is accessed through an SSH local forward.
  • For the optional remote node: a trusted private network and an already active UFW firewall with default deny incoming, or equivalent managed network rules. Do not enable a new firewall blindly over SSH.
01

LET’S BUILD

Confirm the host role and the monitoring scope

Prometheus stores metrics, node_exporter exposes the local host counters, and Grafana queries Prometheus. These commands target a fresh amd64 systemd host, not an existing monitoring installation.

Reserve local ports 3000, 9090 and 9100. Keep them off the public network. The Grafana login and password change will travel through your existing encrypted SSH connection.

Bash

Monitoring server terminal. Commands that begin with sudo need administrative privileges.

hostnamectl
hostname -I
uname -m
sudo ss -lntup
How do I know it worked?

You can identify the host, see its IP addresses, confirm the architecture, and verify that port 3000 is available while local ports 9090 and 9100 are not already reserved by another monitoring stack.

02

LET’S BUILD

Refuse retained state before installing

Use this once on the disposable monitoring VM before any installation. Existing accounts, data, configuration, binaries, units or masks stop the guide; never delete them to pass. Grafana is masked before package scripts can start it. If installation later fails, retain this lab mask until configuration is ready or retire the VM.

Bash

Fresh monitoring VM only · sudo

sudo bash <<'ROOT'
set -euo pipefail
test "$(uname -m)" = x86_64
test "$(ps -p 1 -o comm= | tr -d ' ')" = systemd
for path in /etc/prometheus /var/lib/prometheus /etc/grafana /etc/grafana.ini /var/lib/grafana /usr/local/bin/prometheus /usr/local/bin/promtool /usr/local/bin/node_exporter /etc/systemd/system/prometheus.service /etc/systemd/system/node_exporter.service /etc/systemd/system/grafana-server.service.d /etc/systemd/system/grafana.service.d /etc/apt/keyrings/grafana.asc /etc/apt/sources.list.d/grafana.list /etc/yum.repos.d/grafana.repo; do
  if test -e "$path" || test -L "$path"; then echo "STOP: existing state $path" >&2; exit 1; fi
done
for account in prometheus node_exporter grafana; do
  if getent passwd "$account" >/dev/null || getent group "$account" >/dev/null; then echo "STOP: existing identity $account" >&2; exit 1; fi
done
for unit in prometheus node_exporter grafana-server grafana; do
  test "$(systemctl show "$unit" -p LoadState --value)" = not-found || { echo "STOP: existing unit $unit" >&2; exit 1; }
done
systemctl mask grafana-server.service
ROOT
How do I know it worked?

No existing installation found; this lab owns a new Grafana service mask.

03

LET’S BUILD

Install the base packages

Install the download, JSON, archive and editor tools used below. SHA256 checks use coreutils, already part of these systems. Grafana will use its signed official APT repository.

Bash

Monitoring server terminal.

(
set -euo pipefail
sudo apt-get update
sudo apt-get install -y curl tar adduser ca-certificates gnupg apt-transport-https jq nano
)
How do I know it worked?

APT completes without dependency errors and the host now has the tools required to download Prometheus, node_exporter and the Grafana repository key.

04

LET’S BUILD

Create service accounts and directories

Use dedicated system users and separate directories so binaries, configuration and time-series data remain organized. Prometheus needs a writable data directory, while node_exporter only needs its binary and a system account.

The directory layout below matches the later systemd services and keeps ownership explicit.

Bash

Monitoring server terminal.

(
set -euo pipefail
sudo useradd --system --user-group --no-create-home --home-dir /nonexistent --shell /usr/sbin/nologin prometheus
sudo useradd --system --user-group --no-create-home --home-dir /nonexistent --shell /usr/sbin/nologin node_exporter
sudo install -d -o root -g prometheus -m 0750 /etc/prometheus
sudo install -d -o prometheus -g prometheus -m 0750 /var/lib/prometheus
)
How do I know it worked?

Configuration remains root-owned and readable by the Prometheus group; only the data directory is service-writable.

05

LET’S BUILD

Download and install Prometheus

The official page reviewed on 2026-11-05 lists stable Prometheus 3.15.1 and LTS 3.13.5; 3.16 is a release candidate and is not selected. This guide pins the official linux-amd64 SHA256 for 3.15.1. Stop on download or checksum failure before extraction or installation.

Install only prometheus and promtool. Prometheus 3 archives no longer include the old consoles and console_libraries directories. Keep the unique download directory until validation is complete.

Bash

Monitoring server terminal.

(
set -euo pipefail
umask 022
[ "$(uname -m)" = x86_64 ] || { echo 'This download requires amd64/x86_64' >&2; exit 1; }
work=$(mktemp -d)
cd "$work"
curl --noproxy '*' -fL --connect-timeout 10 --max-time 180 -o prometheus-3.15.1.linux-amd64.tar.gz \
  https://github.com/prometheus/prometheus/releases/download/v3.15.1/prometheus-3.15.1.linux-amd64.tar.gz
printf '%s  %s\n' '6a726885328ad9efebbf36e876ce2fb6225468a71fd1e7ce3ba666d5f4d97a84' 'prometheus-3.15.1.linux-amd64.tar.gz' | sha256sum --check --strict -
tar -xzf prometheus-3.15.1.linux-amd64.tar.gz
cd prometheus-3.15.1.linux-amd64
sudo test ! -e /usr/local/bin/prometheus
sudo test ! -e /usr/local/bin/promtool
sudo install -o root -g root -m 0755 prometheus promtool /usr/local/bin/
/usr/local/bin/prometheus --version
)
How do I know it worked?

Official SHA256 check passes before extraction; the installed absolute-path binary reports 3.15.1.

Open the next configuration file

Open the file, paste the contents in the following panel, then save and exit (nano: Ctrl+O, Enter, Ctrl+X). Do not run file contents as shell commands.

Bash

Monitoring server terminal.

(
set -euo pipefail
sudo test ! -e /etc/prometheus/prometheus.yml
sudo test ! -L /etc/prometheus/prometheus.yml
sudo nano /etc/prometheus/prometheus.yml
)
How do I know it worked?

The command completes successfully; stop and inspect any error before continuing.

06

LET’S BUILD

Write the Prometheus configuration

Start with a compact configuration that scrapes Prometheus itself and the local node_exporter endpoint every 15 seconds. This is enough to prove the stack works before you add remote servers or alerting later.

Create the file exactly as shown and keep the targets on localhost for this first node.

YAML · /etc/prometheus/prometheus.yml

File contents; save in the named file, not in the shell.

global:
  scrape_interval: 15s
  evaluation_interval: 15s

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets:
          - 127.0.0.1:9090

  - job_name: node-exporter
    static_configs:
      - targets:
          - 127.0.0.1:9100
How do I know it worked?

The Prometheus configuration file contains two scrape jobs and is ready for validation by the service start-up step.

Explore all tutorials ↗