Mysql半同步配置
发表于:2025-02-03 作者:千家信息网编辑
千家信息网最后更新 2025年02月03日,Mysql半同步的原理是主库只需要确认从库接收到了事物即可,无需等待从库应用,相比异步复制,半同步提高了数据完整性的保障,但会增加主库的响应时间。1、安装Mysql并配置主从参考http://blog
千家信息网最后更新 2025年02月03日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)
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)
节点
同步
配置
变量
成功
主从
事物
插件
数据
数量
时间
模式
参考
控制
事件
动态
单位
原理
参数
完整性
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络安全维护测评
scrum软件开发流程
服务器网卡中关村
章丘软件开发的工资
游族网络技术骨干层
云南省网络安全特招
游戏服务器传输数据速度
丽水分布式服务器方案
软件开发试岗靠谱吗
网络安全成为中美博弈的重点
未来之役服务器怎么选欧服
云南互联网科技哪家强
河南模拟网络技术有限公司
网络安全法正式实施于哪一年
花雨庭电脑版连不上服务器
首选dns服务器地址干什么用的
cbm数据库检索英文扩展词
.net 修改数据库并发
企业信息网络安全领导小组
软件开发很难嘛
服务器为什么采用linux
海康智能管理服务器有什么用
北京科技大学学位论文数据库
公司服务器可以看购物记录吗
联想服务器硬盘
在服务器部署数据库有什么用
开展网络安全教育新闻
高科技网络技术管理
linq 操作数据库
浙江橙功营网络技术有限公司