☕ XOPSSCHOOL — LEARNING MADE AFFORDABLE
Build the Skills Your Next Career Move Demands.
For the Price of One Coffee a Month.
Why spend hundreds on individual courses? Unlock an entire year of technical learning with one Coffee Pass.
US$4.90 /month
US$58.80/year
₹499 + GST/month
₹5,988 + GST/year
€4.90 /month
€58.80/year
12 Months of Access • Billed Annually • No Automatic Renewal
DevOps • Cloud • SRE • Kubernetes • Terraform • DevSecOps • AI • AIOps • MLOps • LLMOps • FinOps • GitOps • Platform Engineering & Much More
192
Premium Courses
1,085
Video Sessions
99
Ops Disciplines
86
Tool Courses
340
Assignments
227
Quizzes
✓ QR-Verifiable Certificates   ✓ Learn at Your Own Pace   ✓ Hands-on Learning   ✓ New Courses Included
Learn from real-world, instructor-led video sessions by
Rajesh Kumar
Principal Architect • Trainer • Mentor • 15+ Years of Industry Experience
☕ Get My Coffee Pass — Start Learning Today →
One Payment. Every Premium Course. One Full Year.
The best investment you can make is in the person you are becoming.

How to Run Prometheus server as a Service?

To run Prometheus as a service, create a systemd unit file at /etc/systemd/system/prometheus.service that points to the binary by its absolute path, then reload systemd and enable the unit so it starts at boot and restarts after a crash. This page explains the two unit files in the example above, gives a corrected and hardened version, and adds the missing setup, verification and troubleshooting steps.

Step 1 – Create a file:

$ vi /etc/systemd/system/prometheus.service

Step 2 – Reload the Systemctl Daemon:

$ sudo systemctl daemon-reload

Step 3 – Start the Prometheus service:

$ sudo systemctl start prometheus
$ sudo systemctl status prometheus

What the unit file does

A systemd unit file tells the init system how to run a long-lived process. For Prometheus, the three sections in the example above do the following:

  • [Unit] holds the description and the startup order. After=network-online.target together with Wants=network-online.target makes Prometheus wait until the network is up. After= alone sets the order but doesn't pull the network target in.
  • [Service] says which user runs the process, the exact command line (ExecStart) and the restart policy.
  • [Install] controls what systemctl enable does. WantedBy=multi-user.target starts the service at a normal multi-user boot.

The second unit file in the example above is the better starting point. It runs Prometheus as a dedicated unprivileged user, uses absolute paths and passes an explicit config file. The first one has several problems, listed in the corrections section below.

Prerequisites: binary, user and directories

The unit file expects the binary, the config and the data directory to exist already, owned by the right user. The example above skips this part. On a typical Linux host, run:

# 1. Create a system user with no login shell and no home directory
sudo useradd --system --no-create-home --shell /usr/sbin/nologin prometheus

# 2. Create config and data directories
sudo mkdir -p /etc/prometheus /var/lib/prometheus

# 3. Download and unpack a release (set VERSION to the current release)
VERSION="<x.y.z>"
cd /tmp
curl -LO https://github.com/prometheus/prometheus/releases/download/v${VERSION}/prometheus-${VERSION}.linux-amd64.tar.gz
tar xzf prometheus-${VERSION}.linux-amd64.tar.gz
cd prometheus-${VERSION}.linux-amd64

# 4. Install binaries and the sample config
sudo cp prometheus promtool /usr/local/bin/
sudo cp prometheus.yml /etc/prometheus/

# 5. Set ownership
sudo chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus

# 6. Validate the config before starting
promtool check config /etc/prometheus/prometheus.ymlCode language: PHP (php)

The last command should report SUCCESS for the config file. For a full walkthrough that also installs Node Exporter, see Install and Configure Prometheus Server and Node Exporter in Linux.

A corrected, production-ready unit file

Writing to /etc/systemd/system needs root, so open the file with sudo vi /etc/systemd/system/prometheus.service or sudo systemctl edit --force --full prometheus.service. Then paste:

[Unit]
Description=Prometheus monitoring server
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=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=15d \
    --web.listen-address=0.0.0.0:9090
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=5s
LimitNOFILE=65536

# Hardening
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
ReadWritePaths=/var/lib/prometheus

[Install]
WantedBy=multi-user.targetCode language: PHP (php)
  • ExecStart uses absolute paths only. Systemd does not expand ~ or shell variables the way a login shell does.
  • --config.file is needed. Without it, Prometheus looks for prometheus.yml in its working directory, which is / for a system service.
  • --storage.tsdb.path is where the time series database lives. The service user must be able to write to it.
  • --storage.tsdb.retention.time sets how long samples are kept. 15 days is the default. Set it to match your disk capacity.
  • ExecReload makes systemctl reload prometheus send SIGHUP. That reloads the config without restarting the process or losing in-memory data.
  • LimitNOFILE raises the open-file limit. A TSDB with many series and scrape targets can exceed the default.
  • ProtectSystem=strict makes the whole filesystem read-only for the service. ReadWritePaths then gives back write access to the data directory only.

Note: If you need --web.external-url (for example behind a reverse proxy), set it to the real public URL. A placeholder such as http://myurl.com:9090 breaks links in the UI and in alert notifications.

Enable, start and verify

sudo systemctl daemon-reload
sudo systemctl enable --now prometheus
sudo systemctl status prometheus

enable --now starts the service immediately and also sets it to start at boot. The steps above only run start, so Prometheus would not come back after a reboot. A healthy status output includes a line like:

Active: active (running) since ...Code language: HTTP (http)

Then check the HTTP endpoints and logs:

curl http://localhost:9090/-/healthy
curl http://localhost:9090/-/ready
journalctl -u prometheus -fCode language: JavaScript (javascript)

The health endpoint returns a short text message saying the server is healthy. Open http://<server-ip>:9090/targets in a browser to confirm the targets are UP. To reach the UI from another machine, open port 9090 in the host firewall, for example sudo ufw allow 9090/tcp or sudo firewall-cmd --add-port=9090/tcp --permanent && sudo firewall-cmd --reload.

Day-to-day operations

TaskCommand
Reload config after editing prometheus.ymlpromtool check config /etc/prometheus/prometheus.yml && sudo systemctl reload prometheus
Restart after changing flags in the unit filesudo systemctl daemon-reload && sudo systemctl restart prometheus
Stop the servicesudo systemctl stop prometheus
Disable start at bootsudo systemctl disable prometheus
View recent logsjournalctl -u prometheus --since "1 hour ago"
Override settings without editing the main filesudo systemctl edit prometheus

Note: Always run promtool check config before a reload. If the new config is invalid, Prometheus keeps the old one and logs an error, so a broken edit can go unnoticed.

Common errors and fixes

Symptom in systemctl status or journalctlCauseFix
Unit fails to load with a message about the executable path not being absoluteExecStart uses ~ or a relative pathUse the full path, e.g. /usr/local/bin/prometheus
status=203/EXECBinary missing, wrong path or not executableCheck with ls -l /usr/local/bin/prometheus and chmod +x if needed
status=217/USERThe User= account does not existCreate it with useradd --system as shown above
opening storage failed / permission deniedData directory not writable by the service usersudo chown -R prometheus:prometheus /var/lib/prometheus
Error loading config / couldn't load configurationYAML syntax error or wrong config pathRun promtool check config and check --config.file
address already in useAnother process is using port 9090Find it with sudo ss -ltnp | grep 9090, then stop it or change --web.listen-address
Changes to the unit file have no effectsystemd still has the old definition loadedRun sudo systemctl daemon-reload before restarting

Corrections to the original

  • Tilde in ExecStart. The first unit file uses ExecStart=~/prometheus/prometheus. Systemd needs an absolute path to the executable. Install the binary to a fixed location such as /usr/local/bin and point to it there.
  • Running as root. The first unit file sets User=root. Prometheus doesn't need root privileges. Use a dedicated prometheus system user.
  • Missing config flag. The first unit file doesn't pass --config.file, so Prometheus looks for prometheus.yml in / and fails. Pass the config path explicitly.
  • Missing Wants= line. The first unit file has After=network-online.target without Wants=network-online.target, so the network target may not be pulled in at all.
  • Console flags on Prometheus 3.x. The second unit file points --web.console.templates and --web.console.libraries at directories that Prometheus 3.x release archives no longer include. Remove these flags unless you have your own console templates in place.
  • Missing sudo. The file is created without sudo, but writing to /etc/systemd/system needs root.
  • Not enabled at boot. The steps never run systemctl enable, so the service would not start after a reboot.
  • Wrong file extension. The gist files are named .sh, but they are systemd unit files, not shell scripts. Save the file as prometheus.service.

For more on the Prometheus server itself, see the Prometheus tutorials or start writing queries with the PromQL Node Exporter examples.

Frequently asked questions

Where should the Prometheus systemd service file be placed?

Put custom unit files in /etc/systemd/system/prometheus.service. Files under /lib/systemd/system or /usr/lib/systemd/system belong to distribution packages and can be overwritten on upgrade.

Why does Prometheus fail to start with status=203/EXEC?

Systemd could not run the binary named in ExecStart. Usually the path is wrong, relative or uses ~, or the file isn't executable. Use an absolute path such as /usr/local/bin/prometheus and check its permissions.

How do I reload the Prometheus configuration without restarting?

Add ExecReload=/bin/kill -HUP $MAINPID to the unit file and run sudo systemctl reload prometheus. You can also start Prometheus with --web.enable-lifecycle and send curl -X POST http://localhost:9090/-/reload, but only if the endpoint is not exposed to untrusted networks.

Should Prometheus run as root?

No. Prometheus only needs to read its config and write to its data directory. Run it as a dedicated system user with no login shell, and limit filesystem access with options such as ProtectSystem=strict and ReadWritePaths.

How do I make Prometheus start automatically after a reboot?

Run sudo systemctl enable prometheus, or sudo systemctl enable --now prometheus to also start it right away. This links the unit into multi-user.target through its WantedBy= setting.

Related tutorials

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals

Related Posts

Elastic Agent Commands Reference

Elastic Agent runs as an operating system service, so you start and stop it with systemd on Linux, launchd on macOS and the Service Control Manager on…

Read More

Jira on Linux: Installation and Configuration with Safer Service and Firewall Setup

Learn how to install Jira on Linux using Atlassian’s installer, manage it as a service, and expose port 8080 safely. This revision keeps the original references but updates the process for clearer, production-minded operations.

Read More

MySQL Basic Troubleshooting Guide: Service, Port 3306, Logs, and Crash Repair

This Linux-first runbook helps you troubleshoot common MySQL issues quickly, from startup failures to port conflicts and slow performance. You will learn practical checks for service health, configuration, logging, and table repair.

Read More

RHCSA EX200 Self-Study Curriculum and Hands-On Lab Manual

Gold-standard home-study roadmap for the Red Hat Certified System Administrator (RHCSA) exam EX200 Research cut-off: 2026-10-06 Primary authority: current official Red Hat EX200 page, Red Hat Certification…

Read More

Linux Administrator: Role Blueprint, Responsibilities, Skills, KPIs, and Career Path

The Linux Administrator is responsible for the reliability, security, and day-to-day operational health of Linux-based infrastructure that supports enterprise applications, internal developer platforms, and shared IT services. This role ensures Linux systems are consistently configured, patched, monitored, backed up, and recoverable—while meeting organizational standards for availability, performance, and compliance.

Read More

Docker Tutorials: Docker Cgroup Drivers – Complete Guide

Introduction Docker uses cgroups (control groups) to manage resource constraints like CPU, memory, and I/O for containers. These cgroups are orchestrated through cgroup drivers that act as…

Read More