- It runs in the foreground, so closing your terminal stops the process.
- It won’t start automatically after a system reboot.
systemctl, and starts automatically at boot.
Overview
High-level steps:- Create a dedicated, non-login
prometheususer. - Create directories for configuration and TSDB storage.
- Download and extract Prometheus.
- Install binaries and CLI tools to
/usr/local/bin. - Copy consoles, libraries, and the config file into
/etc/prometheus. - Test a manual run as the
prometheususer. - Create a systemd unit file.
- Reload systemd, start, and enable the service.
1) Create a Prometheus user
Create a dedicated system user that cannot log in interactively:Using a dedicated, non-login user reduces risk by limiting file access and attack surface for the Prometheus process.
2) Create directories for configuration and data
Create paths for Prometheus configuration and time-series data, then set ownership to theprometheus user and group:
/etc for configuration and /var/lib for persistent service data.
3) Download and extract Prometheus
Download the Prometheus release tarball (example uses v2.37.0). Change the version string as required for newer releases:4) Install binaries and CLI tools
Copy the Prometheus binary and thepromtool utility into /usr/local/bin and set ownership and permissions:
/usr/local/bin keeps system-managed binaries separate from distribution packages.
5) Install console templates, libraries, and the config file
Copy theconsoles and console_libraries directories plus your prometheus.yml into /etc/prometheus, then ensure the prometheus user owns them:
consoles and console_libraries are used by the web-based Prometheus console (optional for basic scraping/storage).
6) Manual test run as the prometheus user
Before creating the systemd unit, verify Prometheus runs correctly as theprometheus user. This is the same command the systemd unit will use:
7) Create a systemd unit file
Create the unit file at/etc/systemd/system/prometheus.service:
The unit ensures Prometheus starts after the network is up and runs with the least privileges.
8) Reload systemd, start, and enable Prometheus
After creating or changing a unit file, reload systemd and then start and enable the service:systemctl status should report the unit as active (running) and enabled.
If you update
/etc/prometheus/prometheus.yml, reload the service to apply changes:
sudo systemctl restart prometheus. For configuration checks, use promtool check config /etc/prometheus/prometheus.yml.Troubleshooting tips
- Verify permissions: ensure
/etc/prometheusand/var/lib/prometheusare owned byprometheus:prometheus. - Check logs:
sudo journalctl -u prometheus -fshows real-time unit logs. - Port conflicts: if 9090 is already used, change
--web.listen-addressin the unit or config to a different port.
Links and references
- Prometheus official releases and binaries: https://github.com/prometheus/prometheus/releases
- Prometheus documentation: https://prometheus.io/docs/
- systemd service unit documentation: https://www.freedesktop.org/wiki/Software/systemd/Documentation/
systemctl and configured to start automatically at boot.