The apt package for Prometheus on Ubuntu lags the upstream by a major version and ships defaults that are wrong for a long-lived install — five-day retention, no flag for an external URL, a service unit that drops you in /var/lib/prometheus with permissions you do not want. This article walks through a reproducible install of the upstream binary on Ubuntu 24.04 LTS, with the systemd unit, retention, and reverse-proxy fronting we use in the engagements we run.
How to verify
After the install, every check below should pass on a fresh box before you point anything at it.
systemctl status prometheus --no-pager
ss -lntp | grep 9090
curl -fsS http://127.0.0.1:9090/-/ready && echo
curl -fsS http://127.0.0.1:9090/-/healthy && echo
curl -fsS http://127.0.0.1:9090/api/v1/status/runtimeinfo | jq '{GOMAXPROCS, storageRetention}'
curl -fsS http://127.0.0.1:9090/api/v1/status/config | jq -r '.data.yaml' | head -20
journalctl -u prometheus --since "10 min ago" | grep -Ei 'err|warn' || echo 'no errors'
storageRetention should match what you set (default 15d). If the /api/v1/status/config output does not show your scrape_configs, the config in /etc/prometheus is not the one Prometheus loaded — check systemctl cat prometheus for the --config.file flag.
What’s happening
Prometheus is a single Go binary that scrapes HTTP endpoints exposing metrics in its text format, stores them in a local TSDB block under --storage.tsdb.path, and serves a query API on port 9090. There are no agents, no message queues, no external dependencies — which is the appeal, and also the part operators most often misconfigure. The two failure modes worth installing carefully against are: (1) the TSDB grows until it fills the disk, because nobody set a retention; (2) the API is bound to 0.0.0.0 with no auth, exposing query and admin endpoints to anyone who can reach the box.
The install we describe here addresses both: a --storage.tsdb.retention.time flag that bounds disk use, and a reverse proxy on Nginx that terminates TLS and adds basic auth or mTLS in front of port 9090. Internally, Prometheus listens on 127.0.0.1:9090 and nothing else.
The procedure
-
Create the system user, no shell, no home.
sudo useradd --system --no-create-home --shell /usr/sbin/nologin prometheus sudo mkdir -p /etc/prometheus /var/lib/prometheus sudo chown prometheus:prometheus /var/lib/prometheus -
Download the upstream tarball. Check the latest release tag at github.com/prometheus/prometheus/releases; pin it explicitly rather than tracking
latest.PROM_VERSION="2.55.1" cd /tmp curl -fLO "https://github.com/prometheus/prometheus/releases/download/v${PROM_VERSION}/prometheus-${PROM_VERSION}.linux-amd64.tar.gz" tar xzf prometheus-${PROM_VERSION}.linux-amd64.tar.gz cd prometheus-${PROM_VERSION}.linux-amd64 sudo install -m 0755 prometheus /usr/local/bin/prometheus sudo install -m 0755 promtool /usr/local/bin/promtool sudo cp -r consoles console_libraries /etc/prometheus/ sudo chown -R prometheus:prometheus /etc/prometheus -
Write the initial config. Keep this minimal — the goal is to verify the daemon, not to scrape everything yet.
# /etc/prometheus/prometheus.yml global: scrape_interval: 15s evaluation_interval: 15s external_labels: cluster: 'prod-01' replica: 'A' scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['127.0.0.1:9090']Validate before touching the daemon:
promtool check config /etc/prometheus/prometheus.yml. A bad config will refuse to load and leave you with a stale running process — catch it here. -
Write the systemd unit. Bind to localhost; let the reverse proxy expose it.
# /etc/systemd/system/prometheus.service [Unit] Description=Prometheus After=network-online.target Wants=network-online.target [Service] Type=simple User=prometheus Group=prometheus ExecStart=/usr/local/bin/prometheus \ --config.file=/etc/prometheus/prometheus.yml \ --storage.tsdb.path=/var/lib/prometheus \ --storage.tsdb.retention.time=30d \ --storage.tsdb.retention.size=50GB \ --web.listen-address=127.0.0.1:9090 \ --web.external-url=https://prom.example.com \ --web.enable-lifecycle \ --log.level=info ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure RestartSec=5s LimitNOFILE=65536 NoNewPrivileges=true ProtectSystem=full ProtectHome=true ReadWritePaths=/var/lib/prometheus [Install] WantedBy=multi-user.target--web.enable-lifecycleenablesPOST /-/reload, so config changes do not require a restart. Reload it only over the proxy, never over a bind on0.0.0.0. -
Front it with Nginx + basic auth. Generate an htpasswd file and a server block on port 443; the proxy passes to
127.0.0.1:9090and Prometheus never sees the public IP.server { listen 443 ssl http2; server_name prom.example.com; ssl_certificate /etc/letsencrypt/live/prom.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/prom.example.com/privkey.pem; auth_basic "prometheus"; auth_basic_user_file /etc/nginx/htpasswd.prom; location / { proxy_pass http://127.0.0.1:9090; proxy_set_header Host $host; } } -
Start, enable, and check.
sudo systemctl daemon-reload && sudo systemctl enable --now prometheus. Then run the verification block at the top of this article. The targets page athttps://prom.example.com/targetsshould showprometheusasUPwith a recent scrape timestamp.
Common pitfalls
- Forgetting
--storage.tsdb.retention.time— the default is 15 days but the flag also takes a size limit; set both to prevent a runaway scrape from filling the disk. - Running Prometheus as root because the systemd unit was copied without changing
User=; the binary does not need root. - Reloading config via
kill -HUPon a process bound to 0.0.0.0; if the bind is wrong, the reload path is wrong too. - Editing
/etc/prometheus/prometheus.ymlwithout runningpromtool check configfirst — a bad file silently keeps the old in-memory config until the next restart. - Using
latestin the download URL; pin the version so a re-run of the install script is reproducible.
For the install steps that come after — node exporters, alerting rules, federation — see prometheus-node-exporter and prometheus-alerting-rules.
Stack Harbor runs Prometheus this way for clients as the backbone of the managed operations tier — pinned binaries, audited systemd units, retention and disk budgets tied to a real runbook rather than upstream defaults.