Mysql半同步配置
发布时间:2022-03-27 04:11:27 所属栏目:MySql教程 来源:互联网
导读:Mysql半同步的原理是主库只需要确认从库接收到了事物即可,无需等待从库应用,相比异步复制,半同步提高了数据完整性的保障,但会增加主库的响应时间。 1、安装Mysql并配置主从 参考http://blog.itpub.net/28536251/viewspace-2138854/分别在两节点安装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) (编辑:晋中站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |