Grafana 集成 MySQL + Redis

Grafana 默认使用 sqlite3 存储账户数据,为了方便备份与迁移,这里调整为 mysql

1.创建数据库和用户;请把 grafanapassword 替换为更安全的密码

CREATE DATABASE grafana DEFAULT CHARACTER SET utf8;
GRANT ALL ON grafana.* TO grafana@'localhost' IDENTIFIED BY 'grafanapassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;

2.指定数据库及认证信息

cp /etc/grafana/grafana.ini {,.default}
vim /etc/grafana/grafana.ini

#################################### Database ############################
[database]
# You can configure the database connection by specifying type, host, name, user and password
# as seperate properties or as on string using the url propertie.

# Either "mysql", "postgres" or "sqlite3", it's your choice
type = mysql
host = 127.0.0.1:3306
name = grafana
user = grafana
# If the password contains # or ; you have to wrap it with trippel quotes. Ex """#password;"""
password = MXkepzK5ptxhdHR4
# Use either URL or the previous fields to configure the database
# Example: mysql://user:secret@host:port/database
url =

# Max conn setting default is 0 (mean not set)
max_conn =
max_idle_conn =
max_open_conn =

# For "postgres", use either "disable", "require" or "verify-full"
# For "mysql", use either "true", "false", or "skip-verify".
ssl_mode = disable

ca_cert_path =
client_key_path =
client_cert_path =
server_cert_name =

# For "sqlite3" only, path relative to data_path setting
path = grafana.db

#################################### Session #############################
[session]
# Either "memory", "file", "redis", "mysql", "postgres", "memcache", default is "file"
provider = redis

# Provider config options
# memory: not have any config yet
# file: session dir path, is relative to grafana data_path
# redis: config like redis server e.g. `addr=127.0.0.1:6379,pool_size=100,db=grafana`
# postgres: user=a password=b host=localhost port=5432 dbname=c sslmode=disable
# mysql: go-sql-driver/mysql dsn config string, examples:
#         `user:password@tcp(127.0.0.1:3306)/database_name`
#         `user:password@unix(/var/run/mysqld/mysqld.sock)/database_name`
# memcache: 127.0.0.1:11211
provider_config = addr=127.0.0.1:16397,pool_size=100,db=grafana

# Session cookie name
cookie_name = grafana_sess

# If you use session in https only, default is false
cookie_secure = false

# Session life time, default is 86400
session_life_time = 86400
gc_interval_time = 86400

3.重启 grafana

service grafana-server restart

tail -f /var/log/grafana/grafana.log

参考连接

http://docs.grafana.org/installation/configuration/#database

作者:Jeebiz  创建时间:2023-02-08 20:51
最后编辑:Jeebiz  更新时间:2024-02-26 11:18