{"id":932,"date":"2020-10-20T18:03:00","date_gmt":"2020-10-20T18:03:00","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=932"},"modified":"2020-10-20T18:03:00","modified_gmt":"2020-10-20T18:03:00","slug":"install-configure-prometheus-linux","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=932","title":{"rendered":"How To Install and Configure Prometheus Monitoring System On Linux"},"content":{"rendered":"<p>Prometheus is an open-source monitoring system which is very lightweight and has a good alerting mechanism.<\/p>\n<h2 id=\"install-and-configure-prometheus\">Install and Configure Prometheus<\/h2>\n<p>This guide explains how to install and configure the latest Prometheus on a Linux VM.<\/p>\n<p>If you would like to install Prometheus on a Kubernetes cluster, please see the <a href=\"https:\/\/devopscube.com\/setup-prometheus-monitoring-on-kubernetes\/\" rel=\"noopener noreferrer\">Prometheus on kubernetes<\/a> guide.<\/p>\n<h3 id=\"before-you-begin\">Before You Begin<\/h3>\n<ol>\n<li>Ensure that you have sudo access to the Linux server because the commands used in this guide require elevated privileges.<\/li>\n<li>The server has access to the internet for downloading the Prometheus binary.<\/li>\n<li>Most importantly, firewall rules opened for accessing Prometheus port 9090 on the server.<\/li>\n<\/ol>\n<h3 id=\"setup-prometheus-binaries\">Setup Prometheus Binaries<\/h3>\n<p><strong>Step 1:<\/strong> Update the yum package repositories.<\/p>\n<pre><code>sudo yum update -y<\/code><\/pre>\n<p><strong>Step 2:<\/strong> Go to the official Prometheus <a href=\"https:\/\/prometheus.io\/download\/?ref=devopscube.com\" rel=\"noopener noreferrer\">downloads page<\/a> and get the latest download link for the Linux binary.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/prometheus-linux-download-link-2.png\" class=\"kg-image\" alt=\"prometheus linux download link\" loading=\"lazy\" width=\"2000\" height=\"517\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/prometheus-linux-download-link-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/prometheus-linux-download-link-2.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/prometheus-linux-download-link-2.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w2400\/2025\/03\/prometheus-linux-download-link-2.png 2400w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p><strong>Step 3:<\/strong> Download the source using curl, untar it, and rename the extracted folder to prometheus-files.<\/p>\n<pre><code>curl -LO url -LO https:\/\/github.com\/prometheus\/prometheus\/releases\/download\/v2.22.0\/prometheus-2.22.0.linux-amd64.tar.gz\ntar -xvf prometheus-2.22.0.linux-amd64.tar.gz\nmv prometheus-2.22.0.linux-amd64 prometheus-files<\/code><\/pre>\n<p><strong>Step 4:<\/strong> Create a Prometheus user, required directories, and make Prometheus the user as the owner of those directories.<\/p>\n<pre><code>sudo useradd --no-create-home --shell \/bin\/false prometheus\nsudo mkdir \/etc\/prometheus\nsudo mkdir \/var\/lib\/prometheus\nsudo chown prometheus:prometheus \/etc\/prometheus\nsudo chown prometheus:prometheus \/var\/lib\/prometheus<\/code><\/pre>\n<p><strong>Step 5: <\/strong>Copy prometheus and promtool binary from prometheus-files folder to \/usr\/local\/bin and change the ownership to prometheus user.<\/p>\n<pre><code>sudo cp prometheus-files\/prometheus \/usr\/local\/bin\/\nsudo cp prometheus-files\/promtool \/usr\/local\/bin\/\nsudo chown prometheus:prometheus \/usr\/local\/bin\/prometheus\nsudo chown prometheus:prometheus \/usr\/local\/bin\/promtool<\/code><\/pre>\n<p><strong>Step 6:<\/strong> Move the consoles and console_libraries directories from prometheus-files to \/etc\/prometheus folder and change the ownership to prometheus user.<\/p>\n<pre><code>sudo cp -r prometheus-files\/consoles \/etc\/prometheus\nsudo cp -r prometheus-files\/console_libraries \/etc\/prometheus\nsudo chown -R prometheus:prometheus \/etc\/prometheus\/consoles\nsudo chown -R prometheus:prometheus \/etc\/prometheus\/console_libraries<\/code><\/pre>\n<h3 id=\"setup-prometheus-configuration\">Setup Prometheus Configuration<\/h3>\n<p>All the prometheus configurations should be present in \/etc\/prometheus\/prometheus.yml file.<\/p>\n<p><strong>Step 1:<\/strong> Create the prometheus.yml file.<\/p>\n<pre><code>sudo vi \/etc\/prometheus\/prometheus.yml<\/code><\/pre>\n<p><strong>Step 2:<\/strong> Copy the following contents to the prometheus.yml file.<\/p>\n<pre><code>global:\n  scrape_interval: 10s\n\nscrape_configs:\n  - job_name: 'prometheus'\n    scrape_interval: 5s\n    static_configs:\n      - targets: ['localhost:9090']<\/code><\/pre>\n<p><strong>Step 3:<\/strong> Change the ownership of the file to prometheus user.<\/p>\n<pre><code>sudo chown prometheus:prometheus \/etc\/prometheus\/prometheus.yml<\/code><\/pre>\n<h3 id=\"setup-prometheus-service-file\">Setup Prometheus Service File<\/h3>\n<p><strong>Step 1:<\/strong> Create a prometheus service file.<\/p>\n<pre><code>sudo vi \/etc\/systemd\/system\/prometheus.service<\/code><\/pre>\n<p><strong>Step 2:<\/strong> Copy the following content to the file.<\/p>\n<pre><code>[Unit]\nDescription=Prometheus\nWants=network-online.target\nAfter=network-online.target\n\n[Service]\nUser=prometheus\nGroup=prometheus\nType=simple\nExecStart=\/usr\/local\/bin\/prometheus \\\n    --config.file \/etc\/prometheus\/prometheus.yml \\\n    --storage.tsdb.path \/var\/lib\/prometheus\/ \\\n    --web.console.templates=\/etc\/prometheus\/consoles \\\n    --web.console.libraries=\/etc\/prometheus\/console_libraries\n\n[Install]\nWantedBy=multi-user.target<\/code><\/pre>\n<p><strong>Step 3:<\/strong> Reload the systemd service to register the prometheus service and start the prometheus service.<\/p>\n<pre><code>sudo systemctl daemon-reload\nsudo systemctl start prometheus<\/code><\/pre>\n<p>Check the prometheus service status using the following command.<\/p>\n<pre><code>sudo systemctl status prometheus<\/code><\/pre>\n<p>The status should show the active state as shown below.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/prometheus-status-2.png\" class=\"kg-image\" alt=\"prometheus status\" loading=\"lazy\" width=\"1804\" height=\"328\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/prometheus-status-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/prometheus-status-2.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/prometheus-status-2.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/prometheus-status-2.png 1804w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<h3 id=\"access-prometheus-web-ui\">Access Prometheus Web UI<\/h3>\n<p>Now you will be able to access the prometheus UI on 9090 port of the prometheus server.<\/p>\n<pre><code>http:\/\/&lt;prometheus-ip&gt;:9090\/graph<\/code><\/pre>\n<p>You should be able to see the following UI as shown below.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/prometheus-ui-2.png\" class=\"kg-image\" alt=\"prometheus web UI\" loading=\"lazy\" width=\"1960\" height=\"708\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/prometheus-ui-2.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/prometheus-ui-2.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/prometheus-ui-2.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/prometheus-ui-2.png 1960w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>You can use the Prometheus query tab to query the available metrics as shown in the gig below.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/prometheus-metrics-query-2.gif\" class=\"kg-image\" alt=\"querying metrics from prometheus UI\" loading=\"lazy\" width=\"1008\" height=\"897\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/prometheus-metrics-query-2.gif 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/prometheus-metrics-query-2.gif 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/prometheus-metrics-query-2.gif 1008w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>Right now, we have just configured the Prometheus server. You need to register the target in the <code>prometheus.yml<\/code> file to get the metrics from the source systems.<\/p>\n<p>For example, if you want to monitor ten servers, the IP address of these servers should be added as a target in the Prometheus configuration to scrape the metrics.<\/p>\n<p>The server should have Node Exporter installed to collect all the system metrics and make it available for Prometheus to scrap it.<\/p>\n<p>Follow this detailed <a href=\"https:\/\/devopscube.com\/monitor-linux-servers-prometheus-node-exporter\/\" rel=\"noreferrer noopener\">Prometheus Node Exporter Guide<\/a> to setup node exporter and registering it to the Prometheus server.<\/p>\n<p>You can also use this setup as lab for the <a href=\"https:\/\/devopscube.com\/prometheus-certified-associate\/\" rel=\"noreferrer noopener\">Prometheus Certified Associate<\/a> Certification preparation.<\/p>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/install-configure-prometheus-linux\/\" target=\"_blank\" rel=\"noopener noreferrer\">How To Install and Configure Prometheus Monitoring System On Linux \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/install-configure-prometheus-linux\/<\/p>\n","protected":false},"author":1,"featured_media":933,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-932","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/932","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=932"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/932\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/933"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}