How to install Prometheus 2.30.3 Server in Ubuntu 20.04

In this guide, we will learn how to install the Prometheus server on Ubuntu 20.04. Prometheus is an open-source system monitoring and alerting toolkit. Prometheus collects and stores its metrics as time-series data. Metrics information is stored with the timestamp at which it was recorded, alongside optional key-value pairs called labels.

And now you are wondering what are metrics? Metrics are numeric measurements and time series mean that the changes are recorded over time.

Components

  • Has an alertmanager to handle alerts
  • Has a push gateway for supporting short-lived jobs
  • Has main Prometheus server which scrapes and stores time series data
  • Client libraries for instrumenting application code
  • Special purpose exporters for services like HAProxy, statD, Graphite etc

Related Article

Install Prometheus 2.30

Let us update the system first:

$ sudo apt update

Download and install Prometheus

Download the latest release of 2.30.3 into our system.

$ wget https://github.com/prometheus/prometheus/releases/download/v2.30.3/prometheus-2.30.3.linux-amd64.tar.gz

After the download is complete, the next step is to extract the archive:

$ tar xvf prometheus-2.30.3.linux-amd64.tar.gz

For convenience, we can change the directory for the extracted archive

$ cd prometheus-2.30.3.linux-amd64

From there we can create a configuration file directory

$ sudo mkdir -p /etc/prometheus

Then we can create the data directory

$sudo mkdir -p /var/lib/prometheus

Let’s now move the binary files Prometheus and promtool to /usr/local/bin/

Use the following code snippet

$ sudo mv prometheus promtool /usr/local/bin/

Move the template configuration file prometheus.yml to /etc/prometheus/ directory

$ sudo mv prometheus.yml /etc/prometheus/prometheus.yml

We have installed Prometheus. Lets verify the version

$ prometheus --version

Create Prometheus System group

The following code can help create the Prometheus system group.

$ sudo groupadd --system prometheus

We can then create Prometheus system user and assign the primary group created

$ sudo useradd -s /sbin/nologin --system -g prometheus prometheus

Set the ownership of Prometheus files and data directories to the Prometheus group and user.

$ sudo chown -R prometheus:prometheus /etc/prometheus/  /var/lib/prometheus/

$ sudo chmod -R 775 /etc/prometheus/ /var/lib/prometheus/

Lastly, we can create a systemd service to run at boot time

$ sudo nano /etc/systemd/system/prometheus.service

Add the following content to prometheus.service

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Restart=always
Type=simple
ExecStart=/usr/local/bin/prometheus \
    --config.file=/etc/prometheus/prometheus.yml \
    --storage.tsdb.path=/var/lib/prometheus/ \
    --web.console.templates=/etc/prometheus/consoles \
    --web.console.libraries=/etc/prometheus/console_libraries \
    --web.listen-address=0.0.0.0:9090

[Install]
WantedBy=multi-user.target

Start the Prometheus service

$ sudo systemctl start prometheus

Now we can check if our Prometheus is up and running

$ sudo systemctl status prometheus

Add firewall rules to allow Prometheus to run on TCP port 9090

$ ufw allow 9090/tcp

Access your server from the browser.

http://or:9090

for example

http://192.0.1.1:9090

Conclusion

Congratulations! you have successfully installed Prometheus on Ubuntu 20.04. To read more consult Prometheus documentation.

Leave a Reply

Your email address will not be published.