Skip to content

2.1 none 模式切换示例

arstercz edited this page Jun 30, 2021 · 5 revisions

none 模式切换示例

none 模式仅支持简单的主从切换, 在 /etc/masterha/switch.cnf 中增加以下配置:

# only switch master and slave
10.1.1.25:3327 10.1.1.26:3327
   mode none
   block_user ^percona$
   block_host ^10\.1\.1\.%$

主从检测

none 模式 下, master_check_repl 仅做主从检查:

$ masterha_check_repl --global_conf=/etc/masterha/default.cnf --conf=/etc/masterha/app_3327.cnf 
Wed Jun 30 19:49:51 2021 - [info] Reading default configuration from /etc/masterha/default.cnf..
Wed Jun 30 19:49:51 2021 - [info] Reading application default configuration from /etc/masterha/app_3327.cnf..
Wed Jun 30 19:49:51 2021 - [info] Updating application default configuration from /usr/bin/init_conf_loads..
Wed Jun 30 19:49:51 2021 - [info] Reading server configuration from /etc/masterha/app_3327.cnf..
Wed Jun 30 19:49:51 2021 - [info] MHA::MasterMonitor version 0.58.
Wed Jun 30 19:49:52 2021 - [info] GTID failover mode = 1
Wed Jun 30 19:49:52 2021 - [info] Dead Servers:
Wed Jun 30 19:49:52 2021 - [info] Alive Servers:
Wed Jun 30 19:49:52 2021 - [info]   10.1.1.26(10.1.1.26:3327)
Wed Jun 30 19:49:52 2021 - [info]   10.1.1.25(10.1.1.25:3327)
Wed Jun 30 19:49:52 2021 - [info] Alive Slaves:
Wed Jun 30 19:49:52 2021 - [info]   10.1.1.25(10.1.1.25:3327)  Version=5.7.28-31-log (oldest major version between slaves) log-bin:enabled
Wed Jun 30 19:49:52 2021 - [info]     GTID ON
Wed Jun 30 19:49:52 2021 - [info]     Replicating from 10.1.1.26(10.1.1.26:3327)
Wed Jun 30 19:49:52 2021 - [info]     Primary candidate for the new Master (candidate_master is set)
Wed Jun 30 19:49:52 2021 - [info] Current Alive Master: 10.1.1.26(10.1.1.26:3327)
Wed Jun 30 19:49:52 2021 - [info] Checking slave configurations..
Wed Jun 30 19:49:52 2021 - [info] Checking replication filtering settings..
Wed Jun 30 19:49:52 2021 - [info]  binlog_do_db= , binlog_ignore_db= 
Wed Jun 30 19:49:52 2021 - [info]  Replication filtering check ok.
Wed Jun 30 19:49:52 2021 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Wed Jun 30 19:49:52 2021 - [info] Checking SSH publickey authentication settings on the current master..
Wed Jun 30 19:49:52 2021 - [info] HealthCheck: SSH to 10.1.1.26 is reachable.
Wed Jun 30 19:49:52 2021 - [info] 
10.1.1.26(10.1.1.26:3327) (current master)
 +--10.1.1.25(10.1.1.25:3327)

Wed Jun 30 19:49:52 2021 - [info] Checking replication health on 10.1.1.25..
Wed Jun 30 19:49:52 2021 - [info]  ok.
Wed Jun 30 19:49:52 2021 - [info] Checking master_ip_failover_script status:
Wed Jun 30 19:49:52 2021 - [info]   /usr/bin/master_ip_failover --command=status --ssh_user=mha --orig_master_host=10.1.1.26 --orig_master_ip=10.1.1.26 --orig_master_port=3327  --ssh_options='-o ServerAliveInterval=60 -o ServerAliveCountMax=20 -o StrictHostKeyChecking=no -o ConnectionAttempts=5 -o PasswordAuthentication=no -o BatchMode=yes -i /home/mha/.ssh/id_rsa -o ConnectTimeout=3' 
Wed Jun 30 19:49:52 2021 - [info]  OK.
Wed Jun 30 19:49:52 2021 - [warning] shutdown_script is not defined.
Wed Jun 30 19:49:52 2021 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.

主从切换

以 alive 模式切换主从, 如下:

10.1.1.26(10.1.1.26:3327) (current master)
 +--10.1.1.25(10.1.1.25:3327)

To:
10.1.1.25(10.1.1.25:3327) (new master)
 +--10.1.1.26(10.1.1.26:3327)

切换日志见:

$ masterha_master_switch --master_state=alive --global_conf=/etc/masterha/default.cnf --conf=/etc/masterha/app_3327.cnf --orig_master_is_new_slave
Wed Jun 30 19:55:36 2021 - [info] MHA::MasterRotate version 0.58.
Wed Jun 30 19:55:36 2021 - [info] Starting online master switch..
Wed Jun 30 19:55:36 2021 - [info] 
Wed Jun 30 19:55:36 2021 - [info] * Phase 1: Configuration Check Phase..
Wed Jun 30 19:55:36 2021 - [info] 
Wed Jun 30 19:55:36 2021 - [info] Reading default configuration from /etc/masterha/default.cnf..
Wed Jun 30 19:55:36 2021 - [info] Reading application default configuration from /etc/masterha/app_3327.cnf..
Wed Jun 30 19:55:36 2021 - [info] Updating application default configuration from /usr/bin/init_conf_loads..
Wed Jun 30 19:55:36 2021 - [info] Reading server configuration from /etc/masterha/app_3327.cnf..
Wed Jun 30 19:55:38 2021 - [info] GTID failover mode = 1
Wed Jun 30 19:55:38 2021 - [info] Current Alive Master: 10.1.1.26(10.1.1.26:3327)
Wed Jun 30 19:55:38 2021 - [info] Alive Slaves:
Wed Jun 30 19:55:38 2021 - [info]   10.1.1.25(10.1.1.25:3327)  Version=5.7.28-31-log (oldest major version between slaves) log-bin:enabled
Wed Jun 30 19:55:38 2021 - [info]     GTID ON
Wed Jun 30 19:55:38 2021 - [info]     Replicating from 10.1.1.26(10.1.1.26:3327)
Wed Jun 30 19:55:38 2021 - [info]     Primary candidate for the new Master (candidate_master is set)

It is better to execute FLUSH NO_WRITE_TO_BINLOG TABLES on the master before switching. Is it ok to execute on 10.1.1.26(10.1.1.26:3327)? (YES/no): yes
Wed Jun 30 19:55:39 2021 - [info] Executing FLUSH NO_WRITE_TO_BINLOG TABLES. This may take long time..
Wed Jun 30 19:55:39 2021 - [info]  ok.
Wed Jun 30 19:55:39 2021 - [info] Checking MHA is not monitoring or doing failover..
Wed Jun 30 19:55:39 2021 - [info] Checking replication health on 10.1.1.25..
Wed Jun 30 19:55:39 2021 - [info]  ok.
Wed Jun 30 19:55:39 2021 - [info] Searching new master from slaves..
Wed Jun 30 19:55:39 2021 - [info]  Candidate masters from the configuration file:
Wed Jun 30 19:55:39 2021 - [info]   10.1.1.26(10.1.1.26:3327)  Version=5.7.28-31-log log-bin:enabled
Wed Jun 30 19:55:39 2021 - [info]     GTID ON
Wed Jun 30 19:55:39 2021 - [info]   10.1.1.25(10.1.1.25:3327)  Version=5.7.28-31-log (oldest major version between slaves) log-bin:enabled
Wed Jun 30 19:55:39 2021 - [info]     GTID ON
Wed Jun 30 19:55:39 2021 - [info]     Replicating from 10.1.1.26(10.1.1.26:3327)
Wed Jun 30 19:55:39 2021 - [info]     Primary candidate for the new Master (candidate_master is set)
Wed Jun 30 19:55:39 2021 - [info]  Non-candidate masters:
Wed Jun 30 19:55:39 2021 - [info]  Searching from candidate_master slaves which have received the latest relay log events..
Wed Jun 30 19:55:39 2021 - [info] 
From:
10.1.1.26(10.1.1.26:3327) (current master)
 +--10.1.1.25(10.1.1.25:3327)

To:
10.1.1.25(10.1.1.25:3327) (new master)
 +--10.1.1.26(10.1.1.26:3327)

Starting master switch from 10.1.1.26(10.1.1.26:3327) to 10.1.1.25(10.1.1.25:3327)? (yes/NO): yes
Wed Jun 30 19:55:40 2021 - [info] Checking whether 10.1.1.25(10.1.1.25:3327) is ok for the new master..
Wed Jun 30 19:55:40 2021 - [info]  ok.
Wed Jun 30 19:55:40 2021 - [info] 10.1.1.26(10.1.1.26:3327): SHOW SLAVE STATUS returned empty result. To check replication filtering rules, temporarily executing CHANGE MASTER to a dummy host.
Wed Jun 30 19:55:40 2021 - [info] 10.1.1.26(10.1.1.26:3327): Resetting slave pointing to the dummy host.
Wed Jun 30 19:55:40 2021 - [info] ** Phase 1: Configuration Check Phase completed.
Wed Jun 30 19:55:40 2021 - [info] 
Wed Jun 30 19:55:40 2021 - [info] * Phase 2: Rejecting updates Phase..
Wed Jun 30 19:55:40 2021 - [info] 
Wed Jun 30 19:55:40 2021 - [info] Executing master ip online change script to disable write on the current master:
Wed Jun 30 19:55:40 2021 - [info]   /usr/bin/master_ip_online_change --command=stop --orig_master_host=10.1.1.26 --orig_master_ip=10.1.1.26 --orig_master_port=3327 --orig_master_user='root' --new_master_host=10.1.1.25 --new_master_ip=10.1.1.25 --new_master_port=3327 --new_master_user='root' --orig_master_ssh_user=mha --new_master_ssh_user=mha  --ssh_options='-o ServerAliveInterval=60 -o ServerAliveCountMax=20 -o StrictHostKeyChecking=no -o ConnectionAttempts=5 -o PasswordAuthentication=no -o BatchMode=yes -i /home/mha/.ssh/id_rsa -o ConnectTimeout=3'   --orig_master_is_new_slave --orig_master_password=xxx --new_master_password=xxx
Wed Jun 30 19:55:40 2021.579916 Set read_only on the new master.. new master is read only ok.
Wed Jun 30 19:55:40 2021.583593 set off the scheduler if orig master enable the event scheduler.
Wed Jun 30 19:55:40 2021.589895 Blocking app user on the orig master..
Wed Jun 30 19:55:40 2021.591784 Waiting all running 2 threads are disconnected.. (max 1500 milliseconds)
{'Time' => '3','db' => undef,'Id' => '4531','User' => 'monitor','State' => '','Command' => 'Sleep','Rows_examined' => '0','Info' => undef,'Rows_sent' => '1','Host' => '10.1.1.27:11352'}
{'Time' => '98520','db' => undef,'Id' => '4578','User' => 'user_replica','State' => 'Master has sent all binlog to slave; waiting for more updates','Command' => 'Binlog Dump GTID','Rows_examined' => '0','Info' => undef,'Rows_sent' => '0','Host' => '10.1.1.25:37462'}
Wed Jun 30 19:55:41 2021.092562 Waiting all running 3 threads are disconnected.. (max 1000 milliseconds)
{'Time' => '4','db' => undef,'Id' => '4531','User' => 'monitor','State' => '','Command' => 'Sleep','Rows_examined' => '0','Info' => undef,'Rows_sent' => '1','Host' => '10.1.1.27:11352'}
{'Time' => '98521','db' => undef,'Id' => '4578','User' => 'user_replica','State' => 'Master has sent all binlog to slave; waiting for more updates','Command' => 'Binlog Dump GTID','Rows_examined' => '0','Info' => undef,'Rows_sent' => '0','Host' => '10.1.1.25:37462'}
{'Time' => '1','db' => undef,'Id' => '5390','User' => 'monitor','State' => '','Command' => 'Sleep','Rows_examined' => '0','Info' => undef,'Rows_sent' => '0','Host' => '10.1.1.27:1800'}
Wed Jun 30 19:55:41 2021.593221 Waiting all running 3 threads are disconnected.. (max 500 milliseconds)
{'Time' => '4','db' => undef,'Id' => '4531','User' => 'monitor','State' => '','Command' => 'Sleep','Rows_examined' => '0','Info' => undef,'Rows_sent' => '1','Host' => '10.1.1.27:11352'}
{'Time' => '98521','db' => undef,'Id' => '4578','User' => 'user_replica','State' => 'Master has sent all binlog to slave; waiting for more updates','Command' => 'Binlog Dump GTID','Rows_examined' => '0','Info' => undef,'Rows_sent' => '0','Host' => '10.1.1.25:37462'}
{'Time' => '1','db' => undef,'Id' => '5390','User' => 'monitor','State' => '','Command' => 'Sleep','Rows_examined' => '0','Info' => undef,'Rows_sent' => '0','Host' => '10.1.1.27:1800'}
Wed Jun 30 19:55:42 2021.093679 Set read_only=1 on the orig master.. orig master set read only ok.
Wed Jun 30 19:55:42 2021.095646 Waiting all running 3 queries are disconnected.. (max 500 milliseconds)
{'Time' => '1','db' => undef,'Id' => '4531','User' => 'monitor','State' => '','Command' => 'Sleep','Rows_examined' => '0','Info' => undef,'Rows_sent' => '1','Host' => '10.1.1.27:11352'}
{'Time' => '98522','db' => undef,'Id' => '4578','User' => 'user_replica','State' => 'Master has sent all binlog to slave; waiting for more updates','Command' => 'Binlog Dump GTID','Rows_examined' => '0','Info' => undef,'Rows_sent' => '0','Host' => '10.1.1.25:37462'}
{'Time' => '2','db' => undef,'Id' => '5390','User' => 'monitor','State' => '','Command' => 'Sleep','Rows_examined' => '0','Info' => undef,'Rows_sent' => '0','Host' => '10.1.1.27:1800'}
Wed Jun 30 19:55:42 2021.594411 Killing all application threads..
Wed Jun 30 19:55:42 2021.595272 done.
Wed Jun 30 19:55:42 2021.595724 Release app user on the orig master..
Wed Jun 30 19:55:42 2021.596871reset orig master rpl_semi_sync variables if enable semi replication
Wed Jun 30 19:55:42 2021 - [info]  ok.
Wed Jun 30 19:55:42 2021 - [info] Locking all tables on the orig master to reject updates from everybody (including root):
Wed Jun 30 19:55:42 2021 - [info] Executing FLUSH TABLES WITH READ LOCK..
Wed Jun 30 19:55:42 2021 - [info]  ok.
Wed Jun 30 19:55:42 2021 - [info] Orig master binlog:pos is mysql-bin.000002:1171.
Wed Jun 30 19:55:42 2021 - [info]  Waiting to execute all relay logs on 10.1.1.25(10.1.1.25:3327)..
Wed Jun 30 19:55:42 2021 - [info]  master_pos_wait(mysql-bin.000002:1171) completed on 10.1.1.25(10.1.1.25:3327). Executed 0 events.
Wed Jun 30 19:55:42 2021 - [info]   done.
Wed Jun 30 19:55:42 2021 - [info] Getting new master's binlog name and position..
Wed Jun 30 19:55:42 2021 - [info]  mysql-bin.000002:1171
Wed Jun 30 19:55:42 2021 - [info]  All other slaves should start replication from here. The new master Executed_Gtid_Set:'3c7ff0ba-d656-11eb-8b77-bc305bf87da4:1-5'
        Statement should be: CHANGE MASTER TO MASTER_HOST='10.1.1.25', MASTER_PORT=3327, MASTER_AUTO_POSITION=1, MASTER_USER='user_replica', MASTER_PASSWORD='xxx';
Wed Jun 30 19:55:42 2021 - [info] Executing master ip online change script to allow write on the new master:
Wed Jun 30 19:55:42 2021 - [info]   /usr/bin/master_ip_online_change --command=start --orig_master_host=10.1.1.26 --orig_master_ip=10.1.1.26 --orig_master_port=3327 --orig_master_user='root' --new_master_host=10.1.1.25 --new_master_ip=10.1.1.25 --new_master_port=3327 --new_master_user='root' --orig_master_ssh_user=mha --new_master_ssh_user=mha  --ssh_options='-o ServerAliveInterval=60 -o ServerAliveCountMax=20 -o StrictHostKeyChecking=no -o ConnectionAttempts=5 -o PasswordAuthentication=no -o BatchMode=yes -i /home/mha/.ssh/id_rsa -o ConnectTimeout=3'   --orig_master_is_new_slave --orig_master_password=xxx --new_master_password=xxx
Wed Jun 30 19:55:42 2021.816895 Set read_only=0 on the new master.
Wed Jun 30 19:55:42 2021.818126 Releasing app user on the new master..
Wed Jun 30 19:55:42 2021.820248 reset new master rpl_semi_sync variables if enable semi replication
Wed Jun 30 19:55:42 2021.826066 set on the scheduler if new master enable the event scheduler.