Mysql半同步配置

发布时间:2020-08-13 06:00:04 作者:stonebox1122
来源:ITPUB博客 阅读:205
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)
推荐阅读:
  1. mysql 备份 和半同步
  2. MySQL半同步复制

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mysql 同步 配置

上一篇:2020伊始,电动车又给自己刷了一遍谎言buff

下一篇:大数据量删除的思考 - 2

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》