mysql半同步复制及复制过滤

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql半同步复制及复制过滤相关的知识,希望对你有一定的参考价值。

配置mysql半同步,前提是已经有master和slave环境。

MySQL半同步配置

Master配置

安装semisync_master插件

mysql> INSTALL PLUGIN rpl_semi_sync_master SONAME ‘semisync_master.so‘;

Query OK, 0 rows affected (0.02 sec)


mysql>show plugins;

+----------------------------+----------+--------------------+--------------------+---------+

| Name                       | Status   | Type               | Library            | License |

+----------------------------+----------+--------------------+--------------------+---------+

| rpl_semi_sync_master       | ACTIVE   | REPLICATION        | semisync_master.so | GPL     |


vim /etc/my.cnf

[mysqld]

rpl_semi_sync_master_enabled=ON


service mysqld restart

mysql> show global variables like ‘%semi%‘;

+------------------------------------+-------+

| Variable_name                      | Value |

+------------------------------------+-------+

| rpl_semi_sync_master_enabled       | ON   |

| rpl_semi_sync_master_timeout       | 10000 |

| rpl_semi_sync_master_trace_level   | 32    |

| rpl_semi_sync_master_wait_no_slave | ON    |

+------------------------------------+-------+

4 rows in set (0.00 sec)


Slave配置

mysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME ‘semisync_slave.so‘;

Query OK, 0 rows affected (0.00 sec)


vim /etc/my.cnf

[mysqld]

rpl_semi_sync_slave_enabled=ON


service mysqld restart


mysql> show global variables like ‘%semi%‘;

+---------------------------------+-------+

| Variable_name                   | Value |

+---------------------------------+-------+

| rpl_semi_sync_slave_enabled     | ON    |

| rpl_semi_sync_slave_trace_level | 32    |

+---------------------------------+-------+

2 rows in set (0.00 sec)


mysql> start slave;

Query OK, 0 rows affected, 1 warning (0.00 sec)


配置完成后在Master查看半同步复制状态

mysql> show global status like ‘%sem%‘;

+--------------------------------------------+-------+

| Variable_name                              | Value |

+--------------------------------------------+-------+

| Rpl_semi_sync_master_clients               | 1     |

| Rpl_semi_sync_master_net_avg_wait_time     | 703   |

| Rpl_semi_sync_master_net_wait_time         | 703   |

| 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      | 777   |

| Rpl_semi_sync_master_tx_wait_time          | 777   |

| 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.00 sec)


mysql复制过滤

slave配置:

vim /etc/my.cnf

[mysqld]

replicate-do-db =sync_db  //复制时指定要复制的DB

mysql> show slave status\G;

*************************** 1. row ***************************

               Slave_IO_State: Waiting for master to send event

                  Master_Host: 192.168.1.202

                  Master_User: repluser

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: master_bin.000006

          Read_Master_Log_Pos: 344

               Relay_Log_File: relay_log.000019

                Relay_Log_Pos: 284

        Relay_Master_Log_File: master_bin.000006

             Slave_IO_Running: Yes

            Slave_SQL_Running: Yes

              Replicate_Do_DB: sync_db


以上是关于mysql半同步复制及复制过滤的主要内容,如果未能解决你的问题,请参考以下文章

MySQL 半同步复制模式说明及配置示例 - 运维小结

MySQL 5.7的复制架构,在有异步复制半同步增强半同步MGR等的生产中,该如何选择?

mysql数据库备份,主从复制及半同步复制

快速笔记02-MySQL主从复制原理半同步操作步骤及原理

MySQL数据库在线热备(半同步复制)

MySQL中的半同步复制