grafana使用mysql存储

2017-04-05 11:03:37来源:oschina作者:go4it人点击



##序
默认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
- [How to setup Grafana for high availability](http://docs.grafana.org/tutorials/ha_setup/#how-to-setup-grafana-for-high-availability)

微信扫一扫

第七城市微信公众平台