MariaDB semi-synchronous test

MariaDB semi-synchronous test

surroundings:

  • 192.168.205.17: as master server
  • 192.168.205.27: as slave server
  • 192.168.205.37: as slave server

version:

  • OS: centos 7 1810 with mini install
  • mariadb-5.5.60

Joint:

By default, MySQL copy function is asynchronous, asynchronous replication can provide the best performance, the master database sends binlog i.e. from the end of the log to the database to verify not been received from the library. This means that when the primary server or from the server fails, there may not be received from the server binlog log sent from the master server, which will result in inconsistent data in the primary and secondary servers, and even cause data loss during recovery, semisynchronous solve the performance and data security, integration, synchronization as long as there is a confirmation from the server from the server synchronization is complete, return results, do not wait until all the copy is complete, this solves the data synchronously replicated to wait for all return results from the server to achieve the best combination of performance and data security

step:

  1. Database installation script on all servers, run the following initialization
        [root@master ~]#cat /data/maridb_yum.sh 
    rpm -q mariadb-server ||yum install -y mariadb-server
    mkdir /data/{mysql,logs}
    chown mysql:mysql /data/{mysql,logs}
    sed -i '/\[mysqld\]/a log-bin=/data/logs/bin' /etc/my.cnf
    sed -i '/\[mysqld\]/a innodb_file_per_table = on' /etc/my.cnf
    sed -i '/\[mysqld\]/a skip_name_resolve = on' /etc/my.cnf
    sed -i 's@(datadir=).*@\1/data/mysql@' /etc/my.cnf 
  2. Modify the configuration file
    [root@master ~]#vi /etc/my.cnf
    [mysqld]
    server-id=17
    [root@slave1 ~]#vi /etc/my.cnf
    [mysqld]
    server-id=27    
    [root@slave2 ~]#vi /etc/my.cnf
    [mysqld]
    server-id=37  
  3. Accounts and establishing synchronization, the recording position or the backup master server the master server recovers from the server on a second election
    MariaDB [(none)]> grant replication slave on *.* to repluser@'192.168.205.%' identified by 'centos';
    MariaDB [(none)]> show master logs;                                                                 
    +------------+-----------+
    | Log_name   | File_size |
    +------------+-----------+
    | bin.000001 |     30373 |
    | bin.000002 |   1038814 |
    | bin.000003 |       406 |
    +------------+-----------+
    3 rows in set (0.00 sec)
  4. Modify change master to slave servers, and enable slave

    MariaDB [(none)]> CHANGE MASTER TO 
        -> MASTER_HOST='192.168.205.17', 
        -> MASTER_USER='repluser', 
        -> MASTER_PASSWORD='centos', 
        -> MASTER_PORT=3306,
        -> MASTER_LOG_FILE='bin.000003', 
        -> MASTER_LOG_POS=406; 
    Query OK, 0 rows affected (0.01 sec)
    
    MariaDB [(none)]> start slave;
    Query OK, 0 rows affected (0.00 sec)
    
    MariaDB [(none)]> show slave status\G
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for master to send event
                      Master_Host: 192.168.205.17
                      Master_User: repluser
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: bin.000003
              Read_Master_Log_Pos: 406
                   Relay_Log_File: mariadb-relay-bin.000002
                    Relay_Log_Pos: 523
            Relay_Master_Log_File: bin.000003
                 Slave_IO_Running: Yes
                Slave_SQL_Running: Yes
  5. To enable the semi-synchronous master-slave replication need to install a plug-in
    [root@centos7 data]#rpm -ql mariadb-server
    /usr/lib64/mysql/plugin/semisync_master.so
    /usr/lib64/mysql/plugin/semisync_slave.so
  6. In the database, you can view those plug-in installation
    MariaDB [(none)]> show plugins;
  7. Plug-in installed on the primary server
    MariaDB [(none)]> install plugin rpl_semi_sync_master soname 'semisync_master.so';
    Query OK, 0 rows affected (0.00 sec)
    MariaDB [(none)]> show plugins;
    …
    | rpl_semi_sync_master           | ACTIVE   | REPLICATION        | semisync_master.so | GPL     |
    +--------------------------------+----------+--------------------+--------------------+---------+
    43 rows in set (0.00 sec)
  8. View semi-synchronous state
    MariaDB [(none)]> show global variables like '%semi%' ;
    +------------------------------------+-------+
    | Variable_name                      | Value |
    +------------------------------------+-------+
    | rpl_semi_sync_master_enabled       | OFF   | #半同步默认off
    | rpl_semi_sync_master_timeout       | 10000 | #超时毫秒,10秒
    | rpl_semi_sync_master_trace_level   | 32    |
    | rpl_semi_sync_master_wait_no_slave | ON    |
    +------------------------------------+-------+
    4 rows in set (0.00 sec)
  9. Enable semisynchronous
    MariaDB [(none)]> set global rpl_semi_sync_master_enabled=on;
    Query OK, 0 rows affected (0.00 sec)
  10. Check the semi-synchronous status information
    MariaDB [(none)]> show global status like '%semi%';
    +--------------------------------------------+-------+
    | Variable_name                              | Value |
    +--------------------------------------------+-------+
    | Rpl_semi_sync_master_clients               | 0     |
    | Rpl_semi_sync_master_net_avg_wait_time     | 0     |
    | Rpl_semi_sync_master_net_wait_time         | 0     |
    | Rpl_semi_sync_master_net_waits             | 0     |
    | 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      | 0     |
    | Rpl_semi_sync_master_tx_wait_time          | 0     |
    | Rpl_semi_sync_master_tx_waits              | 0     |
    | Rpl_semi_sync_master_wait_pos_backtraverse | 0     |
    | Rpl_semi_sync_master_wait_sessions         | 0     |
    | Rpl_semi_sync_master_yes_tx                | 0     |
    +--------------------------------------------+-------+
    14 rows in set (0.00 sec)
  11. Installation slave semi plug from all nodes;
    MariaDB [(none)]>  install plugin rpl_semi_sync_slave soname 'semisync_slave.so';       
    Query OK, 0 rows affected (0.00 sec)
    MariaDB [(none)]> show plugins;
    …
    | rpl_semi_sync_slave            | ACTIVE   | REPLICATION        | semisync_slave.so | GPL     |
    +--------------------------------+----------+--------------------+-------------------+---------+
    43 rows in set (0.00 sec)
  12. Check the semi-synchronous slave state, and enabled, and you need to restart the thread, and then view the semi-synchronous state is only possible on

    MariaDB [(none)]> show global variables like '%semi%';
    +---------------------------------+-------+
    | Variable_name                   | Value |
    +---------------------------------+-------+
    | rpl_semi_sync_slave_enabled     | OFF   |
    | rpl_semi_sync_slave_trace_level | 32    |
    +---------------------------------+-------+
    2 rows in set (0.00 sec)
    MariaDB [(none)]> set global rpl_semi_sync_slave_enabled=on; 
    Query OK, 0 rows affected (0.00 sec)
    MariaDB [(none)]> 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)
    MariaDB [(none)]> stop slave;
    Query OK, 0 rows affected (0.00 sec)
    
    MariaDB [(none)]> start slave;
    Query OK, 0 rows affected (0.00 sec)
    MariaDB [(none)]> show global status like '%semi%';  
    +----------------------------+-------+
    | Variable_name              | Value |
    +----------------------------+-------+
    | Rpl_semi_sync_slave_status | ON    |
    +----------------------------+-------+
    1 row in set (0.00 sec)
  13. At this time, the master node status See
    MariaDB [(none)]> show global status like '%semi%';
    +--------------------------------------------+-------+
    | Variable_name                              | Value |
    +--------------------------------------------+-------+
    | Rpl_semi_sync_master_clients               | 2     |
    | Rpl_semi_sync_master_net_avg_wait_time     | 0     |
    | Rpl_semi_sync_master_net_wait_time         | 0     |
    | Rpl_semi_sync_master_net_waits             | 0     |
    | 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      | 0     |
    | Rpl_semi_sync_master_tx_wait_time          | 0     |
    | Rpl_semi_sync_master_tx_waits              | 0     |
    | Rpl_semi_sync_master_wait_pos_backtraverse | 0     |
    | Rpl_semi_sync_master_wait_sessions         | 0     |
    | Rpl_semi_sync_master_yes_tx                | 0     |
    +--------------------------------------------+-------+
    14 rows in set (0.00 sec)
  14. Test, create a library on the master node
    MariaDB [(none)]> create database db1;
    Query OK, 1 row affected (0.00 sec)
  15. On the node can be seen from the synchronization
    MariaDB [(none)]> show databases;     
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | db1                |
    | mysql              |
    | performance_schema |
    | test               |
    +--------------------+
    5 rows in set (0.00 sec)
  16. We stopped into this slave1, create the database at the primary site, the display can be successful only copied to the node slave2
    [root@slave1 ~]#systemctl stop mariadb
    MariaDB [(none)]> create database db2; 
    Query OK, 1 row affected (0.01 sec)
    MariaDB [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | db1                |
    | db2                |
    | mysql              |
    | performance_schema |
    | test               |
    +--------------------+
    6 rows in set (0.00 sec)
  17. If all stopped from the node, and then create a database from the master node, it will wait 10 seconds to appear successful
    [root@slave2 ~]#systemctl stop mariadb;
    MariaDB [(none)]> create database db3;
    Query OK, 1 row affected (10.00 sec)
  18. After two server restart, view the data will be synchronized
    [root@slave1 ~]#systemctl start mariadb 
    MariaDB [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | db1                |
    | db2                |
    | db3                |
    | mysql              |
    | performance_schema |
    | test               |
    +--------------------+
    7 rows in set (0.00 sec)

Guess you like

Origin blog.51cto.com/127601/2427333