架构图
前提条件:
mysql主主+keepalived
granfana两台+keepalived
一、使用同一数据源的配置
1、准备grafana数据库:
# mysql -uroot -pk19k19
mysql> CREATE DATABASE grafana DEFAULT CHARACTER SET utf8;
Query OK, 1 row affected (0.02 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| apolloconfigdb |
| apolloportaldb |
| grafana |
| mysql |
| performance_schema |
| sys |
| testforliuxw |
| txc |
+--------------------+
9 rows in set (0.01 sec)
2、修改数据源
Grafana默认使用了内嵌数据库sqlite3来进行用户以及dashboard相关配置的存储。更改配置文件的[database]部分,改为mysql(可以更改为"postgres"等其他数据库):
vi /etc/grafana/grafana.ini
解除注释并修改以下几行
#################################### Database ####################################
[database]
# You can configure the database connection by specifying type, host, name, user and password
# as separate properties or as on string using the url properties.
# Either "mysql", "postgres" or "sqlite3", it's your choice
type = mysql
host = 172.26.1.111:3306 #填写mysql vip
name = grafana #选择grafana存储数据库
user = root #mysql用户
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
password = k19k19 #mysql密码
3、重启grafana
systemctl restart grafana-server.service
测试
grafana vip操作,发现两台grafana同步,成功