0. 概述

作为一款流行的监控软件,grafana 具有丰富的图形展示功能,本文将介绍一下如何安装和设置 Grafana

1. 设置 repo

  1. [root@liqiang.io]# cat >/etc/yum.repos.d/grafana.repo << EOF
  2. [grafana]
  3. name=grafana
  4. baseurl=https://packages.grafana.com/oss/rpm
  5. repo_gpgcheck=1
  6. enabled=1
  7. gpgcheck=1
  8. gpgkey=https://packages.grafana.com/gpg.key
  9. sslverify=1
  10. sslcacert=/etc/pki/tls/certs/ca-bundle.crt
  11. EOF

2. 安装 grafana

  1. [root@liqiang.io]# yum install -y grafana nginx

3. 配置 grafana

  1. [root@liqiang.io]# cat >/etc/grafana/grafana.ini <<EOF
  2. [server]
  3. protocol = http
  4. http_addr = 127.0.0.1
  5. http_port = 3000
  6. domain = grafana.liqiang.io
  7. enforce_domain = true
  8. serve_from_sub_path = true
  9. root_url = http://%(domain)s:%(http_port)s/grafana
  10. EOF
  11. [root@liqiang.io]# mkdir -p /etc/nginx/grafana
  12. [root@liqiang.io]# cat> /etc/nginx/grafana/grafana.conf << EOF
  13. location /grafana {
  14. proxy_pass http://127.0.0.1:3000;
  15. proxy_set_header X-Real-IP $remote_addr;
  16. proxy_set_header Host $host;
  17. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  18. proxy_http_version 1.1;
  19. proxy_set_header Upgrade $http_upgrade;
  20. proxy_set_header Connection "upgrade";
  21. proxy_redirect off;
  22. }
  23. EOF
  24. [root@liqiang.io]# cat> /etc/nginx/conf.d/grafana.conf << EOF
  25. server {
  26. listen 80;
  27. listen [::]:80;
  28. server_name grafana.liqiang.io;
  29. include /etc/nginx/grafana/*.conf;
  30. }
  31. EOF

4. 运行 grafana

  1. [root@liqiang.io]# systemctl enable grafana-server.service
  2. [root@liqiang.io]# systemctl start grafana-server.service
  3. [root@liqiang.io]# nginx -s reload

5. 访问 grafana

打开浏览器:http://grafana.liqiang.io/grafana,然后就看到这个界面了:

图 1:Grafana 登陆界面

grafana 的默认帐号密码是:

6. Kubernetes 默认密码

  1. [root@liqiang.io]# kubectl get secret --namespace default my-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo

6. Ref