(5.14) mysql HA Series - cascading replication

table of Contents:

[0] Experimental demand
  cascading replication, 201 primary library, from the library of 202/203 for both the primary library, from the library 203 to 202
[1] Experimental Environment
  cascade: A-> B-> C
  Practice ideas:
    (1) a direct holding of xtrabackup is perfect to B and C can be further away
    (2) and then set gtid_purged, can finally change master;
[2] operation
  [2.0] profile my.cnf
  [2.1] in the master library creating a user copy 201
  [2.2] 201 creates the test data in the main database
  [2.3] backup and restore
  [2.4] Construction of the cascade master copy from
  [2.5] verification

 

text:

[0] experiment needs

  Cascading replication, 201 primary library, from the library of 202/203 for both the primary library, from the library 203 to 202

  General recommendations stage cascade, as described above, is not recommended more levels.

[1] experimental environment

  Operating System: CentOS 7.5

  Database Version: MySQL 5.7.24

  Database Schema: the master copy, based on the primary structures 3 library from the library, using lossless Xtrabackup + GTID + Replicable

  A: Main Library IP: 192.168.1.201 port: 3306

  B: main library IP: 192.168.1.202 port: 3306

  C: Main Library IP: 192.168.1.203 port: 3306

     Cascade: A-> B-> C

 

  Simple ideas:

    Initialize all equipment (. 1) with A, B, and B as the first from the main library A. Cullen

    (2) generating at least a B et gtid transaction is stopped io thread B, then initialize all equipment B to C.

    (3) C After all equipment to initialize B, and then arranged B-> C from master

  Practical ideas:

    (1) is directly take xtrabackup A to B and C, all equipment can be far

    (2) then set gtid_purged, can finally change master;

[2] Operation

[2.0] configuration file my.cnf

#replication_new 
log_bin = / MySQL / log / 3306 / mysql- bin # open binlog 
log_bin_index = / MySQL / log / 3306 / mysql- bin.index 
binlog_format = Row 
binlog_rows_query_log_events = ON 
max_binlog_size = 2048 

the bind -address = 0.0 . 0.0 
server_id = 2,013,306    # Always remember to modify 
expire_logs_days = 7     # binlog more than seven days of cleaning up 
innodb_support_xa = 1 
binlog_cache_size = 1M 
log_bin_trust_function_creators= 1     # synchronization procedures, functions, triggers 
the innodb_flush_log_at_trx_commit = 1 
sync_binlog = 1 
Transaction -isolation = Read-The committed 

#slave Parameter if it is from the library, sure release 
#relay_log = / MySQL / log / 3306 / relaylog / MySQL- Relay .log 
#read_only = . 1   
#slave -parallel-type = LOGICAL_CLOCK 
#slave -parallel-Workers = . 4 
#master_info_repository = Table #master_info logged to mysql.slave_master_info 
#relay_log_info_repository =  Table #relay_log will be recorded, mysql.slave_relay_log_info
#relay_log_recovery = . 1 
#slave_skip_errors = ddl_exist_errors 
#slave_preserve_commit_order = . 1 

# . 5 .7 reinforcing semi-synchronous 
# If 5. The . 7 , together with the foregoing parameters loose_, as in the following, if 5. The . 6 is used directly = rpl_semi_sync_master_enabled . 1 or the like Enough. 
# 5.7 I do here is directly enhance the semi-synchronous (loseless Semisynchronous) 

PLUGIN_DIR = / MySQL / App / MySQL / lib / plugin / 
plugin_load = rpl_semi_sync_master = semisync_master.so; rpl_semi_sync_slave = semisync_slave.so 
loose_rpl_semi_sync_master_enabled = 1 #MySQL open the main semi-synchronous replication (rpl_semi_sync_master_enabled)
loose_rpl_semi_sync_slave_enabled = . 1 # MySQL5.6 open from the semi-synchronous replication 
loose_rpl_semi_sync_master_timeout = 5000 # 5 seconds time-out, cut back to asynchronous 
rpl_semi_sync_master_wait_for_slave_count = . 1 # ack 1 th slave receives at least the SPDC 
rpl_semi_sync_master_wait_point = AFTER_SYNC #MySQL . 5 method .7, AFTER_SYNC ( default value, enhanced semi-synchronous) & AFTER_COMMIT (conventional semi-synchronous) 
#GTID MODE 
gtid_mode = ON 
enforce_gtid_consistency = . 1 
log -slave-Updates = . 1

[2.1] 201 created copy the user in the main library

create user 'rpl'@'192.168.1.%' identified by '123456';
grant replication slave on *.* to 'rpl'@'192.168.1.%';
flush privileges;
select user,host from mysql.user;

[2.2] 201 to create test data in the main library

- [2.2.1] constructed test test1, test2, test3 table in the library and test library. Table test4 run business has been used to simulate the 
Create  Database Test;
 use Test;
 Create  Table test1 (ID int );
 INSERT  INTO test1 values ( . 1 );
 Create  Table test2 (ID int );
 INSERT  INTO test2 values ( 2 );
 Create  Table Test3 (ID int );
 INSERT  INTO Test3 values ( . 3 );
 the commit ;
Create  Table test4 (ID int );
 INSERT  INTO test4 values ( . 4 );
 the commit ; 

- [2.2.2] sp_test4 configured stored procedure to insert test4 cycle table, simulation run business 
use Test;
 drop  Procedure  IF  EXISTS sp_test4; 
DELIMITER $$ 
Create  Procedure sp_test4 ()
 the begin 
DECLARE n- int ;
 SET n- = . 11 ;
 the while (n- <= 20 is ) 
do 
INSERT  INTO test.test4values(n);
commit;
set n=n+1;
end while;
end $$
delimiter ;

-- 【2.2.3】构造事件,来调度sp_test4过程
use test;
set global event_scheduler=1;

delimiter $$
create event if not exists event_test4
on schedule every 5 second
on completion preserve
enable
do
begin
call sp_test4();
end $$
DELIMITER; 

- To prevent the test data amount accumulated lead Caton, I am here five hours to do a TRUNCATE 
DELIMITER $$
 the Create Event IF  not  EXISTS event_truncate_test4
 ON Schedule Every 5 hour
 ON Completion preserve 
enable 
do 
the begin 
TRUNCATE  the Table test.test4;
 End $$ 
delimiter;

[2.3] to back up and restore

In the master library # A: 201 
innobackupex --defaults File = / etc / -uroot--p123456 the my.cnf --no-timestamp /mysql/backup/full.bak 

# library from B / C: 202, 203,
SCP - [email protected] R & lt: /mysql/backup/full.bak / MySQL / Backup /
innobackupex --apply-Memory---user = log # 800M /mysql/backup/full.bak application the redo / use the undo
Music Videos Data DATAl
mkdir Data
innobackupex = --defaults-File / etc / --copy the my.cnf # copy-Back /mysql/backup/full.bak/ reduction
chown -R & lt MySQL: MySQL / MySQL
the chmod 755 -R & lt / MySQL

[2.4] Construction of the cascade master copy

#, Info file or binlog_info file found in xtrabackup backup gtid;
  
stop slave;
reset master;
reset slave all;
set
session sql_log_bin=0; set global gtid_purged='de853101-b165-11e9-900a-000c291f4171:1-1697'; set session sql_log_bin=1; change master to master_host='192.168.1.202', master_user='rpl', master_password='123456', master_auto_position=1;

# Verification from the master, in the implementation from the library
Show Slave Status \ G
Show PROCESSLIST;
SELECT COUNT (. 1) from test.test4;

[2.5] verification

# In the master library A: 201 performs 
Create Database test1;
Create Table test1.test1 (int ID);
INSERT INTO test1.test1 values (. 1);
the commit;
SELECT * from test1.test1;

# three verification database
select * from test1 .test1;

 

Guess you like

Origin www.cnblogs.com/gered/p/11613961.html