默认grafana使用sqlite3进行相关配置存储,使用本地文件进行session存储,不太方便进行分布式扩展,这里改为mysql。

修改配置文件

[database]
; Either "mysql", "postgres" or "sqlite3", it's your choice
type = mysql
host = 192.168.99.100:3306
name = grafana
user = root
password = root

[session]
provider = mysql
provider_config = root:root@tcp(192.168.99.100:3306)/grafana
cookie_name = grafana_session
cookie_secure = false
session_life_time = 86400

配置mysql

docker run --name grafana-mysql -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -d mysql:5.6.35

CREATE DATABASE IF NOT EXISTS grafana default charset utf8 COLLATE utf8_general_ci;

CREATE TABLE `session` (
    `key`       CHAR(16) NOT NULL,
    `data`      BLOB,
    `expiry`    INT(11) UNSIGNED NOT NULL,
    PRIMARY KEY (`key`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

运行

查看表结构:

mysql> use grafana;
Query OK, 0 rows affected (0.00 sec)

mysql> show tables;
+--------------------+
| Tables_in_grafana  |
+--------------------+
| alert              |
| alert_notification |
| annotation         |
| api_key            |
| dashboard          |
| dashboard_snapshot |
| dashboard_tag      |
| data_source        |
| migration_log      |
| org                |
| org_user           |
| playlist           |
| playlist_item      |
| plugin_setting     |
| preferences        |
| quota              |
| session            |
| star               |
| temp_user          |
| user               |
+--------------------+
20 rows in set (0.01 sec)

代表切换成功。

doc


codecraft
11.9k 声望2k 粉丝

当一个代码的工匠回首往事时,不因虚度年华而悔恨,也不因碌碌无为而羞愧,这样,当他老的时候,可以很自豪告诉世人,我曾经将代码注入生命去打造互联网的浪潮之巅,那是个很疯狂的时代,我在一波波的浪潮上留下...


引用和评论

0 条评论