{"id":23913,"date":"2026-12-06T22:06:03","date_gmt":"2026-12-06T22:06:03","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=23913"},"modified":"2026-12-06T22:06:03","modified_gmt":"2026-12-06T22:06:03","slug":"how-to-run-prometheus-server-as-a-service","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/how-to-run-prometheus-server-as-a-service\/","title":{"rendered":"How to Run Prometheus server as a Service?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1 &#8211; Create a file:<\/h2>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">$ vi \/etc\/systemd\/system\/prometheus.service<\/code><\/span><\/pre>\n\n\n<script src=\"https:\/\/gist.github.com\/devops-school\/e1d541b9ab84c7ea928ab5e7664fdd1d.js\"><\/script>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2 &#8211; Reload the Systemctl Daemon:<\/h2>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">$ sudo systemctl daemon-reload\r\n<\/code><\/span><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Step 3 &#8211; Start the Prometheus service:<\/h2>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">$ sudo systemctl start prometheus\r\n$ sudo systemctl status prometheus<\/code><\/span><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">What the unit file does<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>[Unit]<\/strong> holds the description and the startup order. <code>After=network-online.target<\/code> together with <code>Wants=network-online.target<\/code> makes Prometheus wait until the network is up. <code>After=<\/code> alone sets the order but doesn&#039;t pull the network target in.<\/li>\n\n\n<li><strong>[Service]<\/strong> says which user runs the process, the exact command line (<code>ExecStart<\/code>) and the restart policy.<\/li>\n\n\n<li><strong>[Install]<\/strong> controls what <code>systemctl enable<\/code> does. <code>WantedBy=multi-user.target<\/code> starts the service at a normal multi-user boot.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites: binary, user and directories<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># 1. Create a system user with no login shell and no home directory<\/span>\nsudo useradd --system --no-create-home --shell \/usr\/sbin\/nologin prometheus\n\n<span class=\"hljs-comment\"># 2. Create config and data directories<\/span>\nsudo mkdir -p \/etc\/prometheus \/<span class=\"hljs-keyword\">var<\/span>\/lib\/prometheus\n\n<span class=\"hljs-comment\"># 3. Download and unpack a release (set VERSION to the current release)<\/span>\nVERSION=<span class=\"hljs-string\">\"&lt;x.y.z&gt;\"<\/span>\ncd \/tmp\ncurl -LO https:<span class=\"hljs-comment\">\/\/github.com\/prometheus\/prometheus\/releases\/download\/v${VERSION}\/prometheus-${VERSION}.linux-amd64.tar.gz<\/span>\ntar xzf prometheus-${VERSION}.linux-amd64.tar.gz\ncd prometheus-${VERSION}.linux-amd64\n\n<span class=\"hljs-comment\"># 4. Install binaries and the sample config<\/span>\nsudo cp prometheus promtool \/usr\/local\/bin\/\nsudo cp prometheus.yml \/etc\/prometheus\/\n\n<span class=\"hljs-comment\"># 5. Set ownership<\/span>\nsudo chown -R prometheus:prometheus \/etc\/prometheus \/<span class=\"hljs-keyword\">var<\/span>\/lib\/prometheus\n\n<span class=\"hljs-comment\"># 6. Validate the config before starting<\/span>\npromtool check config \/etc\/prometheus\/prometheus.yml<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The last command should report <code>SUCCESS<\/code> for the config file. For a full walkthrough that also installs Node Exporter, see <a href=\"https:\/\/www.devopsschool.com\/blog\/install-and-configure-prometheus-server-and-node-exporter-in-rhel\/\">Install and Configure Prometheus Server and Node Exporter in Linux<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A corrected, production-ready unit file<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Writing to <code>\/etc\/systemd\/system<\/code> needs root, so open the file with <code>sudo vi \/etc\/systemd\/system\/prometheus.service<\/code> or <code>sudo systemctl edit --force --full prometheus.service<\/code>. Then paste:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">&#91;Unit]\nDescription=Prometheus monitoring server\nDocumentation=https:<span class=\"hljs-comment\">\/\/prometheus.io\/docs\/introduction\/overview\/<\/span>\nWants=network-online.target\nAfter=network-online.target\n\n&#91;Service]\nType=simple\nUser=prometheus\nGroup=prometheus\nExecStart=\/usr\/local\/bin\/prometheus \\\n    --config.file=\/etc\/prometheus\/prometheus.yml \\\n    --storage.tsdb.path=\/<span class=\"hljs-keyword\">var<\/span>\/lib\/prometheus\/ \\\n    --storage.tsdb.retention.time=<span class=\"hljs-number\">15<\/span>d \\\n    --web.listen-address=<span class=\"hljs-number\">0.0<\/span><span class=\"hljs-number\">.0<\/span><span class=\"hljs-number\">.0<\/span>:<span class=\"hljs-number\">9090<\/span>\nExecReload=\/bin\/kill -HUP $MAINPID\nRestart=on-failure\nRestartSec=<span class=\"hljs-number\">5<\/span>s\nLimitNOFILE=<span class=\"hljs-number\">65536<\/span>\n\n<span class=\"hljs-comment\"># Hardening<\/span>\nNoNewPrivileges=<span class=\"hljs-keyword\">true<\/span>\nProtectSystem=strict\nProtectHome=<span class=\"hljs-keyword\">true<\/span>\nPrivateTmp=<span class=\"hljs-keyword\">true<\/span>\nReadWritePaths=\/<span class=\"hljs-keyword\">var<\/span>\/lib\/prometheus\n\n&#91;Install]\nWantedBy=multi-user.target<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<ul class=\"wp-block-list\">\n<li><code>ExecStart<\/code> uses absolute paths only. Systemd does not expand <code>~<\/code> or shell variables the way a login shell does.<\/li>\n\n\n<li><code>--config.file<\/code> is needed. Without it, Prometheus looks for <code>prometheus.yml<\/code> in its working directory, which is <code>\/<\/code> for a system service.<\/li>\n\n\n<li><code>--storage.tsdb.path<\/code> is where the time series database lives. The service user must be able to write to it.<\/li>\n\n\n<li><code>--storage.tsdb.retention.time<\/code> sets how long samples are kept. 15 days is the default. Set it to match your disk capacity.<\/li>\n\n\n<li><code>ExecReload<\/code> makes <code>systemctl reload prometheus<\/code> send SIGHUP. That reloads the config without restarting the process or losing in-memory data.<\/li>\n\n\n<li><code>LimitNOFILE<\/code> raises the open-file limit. A TSDB with many series and scrape targets can exceed the default.<\/li>\n\n\n<li><code>ProtectSystem=strict<\/code> makes the whole filesystem read-only for the service. <code>ReadWritePaths<\/code> then gives back write access to the data directory only.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> If you need <code>--web.external-url<\/code> (for example behind a reverse proxy), set it to the real public URL. A placeholder such as <code>http:\/\/myurl.com:9090<\/code> breaks links in the UI and in alert notifications.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Enable, start and verify<\/h2>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">sudo systemctl daemon-reload\nsudo systemctl enable --now prometheus\nsudo systemctl status prometheus<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><code>enable --now<\/code> starts the service immediately and also sets it to start at boot. The steps above only run <code>start<\/code>, so Prometheus would not come back after a reboot. A healthy status output includes a line like:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"HTTP\" data-shcb-language-slug=\"http\"><span><code class=\"hljs language-http\"><span class=\"hljs-attribute\">Active<\/span>: active (running) since ...<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTTP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">http<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Then check the HTTP endpoints and logs:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">curl http:<span class=\"hljs-comment\">\/\/localhost:9090\/-\/healthy<\/span>\ncurl http:<span class=\"hljs-comment\">\/\/localhost:9090\/-\/ready<\/span>\njournalctl -u prometheus -f<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The health endpoint returns a short text message saying the server is healthy. Open <code>http:\/\/&lt;server-ip&gt;:9090\/targets<\/code> in a browser to confirm the targets are <code>UP<\/code>. To reach the UI from another machine, open port 9090 in the host firewall, for example <code>sudo ufw allow 9090\/tcp<\/code> or <code>sudo firewall-cmd --add-port=9090\/tcp --permanent &amp;&amp; sudo firewall-cmd --reload<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Day-to-day operations<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Task<\/th><th>Command<\/th><\/tr><\/thead><tbody><tr><td>Reload config after editing prometheus.yml<\/td><td><code>promtool check config \/etc\/prometheus\/prometheus.yml &amp;&amp; sudo systemctl reload prometheus<\/code><\/td><\/tr><tr><td>Restart after changing flags in the unit file<\/td><td><code>sudo systemctl daemon-reload &amp;&amp; sudo systemctl restart prometheus<\/code><\/td><\/tr><tr><td>Stop the service<\/td><td><code>sudo systemctl stop prometheus<\/code><\/td><\/tr><tr><td>Disable start at boot<\/td><td><code>sudo systemctl disable prometheus<\/code><\/td><\/tr><tr><td>View recent logs<\/td><td><code>journalctl -u prometheus --since &quot;1 hour ago&quot;<\/code><\/td><\/tr><tr><td>Override settings without editing the main file<\/td><td><code>sudo systemctl edit prometheus<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> Always run <code>promtool check config<\/code> 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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common errors and fixes<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Symptom in systemctl status or journalctl<\/th><th>Cause<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td>Unit fails to load with a message about the executable path not being absolute<\/td><td><code>ExecStart<\/code> uses <code>~<\/code> or a relative path<\/td><td>Use the full path, e.g. <code>\/usr\/local\/bin\/prometheus<\/code><\/td><\/tr><tr><td><code>status=203\/EXEC<\/code><\/td><td>Binary missing, wrong path or not executable<\/td><td>Check with <code>ls -l \/usr\/local\/bin\/prometheus<\/code> and <code>chmod +x<\/code> if needed<\/td><\/tr><tr><td><code>status=217\/USER<\/code><\/td><td>The <code>User=<\/code> account does not exist<\/td><td>Create it with <code>useradd --system<\/code> as shown above<\/td><\/tr><tr><td><code>opening storage failed<\/code> \/ <code>permission denied<\/code><\/td><td>Data directory not writable by the service user<\/td><td><code>sudo chown -R prometheus:prometheus \/var\/lib\/prometheus<\/code><\/td><\/tr><tr><td><code>Error loading config<\/code> \/ <code>couldn&#039;t load configuration<\/code><\/td><td>YAML syntax error or wrong config path<\/td><td>Run <code>promtool check config<\/code> and check <code>--config.file<\/code><\/td><\/tr><tr><td><code>address already in use<\/code><\/td><td>Another process is using port 9090<\/td><td>Find it with <code>sudo ss -ltnp | grep 9090<\/code>, then stop it or change <code>--web.listen-address<\/code><\/td><\/tr><tr><td>Changes to the unit file have no effect<\/td><td>systemd still has the old definition loaded<\/td><td>Run <code>sudo systemctl daemon-reload<\/code> before restarting<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Corrections to the original<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Tilde in ExecStart.<\/strong> The first unit file uses <code>ExecStart=~\/prometheus\/prometheus<\/code>. Systemd needs an absolute path to the executable. Install the binary to a fixed location such as <code>\/usr\/local\/bin<\/code> and point to it there.<\/li>\n\n\n<li><strong>Running as root.<\/strong> The first unit file sets <code>User=root<\/code>. Prometheus doesn&#039;t need root privileges. Use a dedicated <code>prometheus<\/code> system user.<\/li>\n\n\n<li><strong>Missing config flag.<\/strong> The first unit file doesn&#039;t pass <code>--config.file<\/code>, so Prometheus looks for <code>prometheus.yml<\/code> in <code>\/<\/code> and fails. Pass the config path explicitly.<\/li>\n\n\n<li><strong>Missing Wants= line.<\/strong> The first unit file has <code>After=network-online.target<\/code> without <code>Wants=network-online.target<\/code>, so the network target may not be pulled in at all.<\/li>\n\n\n<li><strong>Console flags on Prometheus 3.x.<\/strong> The second unit file points <code>--web.console.templates<\/code> and <code>--web.console.libraries<\/code> at directories that Prometheus 3.x release archives no longer include. Remove these flags unless you have your own console templates in place.<\/li>\n\n\n<li><strong>Missing sudo.<\/strong> The file is created without <code>sudo<\/code>, but writing to <code>\/etc\/systemd\/system<\/code> needs root.<\/li>\n\n\n<li><strong>Not enabled at boot.<\/strong> The steps never run <code>systemctl enable<\/code>, so the service would not start after a reboot.<\/li>\n\n\n<li><strong>Wrong file extension.<\/strong> The gist files are named <code>.sh<\/code>, but they are systemd unit files, not shell scripts. Save the file as <code>prometheus.service<\/code>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For more on the Prometheus server itself, see the <a href=\"https:\/\/www.devopsschool.com\/blog\/category\/monitoring-observability\/prometheus\/\">Prometheus tutorials<\/a> or start writing queries with the <a href=\"https:\/\/www.devopsschool.com\/blog\/prometheus-promql-example-query-node-exporter\/\">PromQL Node Exporter examples<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Where should the Prometheus systemd service file be placed?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Put custom unit files in <code>\/etc\/systemd\/system\/prometheus.service<\/code>. Files under <code>\/lib\/systemd\/system<\/code> or <code>\/usr\/lib\/systemd\/system<\/code> belong to distribution packages and can be overwritten on upgrade.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why does Prometheus fail to start with status=203\/EXEC?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Systemd could not run the binary named in <code>ExecStart<\/code>. Usually the path is wrong, relative or uses <code>~<\/code>, or the file isn&#039;t executable. Use an absolute path such as <code>\/usr\/local\/bin\/prometheus<\/code> and check its permissions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I reload the Prometheus configuration without restarting?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Add <code>ExecReload=\/bin\/kill -HUP $MAINPID<\/code> to the unit file and run <code>sudo systemctl reload prometheus<\/code>. You can also start Prometheus with <code>--web.enable-lifecycle<\/code> and send <code>curl -X POST http:\/\/localhost:9090\/-\/reload<\/code>, but only if the endpoint is not exposed to untrusted networks.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Should Prometheus run as root?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">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 <code>ProtectSystem=strict<\/code> and <code>ReadWritePaths<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I make Prometheus start automatically after a reboot?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run <code>sudo systemctl enable prometheus<\/code>, or <code>sudo systemctl enable --now prometheus<\/code> to also start it right away. This links the unit into <code>multi-user.target<\/code> through its <code>WantedBy=<\/code> setting.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related tutorials<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/install-and-configure-prometheus-server-and-node-exporter-in-rhel\/\">Install and Configure Prometheus Server and Node Exporter in Linux<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/category\/monitoring-observability\/prometheus\/\">More Prometheus tutorials<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/prometheus-promql-example-query-node-exporter\/\">Prometheus PromQL Example Query: node exporter<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/what-is-prometheus-and-use-cases-of-prometheus\/\">What is Prometheus and use cases of Prometheus?<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5013],"tags":[5160],"class_list":["post-23913","post","type-post","status-publish","format-standard","hentry","category-prometheus","tag-systemd"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/23913","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=23913"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/23913\/revisions"}],"predecessor-version":[{"id":80709,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/23913\/revisions\/80709"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=23913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=23913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=23913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}