Ricerca nel sito web

Come installare Grafana 8 Monitoring Tool su Debian 11


Su questa pagina

  1. Prerequisiti
  2. Per iniziare
  3. Installa Grafana 8
  4. Installa Nginx come proxy inverso per Grafana
  5. Accedi alla dashboard di Grafana
  6. Proteggi Grafana con Lets Encrypt
  7. Conclusione

Grafana è uno strumento di visualizzazione dei dati gratuito e open source che viene utilizzato per monitorare le metriche da altri host. È scritto in Typescript and Go e consente di creare e modificare grafici sia di log che di dati e creare metriche. Può generare grafici e dashboard da un database di serie temporali tra cui Graphite, InfluxDB o OpenTSDB e consente di condividerli con altri utenti.

Caratteristiche

  • Modelli di dashboard
  • Annotazioni di provisioning
  • Modalità chiosco e playlist
  • Plugin personalizzati
  • Avvisi e ganci di avviso

In questo post, ti mostreremo come installare Grafana 8 su Debian 11.

Prerequisiti

  • Un server che esegue Debian 11.
  • Un nome di dominio valido indicato con l'IP del tuo server.
  • Sul server è configurata una password di root.

Iniziare

Prima di iniziare, si consiglia di aggiornare il sistema alla versione aggiornata. Puoi aggiornare tutti i pacchetti usando il seguente comando:

apt-get update -y

Dopo aver aggiornato tutti i pacchetti, installa le altre dipendenze richieste utilizzando il seguente comando:

apt-get install gnupg2 curl wget git software-properties-common -y

Una volta installati tutti i pacchetti, puoi procedere al passaggio successivo.

Installa Grafana 8

Per impostazione predefinita, Grafana non è incluso nel repository predefinito di Debian 11. Quindi dovrai aggiungere il repository Grafana all'APT. Puoi aggiungerlo usando il seguente comando:

curl https://packages.grafana.com/gpg.key | apt-key add -
add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"

Una volta aggiunto il repository, aggiorna la cache del repository e installa Grafana utilizzando il seguente comando:

apt-get update -y
apt-get install grafana -y

Una volta installato Grafana, avvia e abilita il servizio Grafana utilizzando il seguente comando:

systemctl start grafana-server
systemctl enable grafana-server

Puoi anche controllare lo stato del servizio Grafana con il seguente comando:

systemctl status grafana-server

Otterrai il seguente output:

? grafana-server.service - Grafana instance
     Loaded: loaded (/lib/systemd/system/grafana-server.service; disabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-02-04 04:08:25 UTC; 5s ago
       Docs: http://docs.grafana.org
   Main PID: 8602 (grafana-server)
      Tasks: 9 (limit: 2341)
     Memory: 29.6M
        CPU: 1.299s
     CGroup: /system.slice/grafana-server.service
             ??8602 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/run/grafana/grafana-server.pid --packaging=deb cfg:>

Feb 04 04:08:27 debian11 grafana-server[8602]: t=2022-02-04T04:08:27+0000 lvl=info msg="migrations completed" logger=migrator performed=381 s>
Feb 04 04:08:27 debian11 grafana-server[8602]: t=2022-02-04T04:08:27+0000 lvl=info msg="Created default admin" logger=sqlstore user=admin
Feb 04 04:08:27 debian11 grafana-server[8602]: t=2022-02-04T04:08:27+0000 lvl=info msg="Created default organization" logger=sqlstore
Feb 04 04:08:27 debian11 grafana-server[8602]: t=2022-02-04T04:08:27+0000 lvl=info msg="Initialising plugins" logger=plugin.manager
Feb 04 04:08:27 debian11 grafana-server[8602]: t=2022-02-04T04:08:27+0000 lvl=info msg="Plugin registered" logger=plugin.manager pluginId=inp>
Feb 04 04:08:27 debian11 grafana-server[8602]: t=2022-02-04T04:08:27+0000 lvl=info msg="Live Push Gateway initialization" logger=live.push_ht>
Feb 04 04:08:27 debian11 grafana-server[8602]: t=2022-02-04T04:08:27+0000 lvl=info msg="Writing PID file" logger=server path=/run/grafana/gra>
Feb 04 04:08:27 debian11 grafana-server[8602]: t=2022-02-04T04:08:27+0000 lvl=info msg="HTTP Server Listen" logger=http.server address=[::]:3>
Feb 04 04:08:27 debian11 grafana-server[8602]: t=2022-02-04T04:08:27+0000 lvl=info msg="warming cache for startup" logger=ngalert
Feb 04 04:08:27 debian11 grafana-server[8602]: t=2022-02-04T04:08:27+0000 lvl=info msg="starting MultiOrg Alertmanager" logger=ngalert.multio>

Per impostazione predefinita, Grafana è in ascolto sulla porta 3000. Puoi verificarlo con il seguente comando:

ss -antpl | grep 3000

Otterrai il seguente output:

LISTEN 0      4096               *:3000            *:*    users:(("grafana-server",pid=8602,fd=8))               

Installa Nginx come proxy inverso per Grafana

Successivamente, dovrai installare e configurare Nginx come proxy inverso per Grafana. Innanzitutto, installa Nginx usando il seguente comando:

apt-get install nginx -y

Una volta installato Nginx, crea un file di configurazione dell'host virtuale Nginx con il seguente comando:

nano /etc/nginx/conf.d/grafana.conf

Aggiungi le seguenti righe:

server {
        server_name grafana.example.com;
        listen 80;
        access_log /var/log/nginx/grafana.log;

        
        location / {
                proxy_pass http://localhost:3000;
                proxy_set_header X-Forwarded-Host $host:$server_port;
                proxy_set_header X-Forwarded-Server $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

Salva e chiudi il file quando hai finito. Quindi, verifica Nginx per qualsiasi errore di sintassi con il seguente comando:

nginx -t

Se tutto va bene, otterrai il seguente output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Successivamente, riavvia Nginx per applicare le modifiche alla configurazione.

systemctl restart nginx

Puoi anche controllare lo stato di Nginx con il seguente comando:

systemctl status nginx

Otterrai il seguente output:

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-02-04 04:09:20 UTC; 4s ago
       Docs: man:nginx(8)
    Process: 8631 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 8632 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 8633 (nginx)
      Tasks: 2 (limit: 2341)
     Memory: 2.5M
        CPU: 35ms
     CGroup: /system.slice/nginx.service
             ??8633 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ??8634 nginx: worker process

Feb 04 04:09:20 debian11 systemd[1]: Starting A high performance web server and a reverse proxy server...
Feb 04 04:09:20 debian11 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Feb 04 04:09:20 debian11 systemd[1]: Started A high performance web server and a reverse proxy server.

A questo punto, Nginx è installato e configurato come proxy inverso per Grafana. Ora puoi procedere al passaggio successivo.

Accedi alla dashboard di Grafana

Ora, apri il tuo browser web e accedi all'interfaccia web di Grafana utilizzando l'URL http://grafana.example.com. Verrai reindirizzato alla pagina di accesso di Grafana:

Fornisci il nome utente e la password dell'amministratore e fai clic sul pulsante Accedi. Dovresti vedere la schermata di reimpostazione della password di Grafana:

Imposta la tua nuova password e fai clic sul pulsante Invia. Dovresti vedere la dashboard di Grafana nella schermata seguente:

Proteggi Grafana con Lets Encrypt

Successivamente, dovrai installare il pacchetto client Certbot per installare e gestire Lets Encrypt SSL.

Innanzitutto, installa Certbot con il seguente comando:

apt-get install certbot python3-certbot-nginx -y

Al termine dell'installazione, esegui il seguente comando per installare Lets Encrypt SSL sul tuo sito web:

certbot --nginx -d grafana.example.com

Ti verrà chiesto di fornire un indirizzo email valido e di accettare i termini di servizio come mostrato di seguito:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for grafana.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/grafana.conf

Successivamente, scegli se reindirizzare o meno il traffico HTTP su HTTPS come mostrato di seguito:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Digita 2 e premi Invio per completare l'installazione. Dovresti vedere il seguente output:

Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/grafana.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://grafana.example.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=grafana.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/grafana.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/grafana.example.com/privkey.pem
   Your cert will expire on 2022-05-07. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

Conclusione

Congratulazioni! hai installato con successo Grafana 8 con Nginx e Lets Encrypt SSL su Debian 11. Ora puoi aggiungere i tuoi host remoti e iniziare a monitorarli dalla dashboard di Grafana. Non esitate a chiedermi se avete domande.