一 简介:今天咱们来探讨下方案2的实现方式,同时也推荐方案2
二 环境部署
1 proxysql 环境
2 mgr 环境
三 进行配置
1 创建用户
1 添加监控用户并授权
grant all privileges on *.* to 'proxyuser'@'%' identified by 'proxypass';
2 添加代理业务用户并授权
GRANT INSERT,UPDATE,DELETE,SELECT,CREATE,DROP,ALTER ON * . * TO 'proxyuser'@'%' IDENTIFIED BY 'proxypass'; ;
flush privileges;
2 添加DB列表
insert into mysql_servers (hostgroup_id, hostname, port) values(1, 'mgr1', 3306);
insert into mysql_servers (hostgroup_id, hostname, port) values(2, 'mgr1', 3306);
insert into mysql_servers (hostgroup_id, hostname, port) values(2, 'mgr2', 3306);
insert into mysql_servers (hostgroup_id, hostname, port) values(2, 'mgr3', 3306);
hostgroup_id = 1代表write group
hostgroup_id = 2代表read group
3 修改监控账号密码
UPDATE global_variables SET variable_value='proxysql' WHERE variable_name='mysql-monitor_username';
UPDATE global_variables SET variable_value='proxysql' WHERE variable_name='mysql-monitor_password';
4 添加后端访问账号
INSERT INTO MySQL_users(username,password,default_hostgroup) VALUES ('proxyuser','proxypass',1);
5 变量生效
LOAD MYSQL VARIABLES TO RUNTIME;
SAVE MYSQL VARIABLES TO DISK;
LOAD MYSQL SERVERS TO RUNTIME;
SAVE MYSQL SERVERS TO DISK;
LOAD MYSQL USERS TO RUNTIME;
SAVE MYSQL USERS TO DISK;
6 部署后端检测脚本
1 下载gr_sw_mode_checker.sh并放置在/var/lib/proxysql下 并授予可执行权限
2 insert into scheduler(id, active, interval_ms, filename, arg1, arg2, arg3, arg4) values(1, 1, 3000, '/var/lib/proxysql/gr_sw_mode_checker.sh', 1, 2, 1, '/var/lib/proxysql/checker.log');
3 LOAD SCHEDULER TO RUNTIME;
SAVE SCHEDULER TO DISK;
7 进行连接检测
四 补充
1 检测脚本必须要执行检测
2 github上检测脚本分为两种 一种是单主模式的 一种是多主模式的 要注意区分场景使用
3 proxysql的视图要预选导入到mysql.sys库中