Indonesia Website Awards
Indonesia Website Awards

Quoted from Wikipedia – “Prometheus is a free software application used for event monitoring and alerting. It records real-time metrics in a time series database (allowing for high dimensionality) built using a HTTP pull model, with flexible queries and real-time alerting. The project is written in Go and licensed under the Apache 2 License, with source code available on GitHub, and is a graduated project of the Cloud Native Computing Foundation, along with Kubernetes and Envoy” Therefore, here I want to share information about how to install Prometheus on Linux, let’s see:

1. Install prometheus on linux

1.1. Install prometheus on linux CentOS 7

Preparation & Install Prometheus

  • Create user for prometheus (without home directory)

useradd --no-create-home --shell /bin/false prometheus

  • Create folder for prometheus library
mkdir /etc/prometheus
mkdir /var/lib/prometheus
  • Set folder ownership for prometheus user
chown prometheus:prometheus /etc/prometheus
chown prometheus:prometheus /var/lib/prometheus
  • Download and ekstract prometheus
curl -LO https://github.com/prometheus/prometheus/releases/download/v2.19.2/prometheus-2.19.2.linux-amd64.tar.gz
tar xzvf prometheus-2.19.2.linux-amd64.tar.gz

/* note : adjust the version and type of your linux */
  • Copy prometheus and promtool to bin directory
cp prometheus-2.19.2.linux-amd64/prometheus /usr/local/bin
cp prometheus-2.19.2.linux-amd64/promtool /usr/local/bin
  • Set folder ownership for prometheus user
chown prometheus:prometheus /usr/local/bin/prometheus
chown prometheus:prometheus /usr/local/bin/promtool
  • Copy console and console_libraries into prometheus directory
cp -r prometheus-2.19.2.linux-amd64/consoles /etc/prometheus
cp -r prometheus-2.19.2.linux-amd64/console_libraries /etc/prometheus
  • Set console and console_libraries ownership for prometheus user
chown -R prometheus:prometheus /etc/prometheus/consoles
chown -R prometheus:prometheus /etc/prometheus/console_libraries

 

Prometheus Configuration

  • Create prometheus configuration file with the extension .yml

vim /etc/prometheus/prometheus.yml

  • Fill in prometheus.yml file, fill in the target section with the server IP address
global:
  scrape_interval: 15s
scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['IP_ADDR:9090']
  • Set ownership of prometheus.yml file for prometheus user

chown prometheus:prometheus /etc/prometheus/prometheus.yml

 

Prometheus Service

  • Create service for prometheus

vim /etc/systemd/system/prometheus.service

  • Fill in prometheus.service file with this config
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
 
[Service]
User=prometheus
Group=prometheus
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
 
[Install]
WantedBy=multi-user.target
  • Reload the daemon to register prometheus.service

systemctl daemon-reload

  • Activate Prometheus service and check the status
systemctl enable prometheus
systemctl start prometheus
systemctl status prometheus

 

1.2. Install prometheus on linux Ubuntu

For prometheus installation on Ubuntu, the method is same as for installing on CentOS 7, so you can follow the method described above 😀

 

2. Allow ports on firewall (optional)

If you manage your port access with a firewall, you need to open port 9090 for prometheus access. Here are several ways to open a port for prometheus :

  • allow ports on ufw firewall

sudo ufw allow 9090/tcp

  • mengizinkan ports di iptables
iptables -A INPUT -p tcp --dport 9090 -j ACCEPT
iptables-save | sudo tee /etc/sysconfig/iptables
systemctl restart iptables

3. Access prometheus

At this point, Prometheus should have been successfully installed. Good job! Then we can access prometheus at http://IP_ADDR:9090. It will look like this :

how to install prometheus on linux

Prometheus

Then to see what metrics are available and usable, you can access them at http://IP_ADDR:9090/metrics. It will look like this :

prometheus metrics

Prometheus Metrics

 

Okay, I think you have successfully installed and accessed the prometheus. In my next article I will discuss how to install node_exporter on linux. node_exporter is one of the exporters of metrics data which we can use on prometheus. Then after that I will also make an article where I combine grafana, prometheus and node_exporter to perform real-time server monitoring. Thank you all 😀

 

Also Read :

 


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *