{"id":3155,"date":"2019-05-29T21:43:09","date_gmt":"2019-05-29T18:43:09","guid":{"rendered":"https:\/\/kifarunix.com\/?p=3155"},"modified":"2020-02-08T20:26:09","modified_gmt":"2020-02-08T17:26:09","slug":"install-prometheus-on-ubuntu-18-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-prometheus-on-ubuntu-18-04\/","title":{"rendered":"Install Prometheus on Ubuntu 18.04"},"content":{"rendered":"\n
In this guide, we are going to learn how to install Prometheus on Ubuntu 18.04. Prometheus<\/a> is an open-source systems and service monitoring system. It collects metrics from configured targets via HTTP calls at given intervals, evaluates rule expressions, displays the results, and can trigger alerts if some conditions are met.<\/p>\n\n\n\n We have covered the installation of Prometheus on Debian 9 and Fedora 29\/28 in our previous guides;<\/p>\n\n\n\n Install and Configure Prometheus on Fedora 29\/Fedora 28<\/a><\/p>\n\n\n\n Install and Configure Prometheus on Debian 9<\/a><\/p>\n\n\n\n Prometheus is made up various components;<\/p>\n\n\n\n Prometheus and its other components are available on the default Ubuntu 18.04 repositories. However, the available versions may not be up-to-date. You can verify the available versions by running the command below;<\/p>\n\n\n\n To ensure that you got the latest versions of Prometheus installed, you can use the pre-compiled binaries which can be downloaded directly from Prometheus downloads section<\/a>.<\/p>\n\n\n\n Before you can begin the installation, you have to create Prometheus system user and group as shown below;<\/p>\n\n\n\n Next, you need to create the directories that will be used to store Prometheus configurations files and other data.<\/p>\n\n\n\n Next, navigate to the downloads section and grab the latest version of Prometheus. You simply use wget to download it.<\/p>\n\n\n\n Once you have downloaded the binary, extract it and proceed to install it as follows.<\/p>\n\n\n\n Next, copy the prometheus<\/strong> and promtool<\/strong> binaries under the extracted archive folder to After copying, set the user and group ownership of these binaries to prometheus<\/strong>.<\/p>\n\n\n\n Next, copy the The default Prometheus configuration file is located on the extracted archive folder. For the demonstration purposes, we will just copy it to Prometheus configuration directory and modify it as follows;<\/p>\n\n\n\n In the default configuration there is a single job, called prometheus<\/strong> , which scrapes the time series data exposed<\/strong> by the Prometheus<\/strong> server. The job contains a single, statically configured, target, the localhost on port 9090<\/strong>.<\/p>\n\n\n\n Next, set the user and group ownership of Prometheus configuration directory, \/etc\/prometheus<\/strong> to prometheus<\/strong>.<\/p>\n\n\n\n Once that is done, similarly set the user and group ownership of Prometheus data directory, \/var\/lib\/prometheus\/<\/strong> to prometheus<\/strong>.<\/p>\n\n\n\n At the very least, Prometheus is now set and is ready to run. However, at this point we do not have the Prometheus service configuration file and hence, we can run it as shown below;<\/p>\n\n\n\n To be able to run prometheus as a service, you can create a systemd service configuration file as shown below;<\/p>\n\n\n\n Next, reload systemd configuration files and start and enable Prometheus to run on system boot.<\/p>\n\n\n\n To check the status of Prometheus service;<\/p>\n\n\n\n You can now access Prometheus using the address, http:\/\/<server_IP>:9090<\/strong>. This will take you to Prometheus’s built-in expression browser.<\/p>\n\n\n\n The scraped metrics can be viewed under, http:\/\/<server_IP>:9090\/metrics<\/strong>.<\/p>\n\n\n\n To check the status of your node, navigate to Status<\/strong> > Targets<\/strong>.<\/p>\n\n\n\n Well, that is just about it on how to install Prometheus on Ubuntu 18.04. Want to learn how to monitor Linux hosts with Prometheus Node Exporter? Check the link below;<\/p>\n\n\n\n Monitor Linux System Metrics with Prometheus Node Exporter<\/a><\/p>\n\n\n\n Check our related articles by following the links below;<\/p>\n\n\n\n Install Graylog 3.0 on CentOS 7<\/a><\/p>\n\n\n\n Monitor Squid Access Logs with Graylog Server<\/a><\/p>\n\n\n\n Monitor Squid logs with Grafana and Graylog<\/a><\/p>\n\n\n\n Install Grafana 6.2.x on Ubuntu 18.04\/Debian 9<\/a><\/p>\n\n\n\nInstall Prometheus on Ubuntu 18.04<\/h2>\n\n\n\n
apt-cache policy prometheus\nprometheus:\n Installed: (none)\n Candidate: 2.1.0+ds-1\n Version table:\n 2.1.0+ds-1 500\n 500 http:\/\/ke.archive.ubuntu.com\/ubuntu bionic\/universe amd64 Packages<\/code><\/pre>\n\n\n\n
Install Prometheus Using Pre-compiled Binaries<\/h3>\n\n\n\n
Create Prometheus System User and Group<\/h4>\n\n\n\n
useradd -M -r -s \/bin\/false prometheus<\/code><\/pre>\n\n\n\n
Create Prometheus Directories<\/h4>\n\n\n\n
mkdir \/etc\/prometheus \/var\/lib\/prometheus<\/code><\/pre>\n\n\n\n
Download Prometheus Binary<\/h4>\n\n\n\n
wget https:\/\/github.com\/prometheus\/prometheus\/releases\/download\/v2.10.0\/prometheus-2.10.0.linux-amd64.tar.gz<\/code><\/pre>\n\n\n\n
Install Prometheus on Ubuntu 18.04<\/h4>\n\n\n\n
tar xzf prometheus-2.10.0.linux-amd64.tar.gz<\/code><\/pre>\n\n\n\n
\/usr\/local\/bin<\/code> directory.<\/p>\n\n\n\n
cp prometheus-2.10.0.linux-amd64\/{prometheus,promtool} \/usr\/local\/bin\/<\/code><\/pre>\n\n\n\n
chown prometheus:prometheus \/usr\/local\/bin\/{prometheus,promtool}<\/code><\/pre>\n\n\n\n
consoles<\/code> and
console_libraries<\/code> directories to
\/etc\/prometheus<\/code>.<\/p>\n\n\n\n
cp -r prometheus-2.10.0.linux-amd64\/{consoles,console_libraries} \/etc\/prometheus\/<\/code><\/pre>\n\n\n\n
Create Prometheus Configuration file<\/h4>\n\n\n\n
cp prometheus-2.10.0.linux-amd64\/prometheus.yml \/etc\/prometheus\/prometheus.yml<\/code><\/pre>\n\n\n\n
less \/etc\/prometheus\/prometheus.yml\nglobal:\n scrape_interval: 15s\n evaluation_interval: 15s\n\nrule_files:\n\nscrape_configs:\n - job_name: 'prometheus'\n static_configs:\n - targets: ['localhost:9090']<\/code><\/pre>\n\n\n\n
chown -R prometheus:prometheus \/etc\/prometheus<\/code><\/pre>\n\n\n\n
chown prometheus:prometheus \/var\/lib\/prometheus<\/code><\/pre>\n\n\n\n
Running Prometheus<\/h4>\n\n\n\n
prometheus --config.file=\/etc\/prometheus\/prometheus.yml<\/code><\/pre>\n\n\n\n
Create Prometheus Systemd Service File<\/h4>\n\n\n\n
vim \/etc\/systemd\/system\/prometheus.service<\/code><\/pre>\n\n\n\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\n\n\n
systemctl daemon-reload\nsystemctl start prometheus\nsystemctl enable prometheus<\/code><\/pre>\n\n\n\n
systemctl status prometheus<\/code><\/pre>\n\n\n\n
\u25cf 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) since Wed 2019-05-29 18:56:28 EAT; 8s ago\n Main PID: 15835 (prometheus)\n Tasks: 7 (limit: 1130)\n CGroup: \/system.slice\/prometheus.service\n \u2514\u250015835 \/usr\/local\/bin\/prometheus --config.file \/etc\/prometheus\/prometheus.yml --storage.tsdb.path \/var\/lib\/prometheus\/ --web.console.templa...<\/code><\/pre>\n\n\n\n
Access Prometheus Web Interface<\/h3>\n\n\n\n
<\/a><\/figure>\n\n\n\n
<\/a><\/figure>\n\n\n\n
<\/a><\/figure>\n\n\n\n