Skip to content

Latest commit

 

History

History
132 lines (115 loc) · 3.22 KB

11.prometheus_installation.md

File metadata and controls

132 lines (115 loc) · 3.22 KB

🟥 Prometheus installation on Centos/Ubuntu Linux

for ubuntu

# apt update -y

or

for centos

#  yum update -y

Download the latest prometheus

# wget https://github.com/prometheus/prometheus/releases/download/v2.44.0/prometheus-2.44.0.linux-amd64.tar.gz

# tar -xvf prometheus-2.44.0.linux-amd64.tar.gz

rename the prometheus-2.44.0.linux-amd64 to prometheus-files

# mv prometheus-2.44.0.linux-amd64 prometheus-files

Add a Prometheus user

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

create necessary directories

# mkdir /etc/prometheus
# mkdir /var/lib/prometheus
# groupadd prometheus

Change the owner of the above directories

# chown prometheus:prometheus /etc/prometheus
# chown prometheus:prometheus /var/lib/prometheus

Copy prometheus and promtool binary from prometheus-files folder to /usr/local/bin and change the ownership to prometheus user

# cp prometheus-files/prometheus /usr/local/bin/
# cp prometheus-files/promtool /usr/local/bin/
# chown prometheus:prometheus /usr/local/bin/prometheus
# chown prometheus:prometheus /usr/local/bin/promtool

Move the consoles and console_libraries directories from prometheus-files to /etc/prometheus folder and change the ownership to prometheus user

# cp -r prometheus-files/consoles /etc/prometheus
# cp -r prometheus-files/console_libraries /etc/prometheus
# chown -R prometheus:prometheus /etc/prometheus/consoles
# chown -R prometheus:prometheus /etc/prometheus/console_libraries

Setup Prometheus Configuration Create the prometheus.yml file.

# vim /etc/prometheus/prometheus.yml
global:
  scrape_interval: 10s

scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'prometheus_server'
    scrape_interval: 5s
    static_configs:
      - targets: ['172.105.63.95:9100']

  - job_name: 'client_1'
    scrape_interval: 5s
    static_configs:
      - targets: ['172.105.63.114:9100']
      
  - job_name: 'client_2'
    scrape_interval: 5s
    static_configs:
      - targets: ['172.105.63.116:9100']
      
  - job_name: 'client_3'
    scrape_interval: 5s
    static_configs:
      - targets: ['15.207.139.147:9100']

:wq! save and exit

Change the ownership of the file to prometheus user

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

Setup Prometheus Service File Create a prometheus service file.

# vim /etc/systemd/system/prometheus.service
[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/ \
       --storage.tsdb.retention.time=7d \
       --storage.tsdb.retention.size=8GB \
       --web.console.templates=/etc/prometheus/consoles \
       --web.console.libraries=/etc/prometheus/console_libraries

[Install]
WantedBy=multi-user.target

:wq! save and exit
# systemctl daemon-reload
# systemctl start prometheus
# systemctl enable prometheus
# systemctl status prometheus

access the prometheus UI on 9090 port
http://xx.xx.xx.xx:9090/graph
xx.xx.xx.xx prometheus server ip