首页 > 代码库 > mysql半同步复制及复制过滤
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半同步复制及复制过滤