{"id":1986,"date":"2019-01-09T19:36:42","date_gmt":"2019-01-09T16:36:42","guid":{"rendered":"http:\/\/kifarunix.com\/?p=1986"},"modified":"2019-09-17T19:59:09","modified_gmt":"2019-09-17T16:59:09","slug":"install-and-configure-prometheus-on-debian-9","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-and-configure-prometheus-on-debian-9\/","title":{"rendered":"Install and Configure Prometheus on Debian 9"},"content":{"rendered":"

In this guide, we are going to learn how to install and configure Prometheus on Debian 9. Prometheus is a time series collection and processing\u00a0monitoring platform with a dimensional data model, flexible query language, efficient time series database and modern alerting approach.<\/span><\/p>\n

Want to install Prometheus on Ubuntu 18.04? See the link below;<\/p>\n

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

Install and Configure Prometheus on Debian 9<\/h2>\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

id prometheus\nuid=999(prometheus) gid=999(prometheus) groups=999(prometheus)<\/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

Assign the ownership of the above directories, user and group, to prometheus.<\/p>\n

chown prometheus:prometheus \/etc\/prometheus\nchown prometheus:prometheus \/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 and\u00a0promtool<\/code>, under the extracted Prometheus 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

Assign the owner and the group of the above directories to prometheus.<\/p>\n

chown prometheus:prometheus \/usr\/local\/bin\/prometheus\nchown prometheus:prometheus \/usr\/local\/bin\/promtool<\/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\/consoles \/etc\/prometheus\/\ncp -r prometheus-2.6.0.linux-amd64\/console_libraries\/ \/etc\/prometheus\/<\/code><\/pre>\n

Similarly, set the ownership to prometheus user.<\/p>\n

chown -R prometheus:prometheus \/etc\/prometheus\/consoles\nchown -R prometheus:prometheus \/etc\/prometheus\/console_libraries<\/code><\/pre>\n

Configure Prometheus<\/h3>\n

Now that we have all the required configuration files in place, proceed to configure Prometheus. The sample Prometheus configuration file is located under the extracted 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.<\/p>\n

cp prometheus-2.6.0.linux-amd64\/prometheus.yml \/etc\/prometheus\/<\/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

Set the ownership of the configuration file to prometheus user.<\/p>\n

chown prometheus:prometheus \/etc\/prometheus\/prometheus.yml<\/code><\/pre>\n

Starting Prometheus<\/h3>\n

The basic configuration of Prometheus is now done. 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

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;<\/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

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

Upto there, we have learnt a basic of how to install and configure Prometheus on Debian 9. In our next tutorials, we will cover how monitor other target systems so that you can have a real taste of what Prometheus has to offer. Stay connected.<\/p>\n

Feel free to explore more about Prometheus here<\/a>.<\/p>\n

Check our other guides by following the links below;<\/p>\n

Install Graylog 3.0 on CentOS 7<\/a><\/p>\n

Monitor Squid Access Logs with Graylog Server<\/a><\/p>\n

Monitor Squid logs with Grafana and Graylog<\/a><\/p>\n

Install Grafana 6.2.x on Ubuntu 18.04\/Debian 9<\/a><\/p>\n

Install Grafana Metrics Monitoring Tool on Debian 9<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

In this guide, we are going to learn how to install and configure Prometheus on Debian 9. Prometheus is a time series collection and processing\u00a0monitoring<\/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":[287,295],"class_list":["post-1986","post","type-post","status-publish","format-standard","hentry","category-howtos","category-monitoring","category-prometheus","tag-debian-9","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\/1986"}],"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=1986"}],"version-history":[{"count":11,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1986\/revisions"}],"predecessor-version":[{"id":4181,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1986\/revisions\/4181"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=1986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=1986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=1986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}