1.1 主服务器配置
1.安装插件
2.mysql > INSTALL PLUGIN rpl_semi_sync_master SONAME \'semisync_master.so\';
3.查看全局变量
4.mysql > show global variables like \'%semi%\';
设置主服务器的半同步复制全局变量
mysql > set global rpl_semi_sync_master_enabled=ON; 开启半同步复制
mysql > set global rpl_semi_sync_master_timeout=10000; 设置为10秒
vi /etc/my.cnf
[mysqld]
rpl_semi_sync_master_enabled=1
rpl_semi_sync_master_timeout=1000 # 1 second
4.2 设置从服务器
1.安装semi插件
2.mysql >install plugin rpl_semi_sync_slave soname \'semisync_slave.so\';
vi /etc/my.cnf
[mysqld]
rpl_semi_sync_slave_enabled=1
relay_log_purge=0
read_only=1
slave_skip_errors=1396
3.设置从服务器半同步复制全局变量
4.mysql> set global rpl_semi_sync_slave_enabled=ON; 开启半同步复制
5.mysql> stop slave io_thread; 关闭io线程
6.mysql> start slave io_thread; 开启io线程
检查半同步是否生效:
Master:
mysql> show global status like \'rpl_semi%\';
+--------------------------------------------+-------+
| 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 | 0 |
| 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 | 0 |
| Rpl_semi_sync_master_tx_wait_time | 0 |
| Rpl_semi_sync_master_tx_waits | 0 |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0 |
| Rpl_semi_sync_master_wait_sessions | 0 |
| Rpl_semi_sync_master_yes_tx | 0 |
+--------------------------------------------+-------+
说明半同步成功。
让半同步功能在MySQL每次启动都自动生效,在Master和Slave的my.cnf中编辑:
Master:
[mysqld]
rpl_semi_sync_master_enabled=1
rpl_semi_sync_master_timeout=1000 #1秒
Slave:
[mysqld]
rpl_semi_sync_slave_enabled=1
也可通过设置全局变量的方式来设置是否启动半同步插件:
Master:
mysql> set global rpl_semi_sync_master_enabled=1
取消加载插件
mysql> uninstall plugin rpl_semi_sync_master;
Slave:
mysql> set global rpl_semi_sync_slave_enabled = 1;
mysql> uninstall plugin rpl_semi_sync_slave;
#三台机器需要全部开启半同步功能,其中参数配置仅server_id不同
> show variables like \'%sync%\';
> show status like \'%sync%\';
有几个参数值得关注:
rpl_semi_sync_master_status 显示主服务器是async还是半同步复制
rpl_semi_sync_master_clients 有多少个从服务器配置为半同步复制模式;
rpl_semi_sync_master_yes_trx 从服务器确认成功提交的数量;
rpl_semi_sync_master_no_trx 从服务器确认不成功提交的数据量;
rpl_semi_sync_master_tx_avg_wait_time
rpl_semi_sync_master_net_avg_wait_time
5,需要每台机器配置ssh 免密登录;
ssh-keygen
ssh-copy-id -i ip
for i in ip1 ip2 ip3 ip4
do
ssh $i date;
done