mysql 半同步复制

(本文测试案例,没有开启gtid,涉及gtid的半同步,将另文说明)
半同步是相当于异步同步而言.异步同步就是我们经常说的master-slave模式.半同步也是基于bin-log的复制,主库在提交一个事物时,在写入binlog后,等待salve端接收到bilog后,返回一个接收成功的信号给主库,主库在接收到次信号后,才会正式提交该事物...简单来讲就是在主库事物提交的尾端增加一个从库接收成功的读取信号过程.
简单讲下安装配置:
安装完mysql后,启动mysql,进入mysql环境安装插件,并开启半同步:
主库:
[root@localhost ~]# cd /opt/mysql3307/lib/plugin/
[root@localhost plugin]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 27
Server version: 5.6.20-log Source distribution
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';
Query OK, 0 rows affected (0.17 sec)
mysql> set global rpl_semi_sync_master_enabled='on';
Query OK, 0 rows affected (0.00 sec)
在my.cnf里面加入rpl_semi_sync_master_enabled=1


从库:
[root@localhost ~]# cd /opt/mysql3307/lib/plugin/
[root@localhost plugin]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 27
Server version: 5.6.20-log Source distribution
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
Query OK, 0 rows affected (0.17 sec)
mysql> set global rpl_semi_sync_slave_enabled='on';
Query OK, 0 rows affected (0.00 sec)
在my.cnf里面加入rpl_semi_sync_slave_enabled=1


从主库导出一份全库数据,在从库导入,然后更改同步用户及时间点等.然后,开启同步(start slave),与异步同步操作一样.

ps:半同步复制,是主库提交一个事务后,等待从库接收binlog后,返回主库一个接收成功的信息,此时,主库才会提交完成一个事务.否则主库就会等待10s.仍没有接收到从库返回信息时,降到异步同步模式.直到主库再次探测到从库恢复,才会再次回到半同步模式.
有此可知,半同步模式只与io_thread有直接关系,与sql_thread没有关系.
rpl_semi_sync_master_timeout决定了主库等待从库返回接收信息的时间,如果这个时间值太大,在salve出现异常的时候,需要等待太长的时间才会提交事务,这个会严重影响主库事务性能.建议该值不要设置太大.


半同步复制相关参数说明:
1.rpl_semi_sync_master_enabled=ON 表示在主库开启半同步复制
  rpl_semi_sync_slave_enabled=ON   表示在从库开启半同步复制


2.rpl_semi_sync_master_timeout=10000   表示如果主库在某次事务中的等待时间超过这个时间值,则降级为异步复制模式,不在等待slave从库反回信息.如果主库再次探测到slave从库恢复了,则会自动再次回到半同步复制模式.
这个值默认是10000ms 即10s.


3.rpl_semi_sync_master_trace_level=32 表示用于开启半同步复制模式时的调试级别,默认是32
  rpl_semi_sync_slave_trace_level   表示用于开启半同步复制模式时的调试级别,默认是32




4.rpl_semi_sync_master_wait_no_slave  表示是否允许master每个事务提交后都要等待slave的接收确认信号.默认为on,即每一个事务都会等待.
 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/20892230/viewspace-2127460/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/20892230/viewspace-2127460/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值