半同步复制需要使用插件,主从节点都需要安装插件。插件安装完之后 ,配置系统变量就可以启用和关闭半同步复制功能。
1.半同步实施前提
数据库版本为 5.5以上
have_dynamic_loading system variable 为 YES.
复制已经正常运行。
2.安装插件
主节点 INSTALL PLUGIN rpl_semi_sync_master SONAME ‘semisync_master.so‘; 从节点 INSTALL PLUGIN rpl_semi_sync_slave SONAME ‘semisync_slave.so‘;
3.查看是否安装成功
show plugins; 显示类似说明安装成功 | rpl_semi_sync_master | ACTIVE | REPLICATION | semisync_master.so | GPL | | rpl_semi_sync_slave | ACTIVE | REPLICATION | semisync_slave.so | GPL | mysql> show variables like ‘%semi%‘; +--------------------------------------------------------+-------+ | Variable_name | Value | +---------------------------------------------------------+-------+ | rpl_semi_sync_master_enabled | OFF | | rpl_semi_sync_master_timeout | 10000 | | rpl_semi_sync_master_trace_level | 32 | | rpl_semi_sync_master_wait_no_slave | ON | | rpl_semi_sync_slave_enabled | OFF | | rpl_semi_sync_slave_trace_level | 32 | +---------------------------------------------------------+-------+ 6 rows in set (0.00 sec)
4.启用半同步
主节点启用半同步,超时时间为10S
SET GLOBAL rpl_semi_sync_master_enabled = 1; SET GLOBAL rpl_semi_sync_master_timeout = 10000;
从节点启用半同步,重启复制线程生效 SET GLOBAL rpl_semi_sync_slave_enabled = 1; STOP SLAVE IO_THREAD; START SLAVE IO_THREAD;
5.确认半同步生效
show global status like ‘rpl%‘;
6.持久化参数
On the master: [mysqld] rpl_semi_sync_master_enabled=1 rpl_semi_sync_master_timeout=1000 # 1 second On each slave: [mysqld] rpl_semi_sync_slave_enabled=1
本文出自 “roidba” 博客,请务必保留此出处http://roidba.blog.51cto.com/12318731/1893359
原文地址:http://roidba.blog.51cto.com/12318731/1893359