GNU/Linux >> Linux Esercitazione >  >> Cent OS

Installa Prometheus e Node Exporter su CentOS / RHEL 8

Prometheus è un'applicazione software gratuita utilizzata per il monitoraggio e gli avvisi di eventi. Registra le metriche in tempo reale in un database di serie temporali creato utilizzando un modello pull HTTP, con query flessibili e avvisi in tempo reale. Il progetto è scritto in Go e concesso in licenza con la Licenza Apache 2 , con codice sorgente disponibile su GitHub, ed è un progetto graduale della Cloud Native Computing Foundation , insieme a Kubernetes e Envoy.

Aggiorna sistema

Aggiorna il tuo sistema operativo Linux con

# dnf update -y

Prometheus attualmente non include una politica SELinux ufficiale. Quindi devi disabilitare SELinux o impostalo in modalità permissiva.

# sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/sysconfig/selinux
# setenforce permissive

Crea utenti e directory Prometheus

Possedere software e processi Prometheus.

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

Crea le directory Prometheus richieste e modifica la proprietà.

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

Installa Prometeo

Puoi scaricarlo dal sito ufficiale di Prometheus.

Scarica Prometheus tarball con wget comando come segue.

[root@unixcop ~]#  wget https://github.com/prometheus/prometheus/releases/download/v2.29.2/prometheus-2.29.2.linux-amd64.tar.gz -P /tmp
--2021-09-09 11:02:11--  https://github.com/prometheus/prometheus/releases/download/v2.29.2/prometheus-2.29.2.linux-amd64.tar.gz
Resolving github.com (github.com)... 140.82.121.3
Connecting to github.com (github.com)|140.82.121.3|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-releases.githubusercontent.com/6838921/17d3d453-5a8e-47aa-844f-d4ff56f5c1cb?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210909%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210909T150118Z&X-Amz-Expires=300&X-Amz-Signature=04f95de9924949000d3cf5b51d508db4a101e6741d13540d60b0b8c7618421bc&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=6838921&response-content-disposition=attachment%3B%20filename%3Dprometheus-2.29.2.linux-amd64.tar.gz&response-content-type=application%2Foctet-stream [following]
--2021-09-09 11:02:13--  https://github-releases.githubusercontent.com/6838921/17d3d453-5a8e-47aa-844f-d4ff56f5c1cb?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210909%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210909T150118Z&X-Amz-Expires=300&X-Amz-Signature=04f95de9924949000d3cf5b51d508db4a101e6741d13540d60b0b8c7618421bc&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=6838921&response-content-disposition=attachment%3B%20filename%3Dprometheus-2.29.2.linux-amd64.tar.gz&response-content-type=application%2Foctet-stream
Resolving github-releases.githubusercontent.com (github-releases.githubusercontent.com)... 185.199.111.154, 185.199.108.154, 185.199.110.154, ...
Connecting to github-releases.githubusercontent.com (github-releases.githubusercontent.com)|185.199.111.154|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 73175122 (70M) [application/octet-stream]
Saving to: 'https://1118798822.rsc.cdn77.org/tmp/prometheus-2.29.2.linux-amd64.tar.gz'

prometheus-2.29.2.linux-amd64.tar.gz  100%[=======================================================================>]  69.79M   169KB/s    in 6m 30s  

2021-09-09 11:08:43 (183 KB/s) - 'https://1118798822.rsc.cdn77.org/tmp/prometheus-2.29.2.linux-amd64.tar.gz' saved [73175122/73175122]

[root@unixcop ~]#

Quindi estrai il tarball di Prometheus scaricato in /var/lib/prometheus come mostrato.

tar -xf /tmp/prometheus-2.29.2.linux-amd64.tar.gz -C /var/lib/prometheus/ --strip-components=1

Assegna la proprietà dei file estratti all'utente Prometheus con:

chown -R prometheus:prometheus /var/lib/prometheus

Sposta il file di configurazione di Prometheus in /etc/prometheus con:

mv /var/lib/prometheus/prometheus.yml /etc/prometheus/

Controlla anche le configurazioni del file prometheus.yml come mostrato di seguito:

[root@unixcop ~]# grep -v '#' /etc/prometheus/prometheus.yml
global:

alerting:
  alertmanagers:
    - static_configs:
        - targets:

rule_files:

scrape_configs:
  - job_name: "prometheus"


    static_configs:
      - targets: ["localhost:9090"]
[root@unixcop ~]#

Crea anche collegamenti simbolici per Prometheus per renderli eseguibili da qualsiasi percorso.

# cp -s /var/lib/prometheus/promtool /usr/bin
# cp -s /var/lib/prometheus/prometheus /usr/bin

Crea unità di servizio Systemd per Prometheus

È necessario creare un'unità di servizio systemd per abilitare un avvio automatico di Prometheus.

Segui questi passaggi:

# vim /usr/lib/systemd/system/prometheus.service

Quindi aggiungi quanto segue.

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

[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/var/lib/prometheus/consoles \
--web.console.libraries=/var/lib/prometheus/console_libraries

[Install]
WantedBy=multi-user.target

Quindi abilita e avvia Prometheus con:

[root@unixcop ~]# systemctl enable --now prometheus.service
Created symlink /etc/systemd/system/multi-user.target.wants/prometheus.service → /usr/lib/systemd/system/prometheus.service.
[root@unixcop ~]#

Configura anche Firewall per Prometheus

La porta predefinita 9090/tcp . Quindi è necessario consentirlo.

[root@unixcop ~]# firewall-cmd --permanent --add-port=9090/tcp
success
[root@unixcop ~]# firewall-cmd --reload
success
[root@unixcop ~]#

Apri l'URL http://localhost:9090 in un browser web come mostrato nell'immagine sottostante

Installa Esportatore nodi

Node Exporter è un esportatore Prometheus per metriche di livello e server con raccoglitori di metriche configurabili. Ci aiuta a misurare le risorse del server come spazio su disco, RAM e utilizzo della CPU.

Devi installare node_exporter sul tuo server Prometheus .

Innanzitutto, crea una directory per Node Exporter come segue:

# mkdir -p /var/lib/prometheus/node_exporter

Scarica Node_Exporter dal sito web di Prometheus.

[root@unixcop ~]# wget https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz -P /tmp
--2021-09-09 11:42:18--  https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz
Resolving github.com (github.com)... 140.82.121.4
Connecting to github.com (github.com)|140.82.121.4|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-releases.githubusercontent.com/9524057/28598a7c-d8ad-483d-85ba-8b2c9c08cf57?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210909%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210909T154012Z&X-Amz-Expires=300&X-Amz-Signature=2581f24124ad04eeb9d7ead72729c4afbcfe08ade2e37a8d3ffa0eb876ab0091&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=9524057&response-content-disposition=attachment%3B%20filename%3Dnode_exporter-1.2.2.linux-amd64.tar.gz&response-content-type=application%2Foctet-stream [following]
--2021-09-09 11:42:19--  https://github-releases.githubusercontent.com/9524057/28598a7c-d8ad-483d-85ba-8b2c9c08cf57?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210909%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210909T154012Z&X-Amz-Expires=300&X-Amz-Signature=2581f24124ad04eeb9d7ead72729c4afbcfe08ade2e37a8d3ffa0eb876ab0091&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=9524057&response-content-disposition=attachment%3B%20filename%3Dnode_exporter-1.2.2.linux-amd64.tar.gz&response-content-type=application%2Foctet-stream
Resolving github-releases.githubusercontent.com (github-releases.githubusercontent.com)... 185.199.108.154, 185.199.110.154, 185.199.109.154, ...
Connecting to github-releases.githubusercontent.com (github-releases.githubusercontent.com)|185.199.108.154|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8898481 (8.5M) [application/octet-stream]
Saving to: 'https://1118798822.rsc.cdn77.org/tmp/node_exporter-1.2.2.linux-amd64.tar.gz'

node_exporter-1.2.2.linux-amd64.tar.g 100%[=======================================================================>]   8.49M   204KB/s    in 42s     

2021-09-09 11:43:02 (207 KB/s) - 'https://1118798822.rsc.cdn77.org/tmp/node_exporter-1.2.2.linux-amd64.tar.gz' saved [8898481/8898481]

[root@unixcop ~]#

Quindi estrai il tarball scaricato in /var/lib/prometheus/node_exporter/ con il seguente comando.

# tar xf /tmp/node_exporter-1.2.2.linux-amd64.tar.gz -C /var/lib/prometheus/unixcop_node_exporter/ --strip-components=1

Modifica la proprietà.

# chown -R prometheus:prometheus /var/lib/prometheus/unixcop_node_exporter/

Crea anche un collegamento simbolico per node_exporter con:

[root@unixcop ~]# cp -s /var/lib/prometheus/unixcop_node_exporter/node_exporter /usr/bin/

Abilita l'avvio automatico di node_exporter processo, creare un'unità di servizio systemd.

vim /usr/lib/systemd/system/unixcop_node_exporter.service

Quindi aggiungi quanto segue:

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

[Service]
User=prometheus
ExecStart=/usr/bin/node_exporter

[Install]
WantedBy=default.target

Abilita e avvia Node Exporter con il comando seguente:

[root@unixcop ~]# systemctl enable --now unixcop_node_exporter.service
Created symlink /etc/systemd/system/default.target.wants/node_exporter.service → /usr/lib/systemd/system/node_exporter.service.
[root@unixcop ~]#

Configura anche il firewall per consentire la porta node_exporter 9100/tcp .

[root@unixcop ~]# firewall-cmd --permanent --add-port=9100/tcp
success
[root@unixcop ~]# firewall-cmd --reload
success
[root@unixcop ~]#

Quindi modifica il file di configurazione di Prometheus.

# vi /etc/prometheus/prometheus.yml

E aggiungi unixcop_node_exporter configurazione dell'endpoint in questo file.

 - job_name: 'unixcop_node_exporter'
    static_configs:
    - targets: ['localhost:9100']

Quindi riavvia Prometeo.

# systemctl restart prometheus.service

Apri il browser, quindi vai su Prometeo.

Apri Stato

Quindi fai clic su Target .

Conclusione

In questo articolo, abbiamo spiegato come installare lo strumento di monitoraggio dei sistemi Prometheus su CentOS / RHEL 8.

Inoltre abbiamo illustrato come installare Node Exporter per le metriche a livello di server e livello che ci aiutano a misurare le risorse del server come lo spazio su disco, la RAM e l'utilizzo della CPU.


Cent OS
  1. Come installare Node.js e NPM su CentOS 7

  2. Come installare Node.js e NPM su CentOS

  3. Come installare Python 3.5 su CentOS/RHEL e Fedora

  4. CentOS / RHEL 7 :Come installare e configurare telnet

  5. Come installare e configurare Samba in CentOS/RHEL

Come installare Node.js su CentOS 7 / RHEL 7

Come installare e configurare Prometheus su CentOS 7

Come installare e utilizzare Firewalld in CentOS/RHEL

Come installare Samba su RHEL e CentOS Stream

Come installare e configurare Jenkins su CentOS 8 / RHEL 8

Come installare Wine 5.0 su CentOS, RHEL e Fedora