MySQL master-slave replication (8)-semi-synchronous replication configuration

MySQL master-slave replication (8)-semi-synchronous replication configuration

MySQL's asynchronous replication can provide the best performance. The master database sends the binlog log to the slave database. This action is over, and it does not verify whether the slave database has received it. It also means that when the main server or the slave server fails, it is possible that the slave server does not receive the binlog log sent by the master server, which will cause the data of the master server and the slave server to be inconsistent, and even cause data during recovery. The loss.

The semi-synchronous replication mode has been introduced since MySQL 5.5. This mode can ensure that the slave server receives the binlog log file sent by the master server and writes it to its own relay log, and then sends a feedback to the master server, telling the master server that the reception is complete, and then the main service thread Return to the current session to inform that the operation is complete.

The configuration process of semi-synchronous replication is as follows:

1. Operating environment

Operating system: CentOS Linux release 7.8.2003 (Core)
MySQL version: MySQL5.7
Primary server IP: 192.168.1.11
Slave server IP: 192.168.1.12

Second, the configuration of the main server

1. Install the semi-synchronous plugin

mysql> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
Query OK, 0 rows affected (0.04 sec)

2. Modify the configuration file

log-bin = mysql-master-binlog
log-slave-updates = 1
binlog_format = row

server-id = 1
server_id_bits = 33
rpl_semi_sync_master_enabled = 1  # 表示在master上开启半同步复制模式
rpl_semi_sync_master_timeout = 1000  # 表示主库在某次事务中的等待时间为10000毫秒

3. View semi-synchronous configuration information

mysql> SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME LIKE '%semi%';
+----------------------+---------------+
| PLUGIN_NAME          | PLUGIN_STATUS |
+----------------------+---------------+
| rpl_semi_sync_master | ACTIVE        |
+----------------------+---------------+
1 row in set (0.00 sec)

4. Create a copy account

mysql> grant replication slave on *.* to 'repl'@'192.168.1.%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

Third, the configuration of the slave server

1. Install the semi-synchronous plugin

mysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
Query OK, 0 rows affected (0.03 sec)

2. Modify the configuration file

log-bin = mysql-master-binlog
log-slave-updates = 1
binlog_format = row  

server-id = 2
server_id_bits = 32
rpl_semi_sync_slave_enabled = 1

3. View semi-synchronous configuration information

mysql> SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME LIKE '%semi%';
+---------------------+---------------+
| PLUGIN_NAME         | PLUGIN_STATUS |
+---------------------+---------------+
| rpl_semi_sync_slave | ACTIVE        |
+---------------------+---------------+
1 row in set (0.03 sec)

4. Set copy options

change master to
master_host='192.168.1.11',
master_user='repl',
master_password='123456',
MASTER_PORT=3306,
MASTER_AUTO_POSITION = 1;

5. Start the slave and check the status of the slave library

mysql> start slave;
Query OK, 0 rows affected (0.01 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.11
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-master-binlog.000002
          Read_Master_Log_Pos: 154
               Relay_Log_File: mysql-relay-log.000003
                Relay_Log_Pos: 387
        Relay_Master_Log_File: mysql-master-binlog.000002
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

Guess you like

Origin blog.csdn.net/weixin_44377973/article/details/107521694