{"id":4619,"date":"2019-11-13T21:26:06","date_gmt":"2019-11-13T18:26:06","guid":{"rendered":"https:\/\/kifarunix.com\/?p=4619"},"modified":"2024-03-12T23:17:12","modified_gmt":"2024-03-12T20:17:12","slug":"install-and-configure-prometheus-on-centos-8","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-and-configure-prometheus-on-centos-8\/","title":{"rendered":"Install and Configure Prometheus on CentOS 8"},"content":{"rendered":"\n<p>Welcome to our guide on how to install and configure Prometheus on CentOS 8. <a href=\"https:\/\/prometheus.io\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Prometheus (opens in a new tab)\">Prometheus<\/a> is an &nbsp;open-source time series collection and processing monitoring system&nbsp;with a dimensional data model, flexible query language, efficient time series database and modern alerting approach.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing Prometheus on CentOS 8<\/h2>\n\n\n\n<p>Want to Install Prometheus on Ubuntu 18\/Debian 9. Check the links below;<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/kifarunix.com\/install-prometheus-on-ubuntu-18-04\/\" target=\"_blank\">Install Prometheus on Ubuntu 18.04<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-configure-prometheus-on-debian-9\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Install and Configure Prometheus on Debian 9<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create Prometheus System User and Group<\/h3>\n\n\n\n<p>Run the command below to create&nbsp;<code>prometheus<\/code>&nbsp;system user and group.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>useradd -M -r -s \/bin\/false prometheus<\/code><\/pre>\n\n\n\n<p>To verify this, you can try to print prometheus user and group information using the&nbsp;<code>id<\/code>&nbsp;command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>getent passwd prometheus\nprometheus:x:986:985::\/home\/prometheus:\/bin\/false<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create Prometheus Configuration Directories<\/h3>\n\n\n\n<p>Since we are installing Prometheus from source, you need to create the respective configuration directories.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mkdir \/etc\/prometheus\nmkdir \/var\/lib\/prometheus<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Download Prometheus Tarball<\/h3>\n\n\n\n<p>In order to install the latest version of Prometheus, navigate to the&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/prometheus.io\/download\" target=\"_blank\">Download\u2019s Page<\/a>&nbsp;and grab Prometheus binary for your platform. You can simply run the command below to download version 2.14.0 (latest version as of this writing) for Linux systems.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>wget https:\/\/github.com\/prometheus\/prometheus\/releases\/download\/v2.14.0\/prometheus-2.14.0.linux-amd64.tar.gz -P \/tmp<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Extract Prometheus Tarball<\/h3>\n\n\n\n<p>Once the download is done, extract the archive.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cd \/tmp<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>tar -xzf prometheus-2.14.0.linux-amd64.tar.gz<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ls prometheus-2.14.0.linux-amd64<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>console_libraries  consoles  LICENSE  NOTICE  prometheus  prometheus.yml  promtool  tsdb<\/code><\/pre>\n\n\n\n<p>Copy the two Prometheus binary files,&nbsp;<code>prometheus<\/code>and&nbsp;<code>promtool<\/code>, under the extracted Prometheus archive directory to the&nbsp;<code>\/usr\/local\/bin<\/code>&nbsp;directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cp prometheus-2.14.0.linux-amd64\/{prometheus,promtool} \/usr\/local\/bin\/<\/code><\/pre>\n\n\n\n<p>Copy the&nbsp;<code>consoles\/<\/code>&nbsp;and&nbsp;<code>console_libraries\/<\/code>&nbsp;directories to&nbsp;<code>\/etc\/prometheus<\/code>&nbsp;directory created above.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cp -r prometheus-2.14.0.linux-amd64\/{consoles,console_libraries} \/etc\/prometheus\/<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure Prometheus on CentOS 8<\/h3>\n\n\n\n<p>The sample Prometheus configuration file,&nbsp;<code>prometheus.yml<\/code>, is located under the extracted archive directory.<\/p>\n\n\n\n<p>Since we are doing a basic setup, we will copy the configuration file and modify it as follows such that it can scrape the local system only (Prometheus server).<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cp prometheus-2.14.0.linux-amd64\/prometheus.yml \/etc\/prometheus\/<\/code><\/pre>\n\n\n\n<p>Next, open the configuration file for modification and adjust it such that it looks like;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/prometheus\/prometheus.yml<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># my global config\nglobal:\n  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.\n  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.\n  # scrape_timeout is set to the global default (10s).\n\n# A scrape configuration containing exactly one endpoint to scrape:\n# Here it's Prometheus itself.\nscrape_configs:\n  # The job name is added as a label `job=&lt;job_name&gt;` to any timeseries scraped from this config.\n  - job_name: 'prometheus'\n\n    # metrics_path defaults to '\/metrics'\n    # scheme defaults to 'http'.\n\n    static_configs:\n    - targets: ['localhost:9090']<\/code><\/pre>\n\n\n\n<p>Allow Prometheus through firewall.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>firewall-cmd --add-port=9090\/tcp --permanent<\/code><\/pre>\n\n\n\n<p>Reload firewalld<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>firewall-cmd --reload<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Set Proper Ownership on Configuration Files and Directories<\/h3>\n\n\n\n<p>Run the command below to set the ownership (owner and group) of Prometheus configuration files and directories to prometheus.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chown -R prometheus:prometheus \/etc\/prometheus<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chown -R prometheus:prometheus \/var\/lib\/prometheus<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chown prometheus.prometheus \/usr\/local\/bin\/{prometheus,promtool}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"starting-prometheus\">Starting Prometheus<\/h3>\n\n\n\n<p>To start Prometheus with our basic configuration file,run:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>prometheus --config.file=\/etc\/prometheus\/prometheus.yml<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>...\nlevel=info ts=2019-11-13T17:33:55.867Z caller=main.go:743 msg=\"Loading configuration file\" filename=\/etc\/prometheus\/prometheus.yml\nlevel=info ts=2019-11-13T17:33:56.353Z caller=main.go:771 msg=\"Completed loading of configuration file\" filename=\/etc\/prometheus\/prometheus.yml\n<strong>level=info ts=2019-11-13T17:33:56.353Z caller=main.go:626 msg=\"Server is ready to receive web requests.\"<\/strong><\/code><\/pre>\n\n\n\n<p>You should able to access the Prometheus status page at&nbsp;<code>http:\/\/localhost:9090<\/code>&nbsp;if you are accessing the server locally or&nbsp;<code>http:\/\/&lt;server-IP&gt;:9090<\/code>&nbsp;if you are accessing remotely.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1348\" height=\"519\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/prometheus.png\" alt=\"Install and Configure Prometheus on CentOS 8\" class=\"wp-image-4620\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/prometheus.png?v=1573666856 1348w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/prometheus-768x296.png?v=1573666856 768w\" sizes=\"(max-width: 1348px) 100vw, 1348px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Create Prometheus Systemd Service file<\/h3>\n\n\n\n<p>To be able to run Prometheus as a service, you need to create a systemd service file,&nbsp;<code>\/etc\/systemd\/system\/prometheus.service<\/code>, configured as follows.<\/p>\n\n\n\n<p>Note that this assumes Prometheus server is listening on default port 9090.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/systemd\/system\/prometheus.service<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>[Unit]\nDescription=Prometheus Time Series Collection and Processing Server\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\n\n\n<p>Reload systemd daemon configuration.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl daemon-reload<\/code><\/pre>\n\n\n\n<p>Start and Enable Prometheus service to run at boot time.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl enable --now prometheus<\/code><\/pre>\n\n\n\n<p>Check the status<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl status prometheus<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\u25cf prometheus.service - Prometheus Time Series Collection and Processing Server\n   Loaded: loaded (\/etc\/systemd\/system\/prometheus.service; enabled; vendor preset: disabled)\n   Active: active (running) since Wed 2019-11-13 20:47:02 EAT; 24s ago\n Main PID: 2931 (prometheus)\n    Tasks: 7 (limit: 5072)\n   Memory: 23.2M\n   CGroup: \/system.slice\/prometheus.service\n           \u2514\u25002931 \/usr\/local\/bin\/prometheus --config.file \/etc\/prometheus\/prometheus.yml --storage.tsdb.path \/var\/lib\/prometheus\/ --web.console.libraries=\/etc\/prometheus\/console_libraries<\/code><\/pre>\n\n\n\n<p>Check that prometheus is listening on TCP port 9090.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>lsof -i :9090<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>COMMAND    PID       USER   FD   TYPE DEVICE SIZE\/OFF NODE NAME\nprometheu 2931 prometheus    3u  IPv6  39243      0t0  TCP localhost:websm-&gt;localhost:45648 (ESTABLISHED)\nprometheu 2931 prometheus    7u  IPv6  39251      0t0  TCP localhost:47936-&gt;localhost:websm (ESTABLISHED)\nprometheu 2931 prometheus    8u  IPv6  39239      0t0  TCP *:websm (LISTEN)\nprometheu 2931 prometheus    9u  IPv6  39252      0t0  TCP localhost:websm-&gt;localhost:47936 (ESTABLISHED)\nprometheu 2931 prometheus   10u  IPv4  39242      0t0  TCP localhost:45648-&gt;localhost:websm (ESTABLISHED)<\/code><\/pre>\n\n\n\n<p>Great, Prometheus is now running as a service.<\/p>\n\n\n\n<p>You can now check the status of the connected targets. Click <strong>Status<\/strong> dropdown and then <strong>Targets.<\/strong> At the moment, we only have Prometheus scraping the localhost on which it is running.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/prometheus-targets.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1096\" height=\"347\" data-id=\"4626\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/prometheus-targets.png\" alt=\"\" class=\"wp-image-4626\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/prometheus-targets.png?v=1573708378 1096w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/prometheus-targets-768x243.png?v=1573708378 768w\" sizes=\"(max-width: 1096px) 100vw, 1096px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>You can also check local system metrics for example to check memory statistics for example &#8220;<strong>go_memstats_frees_total<\/strong>&#8220;.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/check-mem-status.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1361\" height=\"414\" data-id=\"4621\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/check-mem-status.png\" alt=\"\" class=\"wp-image-4621\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/check-mem-status.png?v=1573668535 1361w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/check-mem-status-768x234.png?v=1573668535 768w\" sizes=\"(max-width: 1361px) 100vw, 1361px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>For graphical overview, click Graph.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/check-mem-graph.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1333\" height=\"525\" data-id=\"4622\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/check-mem-graph.png\" alt=\"\" class=\"wp-image-4622\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/check-mem-graph.png?v=1573668820 1333w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/11\/check-mem-graph-768x302.png?v=1573668820 768w\" sizes=\"(max-width: 1333px) 100vw, 1333px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p>Feel free to explore more about Prometheus&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/prometheus.io\/\" target=\"_blank\">here<\/a>.<\/p>\n\n\n\n<p>In our next guides, we will be covering how to monitor other targets using Prometheus. Enjoy.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Related Tutorials<\/h3>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/integrate-prometheus-with-grafana-for-monitoring\/\" target=\"_blank\">Integrate Prometheus with Grafana for Monitoring<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/monitor-linux-system-metrics-with-prometheus-node-exporter\/\" target=\"_blank\">Monitor Linux System Metrics with Prometheus Node Exporter<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-monitorix-on-debian-10\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Install Monitorix on Debian 10<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to our guide on how to install and configure Prometheus on CentOS 8. Prometheus is an &nbsp;open-source time series collection and processing monitoring system&nbsp;with<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,72,294],"tags":[1142,1194,295],"class_list":["post-4619","post","type-post","status-publish","format-standard","hentry","category-howtos","category-monitoring","category-prometheus","tag-centos-8","tag-install-prometheus-centos-8","tag-prometheus","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4619"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=4619"}],"version-history":[{"count":4,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4619\/revisions"}],"predecessor-version":[{"id":21262,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/4619\/revisions\/21262"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=4619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=4619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=4619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}