默認grafana使用sqlite3進行相關配置存儲,使用本地文件進行session存儲,不太方便進行分佈式擴展,這裏改成mysql。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
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;
查看錶結構:sql
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)
表明切換成功。docker