测试的命令:
masterha_check_repl
在gtid模式,非GTID模式
masterha_check_ssh
gtid 模式masterha_check_repl
1.寻找默认—global_conf文件 /etc/masterha_default.cnf
2.找到—conf并读取
3.使用user=用户尝试连接各个节点,判断master以及slave有哪些,并验证mysql的版本,,节点是否存活
4.判断出哪些是slave并进行检查:版本,gitd,binlog是否开启, Relay log info repository(为file/table检测都成功)是否 开启read_only,master是谁,是否有filtering ,gtid是否开启auto_pos,和非gtid的区别,不同模式开始有不同的应对策略
5.从slave尝试ssh连接其他主机
6.在current master 主机使用status运行master_ip_failover_script
7.检测shutdown_script脚本 
以下为debug输出
[root@mysql-zst3 .ssh]# masterha_check_repl —conf=/etc/masterha/app1.conf
Mon May 21 17:42:55 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping. 1。(默认寻找—global_conf文件 /etc/masterha_default.cnf )
Mon May 21 17:42:55 2018 - [info] Reading application default configuration from /etc/masterha/app1.conf.. (2.找到—conf并读取 )
Mon May 21 17:42:55 2018 - [info] Reading server configuration from /etc/masterha/app1.conf..
Mon May 21 17:42:55 2018 - [info] MHA::MasterMonitor version 0.57.
Mon May 21 17:42:55 2018 - [debug] Connecting to servers..(3.使用user=用户尝试连接各个节点,并验证mysql的版本,gtid是否开启,节点是否存活,)
Mon May 21 17:42:56 2018 - [debug] Connected to: zst2(172.0.0.51:3310), user=user1
Mon May 21 17:42:56 2018 - [debug] Number of slave worker threads on host zst2(172.0.0.51:3310): 0
Mon May 21 17:42:56 2018 - [debug] Connected to: zst3(172.0.0.52:3310), user=user1
Mon May 21 17:42:56 2018 - [debug] Number of slave worker threads on host zst3(172.0.0.52:3310): 0
Mon May 21 17:42:56 2018 - [debug] Comparing MySQL versions..
Mon May 21 17:42:56 2018 - [debug] Comparing MySQL versions done.
Mon May 21 17:42:56 2018 - [debug] Connecting to servers done.
Mon May 21 17:42:56 2018 - [info] GTID failover mode = 1
Mon May 21 17:42:56 2018 - [info] Dead Servers:
Mon May 21 17:42:56 2018 - [info] Alive Servers:
Mon May 21 17:42:56 2018 - [info] zst2(172.0.0.51:3310)
Mon May 21 17:42:56 2018 - [info] zst3(172.0.0.52:3310)
Mon May 21 17:42:56 2018 - [info] Alive Slaves:
(4.判断出哪些是slave并进行检查:版本,gitd,binlog是否开启, Relay log info repository,
是否开启read_only,master是谁,是否有filtering ,gtid是否开启auto_pos,
Mon May 21 17:42:56 2018 - [info] zst3(172.0.0.52:3310) Version=5.7.19-log (oldest major version between slaves) log-bin:enabled
Mon May 21 17:42:56 2018 - [info] GTID ON
Mon May 21 17:42:56 2018 - [debug] Relay log info repository: TABLE
Mon May 21 17:42:56 2018 - [info] Replicating from 172.0.0.51(172.0.0.51:3310)
Mon May 21 17:42:56 2018 - [info] Primary candidate for the new Master (candidate_master is set)
Mon May 21 17:42:56 2018 - [info] Current Alive Master: zst2(172.0.0.51:3310)
Mon May 21 17:42:56 2018 - [info] Checking slave configurations..
Mon May 21 17:42:56 2018 - [info] read_only=1 is not set on slave zst3(172.0.0.52:3310).
Mon May 21 17:42:56 2018 - [info] Checking replication filtering settings..
Mon May 21 17:42:56 2018 - [info] binlog_do_db= , binlog_ignore_db=
Mon May 21 17:42:56 2018 - [info] Replication filtering check ok.
Mon May 21 17:42:56 2018 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.(这里就是和非gtid的区别,不同模式开始有不同的应对策略)
Mon May 21 17:42:56 2018 - [info] Checking SSH publickey authentication settings on the current master..
(6.尝试ssh连接其他主机
Mon May 21 17:42:56 2018 - [debug] SSH connection test to zst2, option -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o BatchMode=yes -o ConnectTimeout=5, timeout 5
Mon May 21 17:42:56 2018 - [info] HealthCheck: SSH to zst2 is reachable.
Mon May 21 17:42:56 2018 - [info]
(7在current master 主机使用status运行master_ip_failover_script
zst2(172.0.0.51:3310) (current master)
+—zst3(172.0.0.52:3310)
Mon May 21 17:42:56 2018 - [info] Checking replication health on zst3..
Mon May 21 17:42:56 2018 - [info] ok.
Mon May 21 17:42:56 2018 - [info] Checking master_ip_failover_script status:
Mon May 21 17:42:56 2018 - [info] /etc/masterha/master_ip_failover —command=status —ssh_user=root —orig_master_host=zst2 —orig_master_ip=172.0.0.51 —orig_master_port=3310
Mon May 21 17:42:56 2018 - [info] OK.
(8检测shutdown_script脚本
Mon May 21 17:42:56 2018 - [warning] shutdown_script is not defined.
Mon May 21 17:42:56 2018 - [debug] Disconnected from zst2(172.0.0.51:3310)
Mon May 21 17:42:56 2018 - [debug] Disconnected from zst3(172.0.0.52:3310)
Mon May 21 17:42:56 2018 - [info] Got exit code 0 (Not master dead).
MySQL Replication Health is OK.
非GTIDmasterha_check_repl

Thu May 24 18:13:38 2018 - [debug] SSH connection test to zst3, option -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o BatchMode=yes -o ConnectTimeout=5, timeout 5
Thu May 24 18:13:38 2018 - [info] HealthCheck: SSH to zst3 is reachable.
Thu May 24 18:13:39 2018 - [info] Master MHA Node version is 0.57.
Thu May 24 18:13:39 2018 - [info] Checking recovery script configurations on zst3(172.0.0.52:3310)..判定master后再master执行recovery script
Thu May 24 18:13:39 2018 - [info] Executing command: save_binary_logs —command=test —start_pos=4 —binlog_dir=/data/mysql/mysql3310/logs —output_file=/data/mha/app1/save_bin ary_logs_test —manager_version=0.57 —start_file=mysql-bin.000004 —debug (是现master的show master status位置)
Thu May 24 18:13:39 2018 - [info] Connecting to root@172.0.0.52(zst3:22)..
Creating /data/mha/app1 if not exists.. ok.
Checking output directory is accessible or not..
ok.
Binlog found at /data/mysql/mysql3310/logs, up to mysql-bin.000004
Thu May 24 18:13:39 2018 - [info] Binlog setting check done.
Thu May 24 18:13:39 2018 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..(在所有slave上进行测试应用realy_log)
Thu May 24 18:13:39 2018 - [info] Executing command : apply_diff_relay_logs —command=test —slave_user=’user1’ —slave_host=zst2 —slave_ip=172.0.0.51 —slave_port=3310 —workdir=/data/mha/app1 —target_version=5.7.19-log —manager_version=0.57 —relay_dir=/data/mysql/mysql3310/data —current_relay_log=relay-bin.000007 —debug —slave_pass=xxx
Thu May 24 18:13:39 2018 - [info] Connecting to root@172.0.0.51(zst2:22)..
Checking slave recovery environment settings..
Relay log found at /data/mysql/mysql3310/data, up to relay-bin.000008Temporary relay log file is /data/mysql/mysql3310/data/relay-bin.000008Testing mysql connection and privileges..mysql: [Warning] Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
masterha_check_ssh
注意:这个脚本最好在所有节点都运行一遍。不过该脚本应该在运行在manager上运行成功即可。
[root@mysql-zst3 .ssh]# masterha_check_ssh —conf=/etc/masterha/app1.conf
Mon May 21 17:38:04 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon May 21 17:38:04 2018 - [info] Reading application default configuration from /etc/masterha/app1.conf..
Mon May 21 17:38:04 2018 - [info] Reading server configuration from /etc/masterha/app1.conf..
Mon May 21 17:38:04 2018 - [info] Starting SSH connection tests..
Mon May 21 17:38:05 2018 - [debug]
Mon May 21 17:38:04 2018 - [debug] Connecting via SSH from root@zst2(172.0.0.51:22) to root@zst3(172.0.0.52:22)..
Mon May 21 17:38:04 2018 - [debug] ok.
Mon May 21 17:38:05 2018 - [debug]
Mon May 21 17:38:05 2018 - [debug] Connecting via SSH from root@zst3(172.0.0.52:22) to root@zst2(172.0.0.51:22)..
Mon May 21 17:38:05 2018 - [debug] ok.
Mon May 21 17:38:05 2018 - [info] All SSH connection tests passed successfully.
