{"id":11809,"date":"2021-11-09T04:08:41","date_gmt":"2021-11-09T04:08:41","guid":{"rendered":"https:\/\/linuxways.net\/?p=11809"},"modified":"2021-11-16T13:14:05","modified_gmt":"2021-11-16T13:14:05","slug":"how-to-install-prometheus-monitoring-tool-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-install-prometheus-monitoring-tool-on-ubuntu-20-04\/","title":{"rendered":"How to install Prometheus monitoring tool on Ubuntu 20.04"},"content":{"rendered":"<p>Prometheus is a system monitoring tool used for recording real-time metrics and system performance in a time-series database. It is open-source software that was originally developed at SoundCloud using the Go programming language.<\/p>\n<p>You can monitor applications and system resources such as CPU usage, memory utilization, network bandwidth among others.<\/p>\n<p>Prometheus can be accessed through a web interface, therefore, allowing you to monitor your server from any device. Moreover, you can send alerts via email and SMS messages in case a problem is identified in your system.<\/p>\n<p>&nbsp;<\/p>\n<p>In this guide, we\u2019ll discuss how you can install Prometheus on Ubuntu 20.04.<\/p>\n<h2>Step 1: Create system Users and Directory<\/h2>\n<p>First, you need to create a system user and group for Prometheus. Let\u2019 create a user, group, and directory called Prometheus. Run the following commands:<\/p>\n<pre><strong>$ sudo useradd --no-create-home --shell \/bin\/false prometheus<\/strong><\/pre>\n<pre><strong>$ sudo useradd --no-create-home --shell \/bin\/false node_exporter<\/strong><\/pre>\n<p>Thereafter, we need to create directories for storing Prometheus files and data. Create a \/var\/lib directory for its data and \/etc directory for configuration files.<\/p>\n<pre><strong>$ sudo mkdir \/etc\/prometheus<\/strong>\r\n\r\n<strong>$ sudo mkdir \/var\/lib\/prometheus<\/strong><\/pre>\n<p>Next, modify the user and group ownership on the new directories to the Prometheus user you created. Run:<\/p>\n<pre><strong>$ sudo chown prometheus:prometheus \/etc\/prometheus<\/strong>\r\n\r\n<strong>$ sudo chown prometheus:prometheus \/var\/lib\/prometheus<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"907\" height=\"214\" class=\"wp-image-11814\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-60.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-60.png 907w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-60-300x71.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-60-768x181.png 768w\" sizes=\"auto, (max-width: 907px) 100vw, 907px\" \/><\/strong><\/p>\n<h2><a id=\"post-11809-_kyb0f5s58o26\"><\/a><strong>Step 2: Download Prometheus<\/strong><\/h2>\n<p>Next, download the latest Prometheus archive file from Github or <a href=\"https:\/\/prometheus.io\/download\/\">Prometheus official page<\/a>. Execute the following wget command:<\/p>\n<pre><strong>$ wget <\/strong><strong>https:\/\/github.com\/prometheus\/prometheus\/releases\/download\/v2.21.0\/prometheus-2.31.0.linux-amd64.tar.gz<\/strong><\/pre>\n<p>Then, use the sha256sum command line to verify the integrity of the Prometheus archive file you just downloaded.<\/p>\n<pre><strong>$ sha256sum prometheus-2.31.0.linux-amd64.tar.gz<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"975\" height=\"98\" class=\"wp-image-11816\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-62.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-62.png 975w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-62-300x30.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-62-768x77.png 768w\" sizes=\"auto, (max-width: 975px) 100vw, 975px\" \/><\/strong><\/p>\n<p>Ensure that the result of the above command matches the SHA256 Checksum on the official Prometheus download page. It will guarantee that our file is authentic and not corrupted.<\/p>\n<p>Next, extract the contents of the archive file.<\/p>\n<pre><strong>$ tar -xvf prometheus-2.21.0.linux-amd64.tar.gz<\/strong><\/pre>\n<p>Navigate into the prometheus folder as shown:<\/p>\n<pre><strong>$ cd prometheus-2.21.0.linux-amd64<\/strong><\/pre>\n<p>Use the ls command to view the contents of the folder. You see two binary files (Prometheus and promtool), one prometheus.yml, two consoles, and console libraries directories containing the web interface files.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"729\" height=\"117\" class=\"wp-image-11822\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-67.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-67.png 729w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-67-300x48.png 300w\" sizes=\"auto, (max-width: 729px) 100vw, 729px\" \/><\/p>\n<h2><a id=\"post-11809-_k6ad86bh4eg3\"><\/a><strong>Step 3: Copy Prometheus Binary files<\/strong><\/h2>\n<p>As seen, the prometheus directory contains two binary files, Prometheus and promtool. Copy the binary files to \/usr\/local\/bin directory as shown:<\/p>\n<pre><strong>$ sudo cp prometheus-2.31.0.linux-amd64\/prometheus \/usr\/local\/bin\/<\/strong>\r\n\r\n<strong>$ sudo cp prometheus-2.31.0.linux-amd64\/promtool \/usr\/local\/bin\/<\/strong>\r\n<\/pre>\n<p>Next, set the user and group ownership on the binary files. Execute the commands:<\/p>\n<pre><strong>$ sudo chown prometheus:prometheus \/usr\/local\/bin\/prometheus<\/strong>\r\n\r\n<strong>$ sudo chown prometheus:prometheus \/usr\/local\/bin\/promtool<\/strong>\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"811\" height=\"97\" class=\"wp-image-11824\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-70.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-70.png 811w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-70-300x36.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-70-768x92.png 768w\" sizes=\"auto, (max-width: 811px) 100vw, 811px\" \/><\/strong><\/p>\n<h2><a id=\"post-11809-_48t2g72pecie\"><\/a><strong>Step 4: Copy Prometheus Console Libraries<\/strong><\/h2>\n<p>We also need to copy prometheus console and console_libraries directories to \/etc\/prometheus\/. Run:<\/p>\n<pre>\r\n<strong>$ sudo cp -r prometheus-2.31.0.linux-amd64\/consoles \/etc\/prometheus<\/strong>\r\n\r\n<strong>sudo cp -r prometheus-2.31.0.linux-amd64\/console_libraries \/etc\/prometheus<\/strong>\r\n\r\n<strong>$ sudo cp -r prometheus-2.31.0.linux-amd64\/prometheus.yml \/etc\/prometheus<\/strong>\r\n<\/pre>\n<p>Then, update the user and group ownership on the \/etc\/promotheus directory using the command below:<\/p>\n<pre>\r\n<strong>$ sudo chown -R prometheus:prometheus \/etc\/prometheus\/consoles<\/strong>\r\n\r\n<strong>$ sudo chown -R prometheus:prometheus \/etc\/prometheus\/console_libraries<\/strong>\r\n\r\n<strong>$ sudo chown -R prometheus:prometheus \/etc\/prometheus\/prometheus.yml<\/strong>\r\n<\/pre>\n<p>Prometheus has now been successfully installed on our system. Confirm the version installed with the command:<\/p>\n<pre>\r\n<strong>$ prometheus --version<\/strong>\r\n\r\n<strong>$ promtool --version<\/strong>\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"289\" class=\"wp-image-11832\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-75.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-75.png 960w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-75-300x90.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-75-768x231.png 768w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/strong><\/p>\n<h2><a id=\"post-11809-_rp4q8sgsc0js\"><\/a><strong> Step 5: Configure prometheus <\/strong><\/h2>\n<p><a id=\"post-11809-_6wrxz1ak9fpp\"><\/a>Next, open the prometheus default configuration file as shown below. You can modify the settings according to your preferences<\/p>\n<pre>\r\n<strong>$ cat \/etc\/prometheus\/prometheus.yml<\/strong>\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"1068\" height=\"598\" class=\"wp-image-11838\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-82.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-82.png 1068w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-82-300x168.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-82-1024x573.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-82-768x430.png 768w\" sizes=\"auto, (max-width: 1068px) 100vw, 1068px\" \/><\/strong><\/p>\n<h2><strong>Step 6: Create Prometheus Systemd file<\/strong><\/h2>\n<p>To launch Prometheus as a service, we must first configure it. We will specify a location for both the configuration file and the data directory as shown:<\/p>\n<pre>\r\n<strong>$ sudo -u prometheus \/usr\/local\/bin\/prometheus \\<\/strong>\r\n\r\n<strong> --config.file \/etc\/prometheus\/prometheus.yml \\<\/strong>\r\n\r\n<strong> --storage.tsdb.path \/var\/lib\/prometheus\/ \\<\/strong>\r\n\r\n<strong> --web.console.templates=\/etc\/prometheus\/consoles \\<\/strong>\r\n\r\n<strong> --web.console.libraries=\/etc\/prometheus\/console_libraries<\/strong>\r\n<\/pre>\n<p>Next, create a systemd file for Prometheus so that you can easily manage the service. Let\u2019s create a systemd file in \/etc\/systemd\/system directory as shown:<\/p>\n<pre>\r\n<strong>$ sudo nano \/etc\/systemd\/system\/prometheus.service<\/strong>\r\n<\/pre>\n<p>Next, copy the lines below to the systemd file.<\/p>\n<pre>\r\n<strong>[Unit]<\/strong>\r\n\r\n<strong>Description=Prometheus<\/strong>\r\n\r\n<strong>Wants=network-online.target<\/strong>\r\n\r\n<strong>After=network-online.target<\/strong>\r\n\r\n<strong>[Service]<\/strong>\r\n\r\n<strong>User=prometheus<\/strong>\r\n\r\n<strong>Group=prometheus<\/strong>\r\n\r\n<strong>Type=simple<\/strong>\r\n\r\n<strong>ExecStart=\/usr\/local\/bin\/prometheus \\<\/strong>\r\n\r\n<strong> --config.file \/etc\/prometheus\/prometheus.yml \\<\/strong>\r\n\r\n<strong> --storage.tsdb.path \/var\/lib\/prometheus\/ \\<\/strong>\r\n\r\n<strong> --web.console.templates=\/etc\/prometheus\/consoles \\<\/strong>\r\n\r\n<strong> --web.console.libraries=\/etc\/prometheus\/console_libraries<\/strong>\r\n\r\n<strong>[Install]<\/strong>\r\n\r\n<strong>WantedBy=multi-user.target<\/strong>\r\n<\/pre>\n<p>Save and close the file.<\/p>\n<p>Next, reload the daemon services for the changes to be applied. Run:<\/p>\n<pre>\r\n<strong>$ sudo systemctl daemon-reload<\/strong>\r\n<\/pre>\n<p>Then, start and enable Prometheus service with the following commands:<\/p>\n<pre>\r\n<strong>$ sudo systemctl start prometheus<\/strong>\r\n\r\n<strong>$ sudo systemctl enable prometheus<\/strong>\r\n<\/pre>\n<p>Now check the status of Prometheus with the command:<\/p>\n<pre>\r\n<strong>$ sudo systemctl status prometheus<\/strong>\r\n<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"1453\" height=\"396\" class=\"wp-image-11846\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-91.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-91.png 1453w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-91-300x82.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-91-1024x279.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-91-768x209.png 768w\" sizes=\"auto, (max-width: 1453px) 100vw, 1453px\" \/><\/strong><\/p>\n<p>Prometheus is now up and running.<\/p>\n<h2><a id=\"post-11809-_hzg6vqskbpot\"><\/a><strong>Step 7: Accessing Prometheus<\/strong><\/h2>\n<p>Now that Prometheus has been configured successfully, we can access it through the web interface. Also, make sure that port 9090 is enabled in the firewall. To allow the prometheus service in the firewall, run:<\/p>\n<pre>\r\n<strong>$ sudo ufw allow 9090\/tcp<\/strong>\r\n<\/pre>\n<p>Open a web browser and access Prometheus as shown below:<\/p>\n<pre>\r\n<strong>$ http:\/\/server-IP:9090.<\/strong>\r\n<\/pre>\n<p>You will see the following screen.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1362\" height=\"833\" class=\"wp-image-11850\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-94.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-94.png 1362w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-94-300x183.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-94-1024x626.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/11\/word-image-94-768x470.png 768w\" sizes=\"auto, (max-width: 1362px) 100vw, 1362px\" \/><\/p>\n<p>Prometheus is now running on Ubuntu 20.04 system. You can now start monitoring your system performance and metrics.<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>Prometheus is a system monitoring tool used for recording real-time metrics and system performance in a time-series database. It is open-source software that was originally developed at SoundCloud&hellip;<\/p>","protected":false},"author":1,"featured_media":11853,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-11809","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/11809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=11809"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/11809\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/11853"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=11809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=11809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=11809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}