mysql database group replication (full synchronous replication)

Posted by JohnMike on Tue, 30 Jul 2019 11:58:25 +0200

1. Basic knowledge:

Group replication model:
    Single master model: automatically elect a master node from many MySQL nodes in the replication group, only the master node can write, and other nodes
    Automatically set to read only
    Multi-master model: Any node in the replication group can be written, so there is no concept of master and slave as long as the number of nodes suddenly fails
    Not much, and this multi-master model will continue to be available
 Group Replication Principle: A replication group consists of multiple server members, and each server member in the group can perform transactions independently.
    However, all read-write (RW) transactions are submitted only after the conflict detection is successful. Read-only (RO) transactions do not require conflict detection, they can be immediately
    Submit.
Advantages: MySQL group replication provides high availability, high flexibility, and reliable MySQL services
 Disadvantage: Group replication is inefficient. When the master node writes data, it waits for all slave nodes to replicate the data.
Then proceed on.
Each node of group replication may be slave

2. Experimental environment

server1:172.25.26.101 master node
server2:172.25.27.102 slave node
server3:172.25.27.103 slave node

 

 

 

 

server1,server2,server3 All of these packages need to be installed on top.

    mysql-community-client-5.7.24-1.el7.x86_64.rpm
    mysql-community-common-5.7.24-1.el7.x86_64.rpm
    mysql-community-libs-5.7.24-1.el7.x86_64.rpm
    mysql-community-libs-compat-5.7.24-1.el7.x86_64.rpm
    mysql-community-server-5.7.24-1.el7.x86_64.rpm
##Installation:
yum install -y *.rpm

##Initialization:
systemctl start mysqld
cat /var/log/mysqld.log | grep password		//View Initialization Password

mysql_secure_installation	//Initialization with Initialization Password
	    ZHAOjun@123		/New password--The remaining direct return


//Experiments: After initialization, if you delete the data file / var/lib/mysql /*, you only need to modify the password from the new (or from the new initialization)
    mysql -uroot -p						//Login with Initial Password
    alter user root@localhost identified by 'YLZ123+a';	//Change Password

3. Serr1 configuration

vim /etc/my.cnf
[mysqld]
    #Add the following new content
    server_id=1
    gtid_mode=ON
    enforce_gtid_consistency=ON
    master_info_repository=TABLE
    relay_log_info_repository=TABLE
    binlog_checksum=NONE         #Close binlog validation
    log_slave_updates=ON
    log_bin=binlog
    binlog_format=ROW            #Group replication depends on row-based replication format

    transaction_write_set_extraction=XXHASH64
    loose-group_replication_group_name="have access to uuidgen Generate a uuid,Write it here."
    loose-group_replication_start_on_boot=off
    loose-group_replication_local_address= "172.25.27.101:33061"    #Ip of the current node
    loose-group_replication_group_seeds="172.25.27.101:33061,
                                         172.25.27.102:33061,172.25.27.103:33061"
    loose-group_replication_bootstrap_group=off      
    ##Whether the plug-in boots automatically or not, this option generally needs to be off, just open by the node replicated by the initiator group.
    //And only start once, if on, the next time it starts again, it will generate a group with the same name, which may lead to brain fissure.
    loose-group_replication_ip_whitelist="127.0.0.1,172.25.20.0/24"
    loose-group_replication_enforce_update_everywhere_checks=ON #Each node can update data outward
    loose-group_replication_single_primary_mode=OFF        #Turn off single master mode

#Modify database password
systemctl restart mysqld        #clear shutdown and startup
cat /var/log/mysqld.log | grep password    #View Initialization Password
mysql -uroot -p            #Log on to the database using the initialization password
alter user root@localhost identified by 'ZHAOjun@123';    #Modify database password

#Create group replication users and authorize
SET SQL_LOG_BIN=0;Close binary logs
CREATE USER rpl_user@'%' IDENTIFIED BY 'YLZ123+a';
GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%';
FLUSH PRIVILEGES;
SET SQL_LOG_BIN=1;Open binary logs
CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='Yan+123kou' FOR CHANNEL 'group_replication_recovery';Configuring users
INSTALL PLUGIN group_replication SONAME 'group_replication.so';Installation group replication plug-in
SET GLOBAL group_replication_bootstrap_group=ON;Open it once on the first node
START GROUP_REPLICATION;Open group replication
SET GLOBAL group_replication_bootstrap_group=OFF; Closed group replication activation
SELECT * FROM performance_schema.replication_group_members;Viewing the status of the group, there is currently only one node Online

4,server2/server3

take server1 Upper/etc/my.cnf Copying files requires only two modifications.
vim /etc/my.cnf
    [mysqld]
    server_id=2/3
    loose-group_replication_local_address= "172.25.27.102/103:33061"	//Local ip. Write whatever it is

systemctl restart mysqld

mysql -uroot -pZHAOjun@123

SET SQL_LOG_BIN=0;
CREATE USER rpl_user@'%' IDENTIFIED BY 'ZHAOjun@123';	//Create replicate users
GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%';		    //Give replication permission
FLUSH PRIVILEGES;			//Refresh Authorization Form
SET SQL_LOG_BIN=1;
CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='ZHAOjun@123' FOR CHANNEL 'group_replication_recovery';
INSTALL PLUGIN group_replication SONAME 'group_replication.so';	//Download Group Replication Plug-in
SHOW PLUGINS;			//See
SHOW PLUGINS;
set global group_replication_allow_local_disjoint_gtids_join=on;
START GROUP_REPLICATION;		//Open group replication

5. Testing

#View group members on any node
SELECT * FROM performance_schema.replication_group_members;    

Error report 1: incorrect status after joining (not ONLINE, but RECOVERING)

Solution:

cd /var/lib/mysql	//Backup Server1 data
mysqldump --all-databases --single-transaction --routines --events \
--host=127.0.0.1 --port=3306 --user=root --password=YLZ123+a > dbdump.db

##Send to server 2/3
scp dbdump.db 172.25.27.102:/root
scp dbdump.db 172.25.27.103:/root

##server2/3
mysql -p < dbdump.db		//Import database. If there is an error, please read Error Report 2

CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='YLZ123+a' \
FOR CHANNEL 'group_replication_recovery';
start group_replication;
SELECT * FROM performance_schema.replication_group_members;

Error Reporting II: Importing Data Error

a. ERROR 1290 (HY000) at line 31: The MySQL server is running with the --super-read-only option so it cannot execute this statement.    
(mysql server runs with the super-read-only option, so this statement cannot be executed.) Solution: Turn mysql off and open again.
 

b. ERROR 1840 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty.    (@@
GLOBAL.GTID_PURGED can only be set in @@ GLOBAL.GTID_EXECUTED as space-time. )

 

 

 

Topics: MySQL RPM Database vim