Grafana

1 Grafana的多租户管理

2 Grafana的数据存储优化

1.安装grafna
略,见视频。


	2.Grafana主要参数说明
[root@prometheus-server31 ~]# vim /etc/grafana/grafana.ini 
...
[paths]
data = /var/lib/grafana  
	# 指定Grafana的数据存储路径(包含会话,用户,配置信息),如果使用了sqlite3开发数据库,则数据也是会以本地文件的方式存储。

temp_data_lifetime = 24h 
	# 临时文件存储的时间周期。

logs = /var/log/grafana
	# 指定日志的存储路径

plugins = /var/lib/grafana/plugins
	# 指定插件的存储目录。
	
provisioning = conf/provisioning
	# 包含grafana将在启动和运行时应用的配置文件的文件夹。


[server]
protocol = http
	# Grafana使用的协议,支持的协议有: http, https, h2, socket
	
http_addr =
	# 绑定服务器的IP地址,如果为空,默认绑定所有的网络接口。
	
http_port = 3000
	# 指定Grafana监听的端口。
	
[database]
type = sqlite3
	# 定义数据的存储类型。支持: "mysql", "postgres" or "sqlite3",
	
host = 127.0.0.1:3306
	# 指定数据库的主机IP地址及端口。

name = grafana
	# 指定数据库的用户名。
	
password =
	# 指定数据库的密码。

ssl_mode = disable
	# 使用启用了SSL,比如MySQL使用的自建证书,则建议跳过证书校验。有效值为: "true", "false", or "skip-verify"
	
	
[security]
disable_initial_admin_creation = false
	# 首次启动grafana时禁用创建管理员用户

admin_user = admin
	# 启动时会创建的用户名。
	
admin_password = admin
	# 指定管理员用户的密码。
	
admin_email = admin@localhost
	# 默认管理员的邮箱地址。
	
[dashboards]

versions_to_keep = 20
	# 默认保留最近Dashboard的20次修改记录。
	
min_refresh_interval = 5s
	# 刷新Dashboard最小间隔时间为5s。
	
[users]
allow_sign_up = true
	# 是否运行用户注册。
	
allow_org_create = true
	# 允许非管理员用户创建组织。
	
verify_email_enabled = false
	# 注册用户时是否需要邮箱验证。
	
default_theme = dark 
	# 默认的主题。
	
default_language = en-US
	# 默认使用的语言。


[auth]
disable_login = true    
	# 禁止用户登录。
	
[auth.anonymous]
enabled = false
	# 是否启用匿名用户登录。
	
	
	
	
	3.安装mysql数据库
		3.1 安装docker环境
略,见视频。
		
		3.2 启动mysql服务
[root@node-exporter43 ~]# docker container rm -f `docker container ps -qa`
[root@node-exporter43 ~]# 
[root@node-exporter43 ~]# docker run -d --name mysql-server --restart always --network host -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -e MYSQL_DATABASE=prometheus -e MYSQL_USER=cmy  -e MYSQL_PASSWORD=cmy mysql:8.0.36-oracle --character-set-server=utf8 --collation-server=utf8_bin --default-authentication-plugin=mysql_native_password
0f7d832176e5bf5445b5fcf0db42210fc20c416dbc62cf7021affdd724f2835e
[root@node-exporter43 ~]# 
[root@node-exporter43 ~]# docker ps -l
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS         PORTS     NAMES
0f7d832176e5   mysql:8.0.36-oracle   "docker-entrypoint.s…"   3 seconds ago   Up 2 seconds             mysql-server
[root@node-exporter43 ~]# 
[root@node-exporter43 ~]# ss -ntl | grep 3306
LISTEN 0      151                *:3306             *:*          
LISTEN 0      70                 *:33060            *:*          
[root@node-exporter43 ~]# 


	
	4.修改Grafana的配置文件
[root@prometheus-server31 ~]# vim /etc/grafana/grafana.ini 
...
[database]
...
type = mysql
host = 10.168.10.43:3306
name = prometheus
user = cmy
password = cmy          
	
	5.启动grafna
[root@prometheus-server31 ~]# systemctl restart grafana-server.service 
[root@prometheus-server31 ~]# 
[root@prometheus-server31 ~]# ss -ntl | grep 3000
LISTEN 0      4096               *:3000            *:*          
[root@prometheus-server31 ~]# 


	6.登录Grafana的webUI【注意,之前的数据全部都丢失了,因为之前使用的是sqllit3,现在用的是MySQL。】
http://10.168.10.31:3000/

初始的用户名和密码为: admin


	7.验证数据是否写入成功
[root@node-exporter43 ~]# docker exec -it mysql-server mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.0.36 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| prometheus         |
| sys                |
+--------------------+
5 rows in set (0.01 sec)
上一篇
下一篇