{"id":1992,"date":"2019-01-09T22:59:37","date_gmt":"2019-01-09T19:59:37","guid":{"rendered":"http:\/\/kifarunix.com\/?p=1992"},"modified":"2019-05-29T21:44:59","modified_gmt":"2019-05-29T18:44:59","slug":"install-and-configure-prometheus-on-fedora-29-fedora-28","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-and-configure-prometheus-on-fedora-29-fedora-28\/","title":{"rendered":"Install and Configure Prometheus on Fedora 29\/Fedora 28"},"content":{"rendered":"<p>In this guide, we are going to learn how to install and configure Prometheus on Fedora 29\/Fedora 28. As you already know,\u00a0Prometheus is a time series collection and processing server <span class=\"st\">with a dimensional data model, flexible query language, efficient time series database and modern alerting approach.<\/span><\/p>\n<h2>Install and Configure Prometheus on Fedora\u00a0 29\/Fedora 28<\/h2>\n<p>Step through this guide in order to install and configure Prometheus on Fedora 29\/Fedora 28.<\/p>\n<p>Install Prometheus on Ubuntu 18.04 by checking the link below;<\/p>\n<p><a href=\"https:\/\/kifarunix.com\/install-prometheus-on-ubuntu-18-04\/\" target=\"_blank\" rel=\"noopener noreferrer\">Install Prometheus on Ubuntu 18.04<\/a><\/p>\n<h3>Create Prometheus System User and Group<\/h3>\n<p>To create <code>prometheus<\/code> system user and group, run the command below;<\/p>\n<pre>useradd -M -r -s \/bin\/false prometheus<\/code><\/pre>\n<p>To verify this, you can try to print prometheus user and group information using the <code>id<\/code> command;<\/p>\n<pre>getent passwd prometheus\nprometheus:x:986:985::\/home\/prometheus:\/bin\/false<\/code><\/pre>\n<h3>Create Configuration Directories<\/h3>\n<p>Since we are installing Prometheus from source, you need to create the respective configuration directories.<\/p>\n<pre>mkdir \/etc\/prometheus\nmkdir \/var\/lib\/prometheus<\/code><\/pre>\n<h3>Download Prometheus Binary<\/h3>\n<p>In order to install the latest version of Prometheus, navigate to the <a href=\"https:\/\/prometheus.io\/download\" target=\"_blank\" rel=\"noopener noreferrer\">Download&#8217;s Page<\/a> and grab Prometheus binary for your platform. You can simply run the command below to download version 2.6.0 for Linux systems.<\/p>\n<pre>wget https:\/\/github.com\/prometheus\/prometheus\/releases\/download\/v2.6.0\/prometheus-2.6.0.linux-amd64.tar.gz<\/code><\/pre>\n<p>Once the download is done, extract the archive.<\/p>\n<pre>tar -xzf prometheus-2.6.0.linux-amd64.tar.gz<\/code><\/pre>\n<p>Copy the two Prometheus binary files,\u00a0<code>prometheus<\/code>and <code>promtool<\/code>, under the extracted Prometheus archive directory to the <code>\/usr\/local\/bin<\/code> directory.<\/p>\n<pre>cp prometheus-2.6.0.linux-amd64\/prometheus \/usr\/local\/bin\/\ncp prometheus-2.6.0.linux-amd64\/promtool \/usr\/local\/bin\/<\/code><\/pre>\n<p>Copy the <code>consoles\/<\/code> and <code>console_libraries\/<\/code> directories to <code>\/etc\/prometheus<\/code> directory created above.<\/p>\n<pre>cp -r prometheus-2.6.0.linux-amd64\/console \/etc\/prometheus\/\ncp -r prometheus-2.6.0.linux-amd64\/console_libraries\/ \/etc\/prometheus\/<\/code><\/pre>\n<h3>Configure Prometheus on Fedara 29\/28<\/h3>\n<p>The sample Prometheus configuration file,\u00a0<code>prometheus.yml<\/code>, is located under the extracted archive directory. 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<pre>cp prometheus-2.6.0.linux-amd64\/prometheus.yml \/etc\/prometheus\/<\/code><\/pre>\n<p>Before we proceed, it is good to note that the default port that Prometheus server listens on, <code>TCP port 9090<\/code>, is the same port the Fedora Cockpit socket listening on. As a result, if you are not using the Cockpit Web service Manager, disable and stop both the service and socket to free port 9090.<\/p>\n<pre>systemctl mask cockpit cockpit.socket\nsystemctl stop cockpit cockpit.socket<\/code><\/pre>\n<p>Next, open it for modification and adjust it such that it looks like;<\/p>\n<pre>vim \/etc\/prometheus\/prometheus.yml<\/code><\/pre>\n<pre># 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<p>If you don&#8217;t want to stop the Cockpit service, then you can configure Prometheus server to listen on a different port, say TCP port 8080. Hence adjust your configuration such that it looks like;<\/p>\n<pre># 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    - <strong>targets: ['localhost:8080']<\/strong><\/code><\/pre>\n<p>Note the targets line above. Prometheus server is set to listen TCP port 8080.<\/p>\n<p>Allow Prometheus through firewall.<\/p>\n<pre>firewall-cmd --add-port=9090\/tcp --permanent<\/code><\/pre>\n<p>If it is set to listen on a different port, say 8080;<\/p>\n<pre>firewall-cmd --add-port=8080\/tcp --permanent<\/code><\/pre>\n<p>Reload firewalld<\/p>\n<pre>firewall-cmd --reload<\/code><\/pre>\n<h3>Set Proper Ownership on Configuration Files and Directories<\/h3>\n<p>Run the command below to set the ownership (owner and group) of Prometheus configuration files and directories to prometheus.<\/p>\n<pre>chown -R prometheus:prometheus \/etc\/prometheus\nchown -R prometheus:prometheus \/var\/lib\/prometheus\nchown prometheus.prometheus \/usr\/local\/bin\/prometheus\nchown prometheus.prometheus \/usr\/local\/bin\/promtool<\/code><\/pre>\n<h3 id=\"starting-prometheus\">Starting Prometheus<\/h3>\n<p>To start Prometheus with our basic configuration file,run:<\/p>\n<pre><code class=\"language-bash\">prometheus --config.file<span class=\"o\">=\/etc\/prometheus\/<\/span>prometheus.yml<\/code><\/pre>\n<p>You should able to access the Prometheus status page at <code>http:\/\/localhost:9090<\/code> if you are accessing the server locally or <code>http:\/\/&lt;server-IP&gt;:9090<\/code> if you are accessing remotely.<\/p>\n<p><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/01\/prometheus-dashabord-8080.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1998 size-full\" title=\"Install and Configure Prometheus on Fedora 29\/Fedora 28\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/01\/prometheus-dashabord-8080.png\" alt=\"Install and Configure Prometheus on Fedora 29\/Fedora 28\" width=\"1412\" height=\"609\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/01\/prometheus-dashabord-8080.png 1412w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/01\/prometheus-dashabord-8080-768x331.png 768w\" sizes=\"(max-width: 1412px) 100vw, 1412px\" \/><\/a><\/p>\n<p>If you configured Prometheus server to listen on a different port above, then you can specify the port using the <code>--web.listen-address<\/code> option as shown below;<\/p>\n<pre> prometheus --config.file=\/etc\/prometheus\/prometheus.yml <strong>--web.listen-address=:8080<\/strong><\/code><\/pre>\n<p>You can then access the Prometheus dashboard using the url <code>http:\/\/&lt;server-IP&gt;:8080<\/code>.<\/p>\n<h3>Create Prometheus Systemd Service file<\/h3>\n<p>To be able to run Prometheus as a service, you need to create a systemd service file,\u00a0<code>\/etc\/systemd\/system\/prometheus.service<\/code>, configured as follows. Note that this assumes Prometheus server is listening on default port 9090.<\/p>\n<pre>vim \/etc\/systemd\/system\/prometheus.service<\/code><\/pre>\n<pre>[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<p>If you configured Prometheus server to listen on non-default port, edit the <code>ExecStart=<\/code> section of the service file and add the line, <strong><code>--web.listen-address=0.0.0.0:8080<\/code><\/strong>.<\/p>\n<pre>...\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    <strong>--web.listen-address=0.0.0.0:8080\n\n<\/strong><\/code><\/pre>\n<p>Reload systemd daemon configuration.<\/p>\n<pre>systemctl daemon-reload<\/code><\/pre>\n<p>Start and Enable Prometheus service to run at boot time.<\/p>\n<pre>systemctl start prometheus\nsystemctl enable prometheus<\/code><\/pre>\n<p>Check the status<\/p>\n<pre>systemctl status prometheus\n<span style=\"color: #00ff00;\">\u25cf<\/span> prometheus.service - Prometheus Time Series Collection and Processing Server\n   Loaded: loaded (\/etc\/systemd\/system\/prometheus.service; enabled; vendor preset: enabled)\n   Active: <span style=\"color: #00ff00;\">active (running)<\/span> since Wed 2019-01-09 11:22:52 EST; 1min 1s ago\n Main PID: 1649 (prometheus)\n   CGroup: \/system.slice\/prometheus.service\n           \u2514\u25001649 \/usr\/local\/bin\/prometheus --config.file \/etc\/prometheus\/prometheus.yml --storage.tsdb.path \/var\/lib\/prometheus\/ --web.console.templates=\/etc\/<\/code><\/pre>\n<p>Great, Prometheus is now running as a service.<\/p>\n<p>So far so good, you have learnt how to install and configure Prometheus on Fedoara 29\/Fedora 28. In our next guides, we will be covering how to monitor other targets using Prometheus. Enjoy.<\/p>\n<p>Feel free to explore more about Prometheus <a href=\"https:\/\/prometheus.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we are going to learn how to install and configure Prometheus on Fedora 29\/Fedora 28. As you already know,\u00a0Prometheus is a time<\/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":[289,295],"class_list":["post-1992","post","type-post","status-publish","format-standard","hentry","category-howtos","category-monitoring","category-prometheus","tag-fedora-29","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\/1992"}],"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=1992"}],"version-history":[{"count":3,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1992\/revisions"}],"predecessor-version":[{"id":3165,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1992\/revisions\/3165"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=1992"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=1992"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=1992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}