Mysql半同步配置

Mysql半同步的原理是主库只需要确认从库接收到了事物即可,无需等待从库应用,相比异步复制,半同步提高了数据完整性的保障,但会增加主库的响应时间。
1、安装Mysql并配置主从
参考 http://blog.itpub.net/28536251/viewspace-2138854/ 分别在两节点安装Mysql。
参考 http://blog.itpub.net/28536251/viewspace-2138928/ 或者 http://blog.itpub.net/28536251/viewspace-2139007/ 配置主从。

2、在master节点加载半同步插件
(root@localhost)[(none)] install plugin rpl_semi_sync_master soname 'semisync_master.so';
Query OK, 0 rows affected (0.16 sec)

3、在slave节点加载半同步插件
(root@localhost)[(none)] install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
Query OK, 0 rows affected (0.45 sec)

4、在master节点设置以下变量
(root@localhost)[(none)] set global rpl_semi_sync_master_enabled=1;
Query OK, 0 rows affected (0.05 sec)
#rpl_semi_sync_master_enabled用于控制是否在master节点启用半同步复制,为1表示启动。

(root@localhost)[(none)] set global rpl_semi_sync_master_timeout=3000;
Query OK, 0 rows affected (0.00 sec)
#rpl_semi_sync_master_timeout用于指定master节点等待slave响应的事件,单位是毫秒,默认是10000即10秒钟,这里设置为3秒。若超出指定时间slave节点仍无响应,那么当前复制环境就临时被转换为异步复制。

5、在slave节点设置以下变量
(root@localhost)[(none)] set global rpl_semi_sync_slave_enabled=1;
Query OK, 0 rows affected (0.09 sec)
#rpl_semi_sync_slave_enabled用来控制slave节点是否启用半同步复制。

以上3个变量虽然可以动态修改,但强烈建议将所有配置的变量都保存在初始化参数文件中,这样在每次启动mysql服务时就无需再手动配置了。

6、在slave节点重启io_thread线程
slave节点重新连接master节点,注册为半同步身份。
(root@localhost)[(none)] stop slave io_thread;
Query OK, 0 rows affected (0.12 sec)

(root@localhost)[(none)] start slave io_thread;
Query OK, 0 rows affected (0.02 sec)

7、测试
主库插入数据:
(root@localhost)[(none)] use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
(root@localhost)[test] show tables;
+----------------+
| Tables_in_test |
+----------------+
| tb1            |
+----------------+
1 row in set (0.00 sec)

(root@localhost)[test] select * from tb1;
+------+
| id   |
+------+
|    1 |
+------+
1 row in set (0.03 sec)

(root@localhost)[test] insert into tb1 values(2);
Query OK, 1 row affected (0.10 sec)

(root@localhost)[test] select * from tb1;
+------+
| id   |
+------+
|    1 |
|    2 |
+------+
2 rows in set (0.02 sec)

(root@localhost)[test] show status like 'rpl_semi_sync%';
+--------------------------------------------+-------+
| Variable_name                              | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients               | 1     |
| Rpl_semi_sync_master_net_avg_wait_time     | 0     |
| Rpl_semi_sync_master_net_wait_time         | 0     |
| Rpl_semi_sync_master_net_waits             | 1     |
| Rpl_semi_sync_master_no_times              | 0     |
| Rpl_semi_sync_master_no_tx                 | 0     |
| Rpl_semi_sync_master_status                | ON    |
| Rpl_semi_sync_master_timefunc_failures     | 0     |
| Rpl_semi_sync_master_tx_avg_wait_time      | 52899 |
| Rpl_semi_sync_master_tx_wait_time          | 52899 |
| Rpl_semi_sync_master_tx_waits              | 1     |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0     |
| Rpl_semi_sync_master_wait_sessions         | 0     |
| Rpl_semi_sync_master_yes_tx                | 1     |
+--------------------------------------------+-------+
14 rows in set (0.05 sec)

其中:
rpl_semi_sync_master_clients为1表示处于半同步模式的slave节点有1个。
rpl_semi_sync_master_status为ON表示master节点启用了半同步模式。
rpl_semi_sync_master_no_tx为0表示还没有未成功发送到slave节点的事物数量。
rpl_semi_sync_master_yes_tx为1表示已成功发送到slave节点的事物数量为1。

备库查看:
(root@localhost)[test] select * from tb1;
+------+
| id   |
+------+
|    1 |
|    2 |
+------+
2 rows in set (0.00 sec)

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

转载于:http://blog.itpub.net/28536251/viewspace-2139097/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值