Chinaunix首页 | 论坛 | 博客
  • 博客访问: 78750
  • 博文数量: 27
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 246
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-26 10:22
个人简介

做个辛勤的搬运工

文章分类

全部博文(27)

文章存档

2015年(27)

我的朋友

分类: Mysql/postgreSQL

2015-04-29 09:26:56

半同步是相当于异步同步而言.异步同步就是我们经常说的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,即每一个事务都会等待.
  




















阅读(1103) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~