← Start of tutorial

WIUNIX ACADEMY

Build a Prometheus + Grafana monitoring stack

Page 2 of 6. Review the earlier steps and prerequisites before continuing.

YOUR SYSTEM. YOUR STEPS.

Where are you working?

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

Ubuntu 26.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

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/systemd/system/prometheus.service
sudo test ! -L /etc/systemd/system/prometheus.service
sudo nano /etc/systemd/system/prometheus.service
)
How do I know it worked?

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

07

LET’S BUILD

Create the Prometheus systemd service

This service keeps Prometheus under systemd control and stores metrics in /var/lib/prometheus. The web interface is bound to 127.0.0.1:9090 so the host does not publish Prometheus directly to the network by default.

If you later need remote access, expose it through a trusted reverse proxy or a controlled tunnel rather than widening access immediately.

systemd · /etc/systemd/system/prometheus.service

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

[Unit]
Description=Prometheus Monitoring Server
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 \
  --storage.tsdb.retention.time=15d \
  --web.listen-address=127.0.0.1:9090
Restart=on-failure

[Install]
WantedBy=multi-user.target
How do I know it worked?

The systemd unit file exists and matches the Prometheus paths created in the earlier steps.

08

LET’S BUILD

Download and install node_exporter

node_exporter publishes host metrics such as CPU, memory, filesystem and network counters in Prometheus format. The current official download page lists 1.12.1 as the latest release at the review date.

Install only the binary on the monitoring server for now. You will reuse the same pattern on any additional Linux node that you want to monitor later.

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 node_exporter-1.12.1.linux-amd64.tar.gz \
  https://github.com/prometheus/node_exporter/releases/download/v1.12.1/node_exporter-1.12.1.linux-amd64.tar.gz
printf '%s  %s\n' 'b51d8a76aa2a9156a55d501aca6276fae09e262259a5e4e831d2c2222f084e63' 'node_exporter-1.12.1.linux-amd64.tar.gz' | sha256sum --check --strict -
tar -xzf node_exporter-1.12.1.linux-amd64.tar.gz
cd node_exporter-1.12.1.linux-amd64
sudo test ! -e /usr/local/bin/node_exporter
sudo install -o root -g root -m 0755 node_exporter /usr/local/bin/
/usr/local/bin/node_exporter --version
)
How do I know it worked?

SHA256 reports OK before extraction; node_exporter reports 1.12.1. Keep the temporary download directory until validation is complete.

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/systemd/system/node_exporter.service
sudo test ! -L /etc/systemd/system/node_exporter.service
sudo nano /etc/systemd/system/node_exporter.service
)
How do I know it worked?

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

09

LET’S BUILD

Create the node_exporter systemd service

Run the basic host collectors on loopback. The optional systemd collector is omitted because service metrics need additional D-Bus access; host CPU, memory and filesystem metrics do not need it.

systemd · /etc/systemd/system/node_exporter.service

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

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

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter \
  --web.listen-address=127.0.0.1:9100
Restart=on-failure

[Install]
WantedBy=multi-user.target
How do I know it worked?

The node_exporter systemd unit is present and refers to the installed binary path.

Keep the selected host policy enabled

Keep the distribution security policy enabled and inspect the real service context, not only Unix file ownership. These locally installed binaries and hand-written units do not create a dedicated confined SELinux domain. On RPM restore standard path labels before startup, then inspect actual process labels and AVCs if a real service action is denied. Do not disable enforcement or generate an unchecked audit2allow policy.

On Ubuntu/Debian preserve any active AppArmor profiles; on Arch/Manjaro review the policy you installed. A shell invocation as the service user is not proof of access under the systemd service security context.

Bash

Monitoring server · policy inspection

if command -v aa-status >/dev/null; then sudo aa-status; fi
if command -v getenforce >/dev/null; then getenforce; fi
Explore all tutorials ↗