11: mysql master-slave replication - semi-sync - replica filter

Semi-synchronous replication
starting point is to ensure the consistency of data from the main issues, security considerations

5.5 The concept appears, but is not recommended, poor performance

5.6 emerged after the performance group commit group commit function to enhance the open version of Replication

5.7 more perfect, MGR appeared in the group commit on the basis of
new feature enhancements 5.7 of semi-synchronous replication: after commit; after sync;

------
restore the master-slave environment:

1, 3308 all equipment (as we do in front of the time delay replication, a simulated fault, from the library is now the master)
the mysqldump -S /data/3308/mysql.sock -A -R & lt --triggers --master- data = 2 --single-transaction> /tmp/full3308.sql

2, (3307) restored from backups, and turn the main from
MySQL -S /data/3307/mysql.sock
MySQL> SQL_LOG_BIN SET = 0;
MySQL> Source /tmp/full3308.sql

:( obtain master-slave replication can show master status; above the main library in 3308)
----------- vim +22 /tmp/full3308.sql line 22 -------- --------------------------------
the CHANGE of MASTER_LOG_FILE the MASTER the TO = 'MySQL-bin.000003', MASTER_LOG_POS = 120;
- -------------------------------------------------- ---------------------------

从库3307执行:
mysql>CHANGE MASTER TO
MASTER_HOST='192.168.6.181',
MASTER_USER='repl',
MASTER_PASSWORD='123',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000006',
MASTER_LOG_POS=361,
MASTER_CONNECT_RETRY=10;
mysql> start slave;
mysql> show slave status \G

The read-only library 3308 to close the main
MySQL -S /data/3308/mysql.sock
MySQL> Global read_only SET = 0;
the profile read_only removed (primary library requires normal write operation, it is necessary to turn off the read-only mode)

The read-only open from library 3307
MySQL -S /data/3307/mysql.sock
MySQL> SET Global read_only = 1;
the profile read_only = 1

-------------------------------------------------- -----
semi-synchronous replication:
load plugins (semi-synchronous need to load the plug-in to use semi-sync)

主3308:
mysql -S /data/3308/mysql.sock
mysql> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';


从3307:
mysql -S /data/3307/mysql.sock
mysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';

查看是否加载成功:
主3308:
mysql>show plugins;
| partition | ACTIVE | STORAGE ENGINE | NULL | GPL |
| rpl_semi_sync_master | ACTIVE | REPLICATION | semisync_master.so | GPL |
+----------------------------+----------+--------------------+--------------------+---------+
43 rows in set (0.00 sec)

从3307:
mysql>show plugins;
| partition | ACTIVE | STORAGE ENGINE | NULL | GPL |
| rpl_semi_sync_slave | ACTIVE | REPLICATION | semisync_slave.so | GPL |
+----------------------------+----------+--------------------+-------------------+---------+
43 rows in set (0.00 sec)

启动插件:
主:
mysql -S /data/3308/mysql.sock
mysql> SET GLOBAL rpl_semi_sync_master_enabled = 1;

从:
mysql -S /data/3307/mysql.sock
mysql> SET GLOBAL rpl_semi_sync_slave_enabled = 1;

重启从库上的IO线程
mysql -S /data/3307/mysql.sock
mysql>stop SLAVE IO_THREAD;
mysql>start SLAVE IO_THREAD;


查看是否在运行
主:
mysql -S /data/3308/mysql.sock
mysql> show status like 'Rpl_semi_sync_master_status';
+-----------------------------+-------+
| Variable_name | Value |
+-----------------------------+-------+
| Rpl_semi_sync_master_status | ON |
+-----------------------------+-------+
1 row in set (0.00 sec)
从:
mysql -S /data/3307/mysql.sock
mysql> show status like 'Rpl_semi_sync_slave_status';
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| Rpl_semi_sync_slave_status | ON |
+----------------------------+-------+
1 row in set (0.00 sec)

到此 -- 主从半同步复制搭建好了,从库现在已经是半同步复制。

-------------------------------------
MGR 5.7.17以后 5.7.20以后
8.0以后的 innodb cluster 重要组成部分

------------------------------------
七、复制过滤(了解就好,工作中用的不多,大多数是用软件实现的)

先看一张图:
xxxxxxx

1:假如现在是一主2从(从1,从2)。主里面有三个库(bbs,blog,wordpress)
2: 现在我想在主从复制的时候, 只把bbs复制到从1,blog,wordpress 复制到从2
应该如何实现?
这个时候就需要复制过滤的功能;


主库方面:(可以这样设置,但是不能这样,所以不能主库设置白黑名单)
mysql> show master status;(可以看到Position后面还有三个参数)
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000006 | 361 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

白名单:只记录白名单中列出的库的二进制日志
binlog-do-db

黑名单:不记录黑名单列出的库的二进制日志
binlog-ignore-db

从库:

白名单:只执行白名单中列出的库或者表的中继日志

--replicate-do-db=test(一般情况只设置白名单就行。只用这一句,只复制这个库)
--replicate-do-table=test.t1
--replicate-wild-do-table=test.x*

黑名单:不执行黑名单中列出的库或者表的中继日志
--replicate-ignore-db
--replicate-ignore-table
--replicate-wild-ignore-table

例子:

[root@db01 data]# vim /data/3307/my.cnf
replicate-do-db=world

停掉3307从库。重新做主从复制:
mysqladmin -S /data/3307/mysql.sock shutdown
重新初始化数据,测试白名单。
mysqld_safe --defaults-file=/data/3307/my.cnf &
........此处省略搭建主从复制过程.....
++++++++++++++++++++
测试复制过滤:

第一次测试:
主库:
mysql -uroot -p123 -S /data/3308/mysql.sock
use world
create table t1(id int);

从库查看结果:
mysql -uroot -p123 -S /data/3307/mysql.sock
use world
show tables;
--------------

第二次测试:
主库:
mysql -uroot -p123 -S /data/3308/mysql.sock
use test
create table tb1(id int);

从库查看结果:
mysql -uroot -p123 -S /data/3307/mysql.sock
use test
show tables;

----------------------------------------------------------

Guess you like

Origin www.cnblogs.com/jim-xu/p/11668486.html