웹사이트 검색

Debian 11에 Grafana 8 모니터링 도구를 설치하는 방법


이 페이지에서

  1. 전제 조건
  2. 시작하기\n
  3. Grafana 8 설치
  4. Grafana용 리버스 프록시로 Nginx 설치\n
  5. Grafana 대시보드 액세스
  6. Lets Encrypt로 Grafana 보호\n
  7. 결론

Grafana는 다른 호스트의 메트릭을 모니터링하는 데 사용되는 무료 오픈 소스 데이터 시각화 도구입니다. Typescript 및 Go로 작성되었으며 로그 및 데이터 그래프를 생성 및 편집하고 지표를 생성할 수 있습니다. Graphite, InfluxDB 또는 OpenTSDB를 포함한 시계열 데이터베이스에서 그래프 및 대시보드를 생성하고 다른 사용자와 공유할 수 있습니다.

특징

  • 대시보드 템플릿\n
  • 프로비저닝 주석\n
  • 키오스크 모드 및 재생목록
  • 맞춤형 플러그인\n
  • 경고 및 경고 후크\n

이 게시물에서는 Debian 11에 Grafana 8을 설치하는 방법을 보여줍니다.

전제 조건

  • Debian 11을 실행하는 서버.\n
  • 서버 IP를 가리키는 유효한 도메인 이름입니다.\n
  • 루트 암호는 서버에서 구성됩니다.\n

시작하기

시작하기 전에 시스템을 업데이트된 버전으로 업데이트하는 것이 좋습니다. 다음 명령을 사용하여 모든 패키지를 업데이트할 수 있습니다.

apt-get update -y

모든 패키지를 업데이트한 후 다음 명령을 사용하여 다른 필수 종속성을 설치합니다.

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

모든 패키지가 설치되면 다음 단계로 진행할 수 있습니다.

Grafana 8 설치

기본적으로 Grafana는 Debian 11 기본 리포지토리에 포함되어 있지 않습니다. 따라서 APT에 Grafana 리포지토리를 추가해야 합니다. 다음 명령을 사용하여 추가할 수 있습니다.

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

리포지토리가 추가되면 리포지토리 캐시를 업데이트하고 다음 명령을 사용하여 Grafana를 설치합니다.

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

Grafana가 설치되면 다음 명령을 사용하여 Grafana 서비스를 시작하고 활성화합니다.

systemctl start grafana-server
systemctl enable grafana-server

다음 명령을 사용하여 Grafana 서비스의 상태를 확인할 수도 있습니다.

systemctl status grafana-server

다음과 같은 결과가 표시됩니다.

? 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>

기본적으로 Grafana는 포트 3000에서 수신합니다. 다음 명령으로 확인할 수 있습니다.

ss -antpl | grep 3000

다음과 같은 결과가 표시됩니다.

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

Grafana용 리버스 프록시로 Nginx 설치

다음으로 Nginx를 Grafana용 리버스 프록시로 설치하고 구성해야 합니다. 먼저 다음 명령을 사용하여 Nginx를 설치합니다.

apt-get install nginx -y

Nginx가 설치되면 다음 명령을 사용하여 Nginx 가상 호스트 구성 파일을 만듭니다.

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

다음 줄을 추가합니다.

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;
        }
}

완료되면 파일을 저장하고 닫습니다. 그런 다음 다음 명령을 사용하여 구문 오류가 있는지 Nginx를 확인합니다.

nginx -t

모든 것이 정상이면 다음과 같은 결과가 표시됩니다.

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

그런 다음 Nginx를 다시 시작하여 구성 변경 사항을 적용합니다.

systemctl restart nginx

다음 명령을 사용하여 Nginx 상태를 확인할 수도 있습니다.

systemctl status nginx

다음과 같은 결과가 표시됩니다.

? 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.

이 시점에서 Nginx는 Grafana용 리버스 프록시로 설치 및 구성됩니다. 이제 다음 단계를 진행할 수 있습니다.

Grafana 대시보드에 액세스

이제 웹 브라우저를 열고 URL http://grafana.example.com을 사용하여 Grafana 웹 인터페이스에 액세스하십시오. Grafana 로그인 페이지로 리디렉션됩니다.

관리자 사용자 이름, 비밀번호를 제공하고 로그인 버튼을 클릭합니다. Grafana 암호 재설정 화면이 표시되어야 합니다.

새 비밀번호를 설정하고 제출 버튼을 클릭합니다. 다음 화면에 Grafana 대시보드가 표시되어야 합니다.

Lets Encrypt로 Grafana 보호

다음으로 Lets Encrypt SSL을 설치하고 관리하려면 Certbot 클라이언트 패키지를 설치해야 합니다.

먼저 다음 명령을 사용하여 Certbot을 설치합니다.

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

설치가 완료되면 다음 명령을 실행하여 웹사이트에 Lets Encrypt SSL을 설치합니다.

certbot --nginx -d grafana.example.com

유효한 이메일 주소를 제공하고 아래와 같이 서비스 약관에 동의하라는 메시지가 표시됩니다.

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

다음으로 아래와 같이 HTTP 트래픽을 HTTPS로 리디렉션할지 여부를 선택합니다.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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

2를 입력하고 Enter 키를 눌러 설치를 마칩니다. 다음 출력이 표시되어야 합니다.

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.

결론

축하합니다! Nginx와 함께 Grafana 8을 성공적으로 설치했고 Debian 11에 Lets Encrypt SSL을 설치했습니다. 이제 Grafana 대시보드에서 원격 호스트를 추가하고 모니터링을 시작할 수 있습니다. 궁금한 점이 있으면 언제든지 문의해 주세요.