ProxySQL 部署 Single Writer Failover 读写分离 (PXC)


 

 

 

主机信息:

Proxysql:

如果你忽略了ProxySQL会报告主机组的变化,我建议把它设置为0,除非你试图调试“某些东西”,否则你的日志将很快变得巨大。
UPDATE global_variables SET Variable_Value=0 WHERE Variable_name='mysql-hostgroup_manager_verbose';

在PXC 5.7添加proxysql监控用户:

CREATE USER 'proxysql'@'%' IDENTIFIED BY 'proxysql';
GRANT USAGE ON *.* TO 'proxysql'@'%';

 

添加访问mysql用户配置

INSERT INTO mysql_users (username,password,active,default_hostgroup,default_schema,transaction_persistent) VALUES ('proxysql','proxysql',1,50,'mysql',1);
LOAD MYSQL USERS TO RUNTIME; SAVE MYSQL USERS TO DISK;

 

添加您的服务器:

INSERT INTO mysql_servers (hostname,hostgroup_id,port,weight,max_connections) VALUES ('10.1.1.11',50,3306,1000000,2000);
INSERT INTO mysql_servers (hostname,hostgroup_id,port,weight,max_connections) VALUES ('10.1.1.11',52,3306,1,2000); INSERT INTO mysql_servers (hostname,hostgroup_id,port,weight,max_connections) VALUES ('10.1.1.11',8050,3306,1000000,2000); INSERT INTO mysql_servers (hostname,hostgroup_id,port,weight,max_connections) VALUES ('10.1.1.33',52,3306,1,2000); INSERT INTO mysql_servers (hostname,hostgroup_id,port,weight,max_connections) VALUES ('10.1.1.33',8050,3306,10000,2000); INSERT INTO mysql_servers (hostname,hostgroup_id,port,weight,max_connections) VALUES ('10.1.1.44',52,3306,1,2000); INSERT INTO mysql_servers (hostname,hostgroup_id,port,weight,max_connections) VALUES ('10.1.1.44',8050,3306,100000,2000); LOAD MYSQL SERVERS TO RUNTIME; SAVE MYSQL SERVERS TO DISK; select hostgroup_id,hostname,port,STATUS,weight FROM runtime_mysql_servers ORDER BY hostgroup_id,weight DESC;

 

检查配置:

select hostgroup_id,hostname,port,STATUS,weight FROM runtime_mysql_servers ORDER BY hostgroup_id,weight DESC;

添加查询规则:

INSERT INTO mysql_query_rules (rule_id,proxy_port,username,destination_hostgroup,active,retries,match_digest,apply) VALUES(4,6033,'proxysql',50,1,3,'^\(?SELECT',1);

INSERT INTO mysql_query_rules (rule_id,proxy_port,username,destination_hostgroup,active,retries,match_digest,apply) VALUES(40,6033,'proxysql',50,1,3,'^SELECT.*FOR UPDATE$',1); INSERT INTO mysql_query_rules (rule_id,proxy_port,username,destination_hostgroup,active,retries,match_digest,apply) VALUES(41,6033,'proxysql',52,1,3,'^SELECT',1); LOAD MYSQL QUERY RULES TO RUNTIME;SAVE MYSQL QUERY RULES TO DISK;

 

加入故障转移脚本,利用scheduler 修改配置提升44为new writer:

cd /opt/
git clone https://github.com/Tusamarco/proxy_sql_tools chmod +x /opt/proxy_sql_tools/galera_check.pl INSERT INTO scheduler (id,active,interval_ms,filename,arg1) VALUES (10,0,2000,"/opt/proxy_sql_tools/galera_check.pl","-u=admin -p=admin -h=127.0.0.1 -H=50:W,52:R -P=6032 --execution_time=0 --retry_down=0 --retry_up=0 --main_segment=1 --debug=0 --log=/var/lib/proxysql/galeraLog --active_failover=1"); LOAD SCHEDULER TO RUNTIME; SAVE SCHEDULER TO DISK;

 

激活scheduler:

UPDATE scheduler SET active=1 WHERE id=10;
LOAD scheduler TO run;

 

当你想做一个CONTROLLED故障转移时,

以最小的影响做最好的方法是手动添加非常低权重的第二个节点,

并在删除节点后,您需要处理。我会告诉你如何安全地做到这一点。

INSERT INTO mysql_servers (hostname,hostgroup_id,port,weight,max_connections) VALUES('10.1.1.11',50,3306,1,2000);
LOAD mysql servers TO run;
SELECT * FROM stats_mysql_connection_pool;

 

 把10.1.1.11 kill了mysqld 和 mysqld_safe进程 ,发现10.1.1.44 已经提升为writer

 

select hostgroup_id,hostname,port,STATUS,weight FROM runtime_mysql_servers ORDER BY hostgroup_id,weight DESC;

 

10.1.1.11 恢复之后,重新读取配置

load mysql servers to runtime;
save mysql servers to disk; select hostgroup_id,hostname,port,STATUS,weight FROM runtime_mysql_servers ORDER BY hostgroup_id,weight DESC;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM