mysql 架構~MGR+proxysql(1)
一 簡介:今天咱們來探討下方案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庫中
mysql 架構~MGR+proxysql(1)