{"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":"

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 with a dimensional data model, flexible query language, efficient time series database and modern alerting approach.<\/span><\/p>\n

Install and Configure Prometheus on Fedora\u00a0 29\/Fedora 28<\/h2>\n

Step through this guide in order to install and configure Prometheus on Fedora 29\/Fedora 28.<\/p>\n

Install Prometheus on Ubuntu 18.04 by checking the link below;<\/p>\n

Install Prometheus on Ubuntu 18.04<\/a><\/p>\n

Create Prometheus System User and Group<\/h3>\n

To create prometheus<\/code> system user and group, run the command below;<\/p>\n

useradd -M -r -s \/bin\/false prometheus<\/code><\/pre>\n

To verify this, you can try to print prometheus user and group information using the id<\/code> command;<\/p>\n

getent passwd prometheus\nprometheus:x:986:985::\/home\/prometheus:\/bin\/false<\/code><\/pre>\n

Create Configuration Directories<\/h3>\n

Since we are installing Prometheus from source, you need to create the respective configuration directories.<\/p>\n

mkdir \/etc\/prometheus\nmkdir \/var\/lib\/prometheus<\/code><\/pre>\n

Download Prometheus Binary<\/h3>\n

In order to install the latest version of Prometheus, navigate to the Download’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

wget https:\/\/github.com\/prometheus\/prometheus\/releases\/download\/v2.6.0\/prometheus-2.6.0.linux-amd64.tar.gz<\/code><\/pre>\n

Once the download is done, extract the archive.<\/p>\n

tar -xzf prometheus-2.6.0.linux-amd64.tar.gz<\/code><\/pre>\n

Copy the two Prometheus binary files,\u00a0prometheus<\/code>and promtool<\/code>, under the extracted Prometheus archive directory to the \/usr\/local\/bin<\/code> directory.<\/p>\n

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

Copy the consoles\/<\/code> and console_libraries\/<\/code> directories to \/etc\/prometheus<\/code> directory created above.<\/p>\n

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

Configure Prometheus on Fedara 29\/28<\/h3>\n

The sample Prometheus configuration file,\u00a0prometheus.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

cp prometheus-2.6.0.linux-amd64\/prometheus.yml \/etc\/prometheus\/<\/code><\/pre>\n

Before we proceed, it is good to note that the default port that Prometheus server listens on, 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

systemctl mask cockpit cockpit.socket\nsystemctl stop cockpit cockpit.socket<\/code><\/pre>\n

Next, open it for modification and adjust it such that it looks like;<\/p>\n

vim \/etc\/prometheus\/prometheus.yml<\/code><\/pre>\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# 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']<\/code><\/pre>\n

If you don’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

# 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=<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:8080']<\/strong><\/code><\/pre>\n

Note the targets line above. Prometheus server is set to listen TCP port 8080.<\/p>\n

Allow Prometheus through firewall.<\/p>\n

firewall-cmd --add-port=9090\/tcp --permanent<\/code><\/pre>\n

If it is set to listen on a different port, say 8080;<\/p>\n

firewall-cmd --add-port=8080\/tcp --permanent<\/code><\/pre>\n

Reload firewalld<\/p>\n

firewall-cmd --reload<\/code><\/pre>\n

Set Proper Ownership on Configuration Files and Directories<\/h3>\n

Run the command below to set the ownership (owner and group) of Prometheus configuration files and directories to prometheus.<\/p>\n

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

Starting Prometheus<\/h3>\n

To start Prometheus with our basic configuration file,run:<\/p>\n

prometheus --config.file=\/etc\/prometheus\/<\/span>prometheus.yml<\/code><\/pre>\n

You should able to access the Prometheus status page at http:\/\/localhost:9090<\/code> if you are accessing the server locally or http:\/\/<server-IP>:9090<\/code> if you are accessing remotely.<\/p>\n

\"Install<\/a><\/p>\n

If you configured Prometheus server to listen on a different port above, then you can specify the port using the --web.listen-address<\/code> option as shown below;<\/p>\n

 prometheus --config.file=\/etc\/prometheus\/prometheus.yml --web.listen-address=:8080<\/strong><\/code><\/pre>\n

You can then access the Prometheus dashboard using the url http:\/\/<server-IP>:8080<\/code>.<\/p>\n

Create Prometheus Systemd Service file<\/h3>\n

To be able to run Prometheus as a service, you need to create a systemd service file,\u00a0\/etc\/systemd\/system\/prometheus.service<\/code>, configured as follows. Note that this assumes Prometheus server is listening on default port 9090.<\/p>\n

vim \/etc\/systemd\/system\/prometheus.service<\/code><\/pre>\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<\/code><\/pre>\n

If you configured Prometheus server to listen on non-default port, edit the ExecStart=<\/code> section of the service file and add the line, --web.listen-address=0.0.0.0:8080<\/code><\/strong>.<\/p>\n

...\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    --web.listen-address=0.0.0.0:8080\n\n<\/strong><\/code><\/pre>\n

Reload systemd daemon configuration.<\/p>\n

systemctl daemon-reload<\/code><\/pre>\n

Start and Enable Prometheus service to run at boot time.<\/p>\n

systemctl start prometheus\nsystemctl enable prometheus<\/code><\/pre>\n

Check the status<\/p>\n

systemctl status prometheus\n\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: 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

Great, Prometheus is now running as a service.<\/p>\n

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

Feel free to explore more about Prometheus here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"

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}]}}