{"id":9529,"date":"2021-07-09T00:00:22","date_gmt":"2021-07-08T21:00:22","guid":{"rendered":"https:\/\/kifarunix.com\/?p=9529"},"modified":"2024-03-18T19:49:11","modified_gmt":"2024-03-18T16:49:11","slug":"install-prometheus-on-rocky-linux-8","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-prometheus-on-rocky-linux-8\/","title":{"rendered":"Install Prometheus on Rocky Linux 8"},"content":{"rendered":"\n<p>Welcome to our guide on how to install Prometheus on Rocky Linux 8.&nbsp;<a href=\"https:\/\/prometheus.io\/\" target=\"_blank\" rel=\"noreferrer noopener\">Prometheus<\/a>&nbsp;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<p>Want to quickly get started wit Prometheus application and infrastructure monitoring? Check the link below;<\/p>\n\n\n\n<p><a target=\"_blank\" href=\"https:\/\/www.amazon.com\/gp\/product\/1492034142\/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1492034142&amp;linkCode=as2&amp;tag=unixkip-20&amp;linkId=ad8e4c52d97f6364fd2fba5bc30dd789\" rel=\"noreferrer noopener\">Prometheus: Up &amp; Running: Infrastructure and Application Performance Monitoring<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing Prometheus on Rocky Linux 8<\/h2>\n\n\n\n<p>Step through this guide in order to install and configure Prometheus on Rocky Linux 8.<\/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<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<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mkdir \/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.<\/p>\n\n\n\n<p>You can simply run the command below to download the latest version as of this writing for Linux systems.<\/p>\n\n\n\n<p>Replace the value of the VER variable below with the current version of Prometheus.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>VER=2.28.1<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>wget https:\/\/github.com\/prometheus\/prometheus\/releases\/download\/v$VER\/prometheus-$VER.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-$VER.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-$VER.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-$VER.linux-amd64\/{consoles,console_libraries} \/etc\/prometheus\/<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure Prometheus on Rocky Linux 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-$VER.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<p>The default configuration is enough for demo purposes. Below is the content of the default Prometheus config file.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\n# 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# Alertmanager configuration\nalerting:\n  alertmanagers:\n  - static_configs:\n    - targets:\n      # - alertmanager:9093\n\n# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.\nrule_files:\n  # - \"first_rules.yml\"\n  # - \"second_rules.yml\"\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=<job_name>` 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']\n<\/code><\/pre>\n\n\n\n<p>Save and exit the configuration file.<\/p>\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<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-code\"><code>...\nlevel=info ts=2021-07-08T20:14:48.449Z caller=main.go:854 msg=\"TSDB started\"\nlevel=info ts=2021-07-08T20:14:48.449Z caller=main.go:981 msg=\"Loading configuration file\" filename=\/etc\/prometheus\/prometheus.yml\nlevel=info ts=2021-07-08T20:14:48.451Z caller=main.go:1012 msg=\"Completed loading of configuration file\" filename=\/etc\/prometheus\/prometheus.yml totalDuration=1.389669ms remote_storage=1.749\u00b5s web_handler=236ns query_engine=591ns scrape=1.093751ms scrape_sd=26.279\u00b5s notify=23.549\u00b5s notify_sd=17.882\u00b5s rules=1.004\u00b5s\nlevel=info ts=2021-07-08T20:14:48.451Z caller=main.go:796 <strong>msg=\"Server is ready to receive web requests.\"<\/strong><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Accessing Prometheus Web Interface<\/h3>\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=\"1910\" height=\"589\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/prometheus.png\" alt=\"Install Prometheus on Rocky Linux 8\" class=\"wp-image-9551\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/prometheus.png?v=1625776433 1910w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/prometheus-768x237.png?v=1625776433 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/prometheus-1536x474.png?v=1625776433 1536w\" sizes=\"(max-width: 1910px) 100vw, 1910px\" \/><\/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<pre class=\"wp-block-preformatted\"><code>Note that this assumes Prometheus server is listening on default port 9090.<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\ncat > \/etc\/systemd\/system\/prometheus.service << 'EOL'\n[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\nEOL\n<\/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=\"scroll-box\"><code>\u25cf prometheus.service - Prometheus Time Series Collection and Processing Server\n   Loaded: loaded (\/etc\/systemd\/system\/prometheus.service; disabled; vendor preset: disabled)\n   Active: active (running) since Thu 2021-07-08 23:19:51 EAT; 7s ago\n Main PID: 8209 (prometheus)\n    Tasks: 6 (limit: 4938)\n   Memory: 18.3M\n   CGroup: \/system.slice\/prometheus.service\n           \u2514\u25008209 \/usr\/local\/bin\/prometheus --config.file \/etc\/prometheus\/prometheus.yml --storage.tsdb.path \/var\/lib\/prometheus\/ --web.console.templates=\/etc\/prometheus\/c&gt;\n\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.676Z caller=head.go:794 component=tsdb msg=\"On-disk memory mappable chunks replay&gt;\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.676Z caller=head.go:800 component=tsdb msg=\"Replaying WAL, this may take a while\"\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.678Z caller=tls_config.go:191 component=web msg=\"TLS is disabled.\" http2=false\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.678Z caller=head.go:854 component=tsdb msg=\"WAL segment loaded\" segment=0 maxSegm&gt;\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.678Z caller=head.go:860 component=tsdb msg=\"WAL replay completed\" checkpoint_repl&gt;\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.679Z caller=main.go:851 fs_type=XFS_SUPER_MAGIC\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.679Z caller=main.go:854 msg=\"TSDB started\"\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.679Z caller=main.go:981 msg=\"Loading configuration file\" filename=\/etc\/prometheus&gt;\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.681Z caller=main.go:1012 msg=\"Completed loading of configuration file\" filename=\/&gt;\nJul 08 23:19:51 localhost.localdomain prometheus[8209]: level=info ts=2021-07-08T20:19:51.681Z caller=main.go:796 msg=\"Server is ready to receive web requests.\"\n<\/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>ss -altnp | grep 9090<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>LISTEN 0      128                *:9090            *:*    users:((\"prometheus\",pid=8209,fd=7))<\/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&nbsp;<strong>Status<\/strong>&nbsp;dropdown and then&nbsp;<strong>Targets.<\/strong>&nbsp;At the moment, we only have Prometheus scraping the localhost on which it is running.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1888\" height=\"520\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/prometheus-status.png\" alt=\"\" class=\"wp-image-9550\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/prometheus-status.png?v=1625776387 1888w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/prometheus-status-768x212.png?v=1625776387 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/prometheus-status-1536x423.png?v=1625776387 1536w\" sizes=\"(max-width: 1888px) 100vw, 1888px\" \/><\/figure>\n\n\n\n<p>You can also check local system metrics for example to check memory statistics for example \u201c<strong>go_memstats_frees_total<\/strong>\u201c.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1912\" height=\"476\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/prometheus-check-mem.png\" alt=\"\" class=\"wp-image-9552\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/prometheus-check-mem.png?v=1625776480 1912w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/prometheus-check-mem-768x191.png?v=1625776480 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/prometheus-check-mem-1536x382.png?v=1625776480 1536w\" sizes=\"(max-width: 1912px) 100vw, 1912px\" \/><\/figure>\n\n\n\n<p>For graphical overview, click Graph.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1877\" height=\"919\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/prometheus-check-mem-grap.png\" alt=\"\" class=\"wp-image-9553\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/prometheus-check-mem-grap.png?v=1625777579 1877w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/prometheus-check-mem-grap-768x376.png?v=1625777579 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/07\/prometheus-check-mem-grap-1536x752.png?v=1625777579 1536w\" sizes=\"(max-width: 1877px) 100vw, 1877px\" \/><\/figure>\n\n\n\n<p>So far so good, you have learnt how to install and configure Prometheus on Rocky Linux 8.<\/p>\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<h4 class=\"wp-block-heading\">Other tutorials<\/h4>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/configure-prometheus-email-alerting-with-alertmanager\/\" target=\"_blank\" rel=\"noreferrer noopener\">Configure Prometheus Email Alerting with AlertManager<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/monitor-ssl-tls-certificate-expiry-with-prometheus-and-grafana\/\" target=\"_blank\" rel=\"noreferrer noopener\">Monitor SSL\/TLS Certificate Expiry with Prometheus and Grafana<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to our guide on how to install Prometheus on Rocky Linux 8.&nbsp;Prometheus&nbsp;is an &nbsp;open-source time series collection and processing monitoring system&nbsp;with a dimensional data<\/p>\n","protected":false},"author":1,"featured_media":9554,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[72,121,294],"tags":[3816,3817,3587],"class_list":["post-9529","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-monitoring","category-howtos","category-prometheus","tag-install-prometheus-rocky-linux","tag-prometheus-install","tag-rocky-linux-8","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9529"}],"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=9529"}],"version-history":[{"count":8,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9529\/revisions"}],"predecessor-version":[{"id":21742,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/9529\/revisions\/21742"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/9554"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=9529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=9529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=9529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}