mysql主从同步启用半同步
Posted Colinshi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql主从同步启用半同步相关的知识,希望对你有一定的参考价值。
安装mysql半同步插件:
主服务器安装插件:
mysql> show global variables like ‘plugin_dir%‘;
+---------------+--------------------------+
| Variable_name | Value |
+---------------+--------------------------+
| plugin_dir | /usr/lib64/mysql/plugin/ | 当前mysql插件目录的具体位置
+---------------+--------------------------+
mysql > INSTALL PLUGIN rpl_semi_sync_master SONAME ‘semisync_master.so‘;
主服务器半同步参数(插件安装后才有):
mysql> show global variables like ‘rpl_semi_sync_master%‘;
+-------------------------------------------+------------+
| Variable_name | Value |
+-------------------------------------------+------------+
| rpl_semi_sync_master_enabled | OFF | 开启半同步模式
| rpl_semi_sync_master_timeout | 10000 | 半同步timeout时间10000毫秒
| rpl_semi_sync_master_trace_level | 32 | 跟踪级别
| rpl_semi_sync_master_wait_for_slave_count | 1 | 等待最少多少台从服务器完成同步
| rpl_semi_sync_master_wait_no_slave | ON |
| rpl_semi_sync_master_wait_point | AFTER_SYNC | 5.7的新半同步模式(value=AFTER_SYNC为Loss-Less半同步复制,AFTER_COMMIT为老版半同步)
+-------------------------------------------+------------+
开启主服务器半同步:mysql> set global rpl_semi_sync_master_enabled=ON;从服务器安装插件:
mysql > INSTALL PLUGIN rpl_semi_sync_slave SONAME ‘semisync_slave.so‘;
从服务器半同步参数(插件安装后才有):
mysql> show global variables like ‘rpl_semi_sync_slave%‘;
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| rpl_semi_sync_slave_enabled | OFF | 开启半同步模式
| rpl_semi_sync_slave_trace_level | 32 | 跟踪级别
+---------------------------------+-------+
开从服务器启半同步:mysql> set global rpl_semi_sync_slave_enabled=ON;
查看具体半同步状态信息:
主:
mysql > show global status like ‘rpl_semi_sync%‘;
+--------------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients | 0 | 半同步复制从服务器的个数
| 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 |
+--------------------------------------------+-------+
注:这之后需要重启一下从服务器的线程,之前一直卡着主从都已经开启了半同步,状态(Rpl_semi_sync_master_status=ON),但是没有从客户端(Rpl_semi_sync_master_clients=0),见上面的状态信息
mysql> STOP SLAVE [IO_THREAD];
mysql> START SLAVE [IO_THREAD];
以上是关于mysql主从同步启用半同步的主要内容,如果未能解决你的问题,请参考以下文章