我要评分
获取效率
正确性
完整性
易理解

Verifying HA

  1. Simulate a scenario where a secondary node is stopped and test read requests.
    1. Log in to secondary database 1.
      /usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysqls.sock
    2. Stop the database.
      shutdown;
    3. Log in to the primary database and view the group member information.
      /usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysqlm.sock
      select * from performance_schema.replication_group_members;

    4. Execute the read request script.
      sh /home/read_6447.sh

      The 127.0.0.1:3307 database service is stopped. Connections to the read port are routed only to 127.0.0.1:3308 as expected.

  2. Simulate a scenario where two secondary nodes are stopped and test the routing of read requests.
    1. Log in to secondary database 2.
      /usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysqls2.sock
    2. Stop the database.
      shutdown;
    3. Log in to the primary database and view the group member information.
      /usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysqlm.sock
      select * from performance_schema.replication_group_members;

    4. Execute the read request script.
      sh /home/read_6447.sh

      Both secondary servers are stopped. Connections to the read port are routed to the primary node (127.0.0.1:3306) as expected (implemented by using the round-robin-with-fallback algorithm).

  3. Simulate a primary role switchover.
    1. Start secondary databases 1 and 2.
      /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf-slave-mgr &
      /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf-slave-2-mgr &
    2. Log in to secondary databases 1 and 2.
      /usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysqls.sock
      /usr/local/mysql/bin/mysql -uroot -p123456 -S /data/mysql/run/mysqls2.sock
    3. Execute the following statement in secondary databases 1 and 2 separately to start MGR:
      START GROUP_REPLICATION;
    4. View the information about group members. You can view any member in the MGR group.
      select * from performance_schema.replication_group_members;

    5. Configure secondary database 2 as the primary and the other two databases as the secondaries.
      select group_replication_set_as_primary ('member_id of secondary database 2');

    6. Execute the read request script.
      sh /home/read_6446.sh

    7. Execute the write request script.
      1. Open the file.
        vim /home/write_6446.sh
      2. Replace the file content with the following:
        1
        2
        3
        4
        5
        #!/bin/bash
        for i in {1001..2000}
        do
        /usr/local/mysql/bin/mysql -uroot -p123456 -P6446 -h127.0.0.1 -Dsysbench -e "insert into test1(id,report_serverid) values($i,@@server_id)"
        done
        
      3. Press Esc, type :wq!, and press Enter to save the file and exit.
      4. Execute the write request script.
        1
        sh /home/write_6446.sh
        
      5. Confirm the test data.
        1
        /usr/local/mysql/bin/mysql -uroot -p123456 -P6446 -h127.0.0.1 -Dsysbench -e "select * from test1"
        

    8. Execute the read request script.
      sh /home/read_6447.sh

      All read and write requests of the write port 6446 are routed to the primary node 127.0.0.1:3308, and all read requests of the read port 6447 are routed to secondary nodes 127.0.0.1:3306 and 127.0.0.1:3307, which meets the expectation.