MHA masterha_check_repl 檢測過程

來源:互聯網
上載者:User

MHA masterha_check_repl 檢測過程

MHA部署及配置是否OK,我們可以藉助於MHA內建的masterha_check_ssh以及masterha_check_repl指令碼來檢測。masterha_check_repl檢測是保證MHA成功切換的重要一步。本文主要描述了masterha_check_repl這個檢測指令碼到底做了些什麼事情。有助於更好的理解MHA的相關原理及過程等。

1、當前的主從環境
[root@vdbsrv1 ~]# more /etc/hosts
127.0.0.1    localhost.localdomain localhost
192.168.1.6  vdbsrv1  #master
192.168.1.7  vdbsrv2  #slave1
192.168.1.8  vdbsrv3  #slave2
192.168.1.12 vdbsrv4  #manager

###os環境
[root@vdbsrv4 ~]# more /etc/issue
CentOS release 5.9 (Final)
Kernel \r on an \m

###mysql環境
[root@vdbsrv4 ~]# mysql -e "show variables like 'version'"
+---------------+------------+
| Variable_name | Value      |
+---------------+------------+
| version      | 5.6.22-log |
+---------------+------------+

[root@vdbsrv4 ~]# masterha_manager --version
masterha_manager version 0.56.

 

2、當前的MHA配置資訊
[root@vdbsrv4 ~]$ more /etc/masterha/app1.cnf
[server default]
manager_workdir=/var/log/masterha/app1
manager_log=/var/log/masterha/app1/manager.log

user=mha
password=xxx
ssh_user=root
repl_user=repl 
repl_password=repl 
ping_interval=1
shutdown_script=""
master_ip_online_change_script=""
report_script=""
master_ip_failover_script=/tmp/master_ip_failover
 
[server1]
hostname=vdbsrv1
master_binlog_dir=/data/mysqldata

[server2]
hostname=vdbsrv2
master_binlog_dir=/data/mysqldata

[server3]
hostname=vdbsrv3
master_binlog_dir=/data/mysqldata/
#candidate_master=1

 

3、masterha_check_repl檢測步驟
a、讀取設定檔
b、檢測設定檔中列出的mysql伺服器(識別主從)
c、檢測從庫配置資訊
    read_only參數
    relay_log_purge參數
    複製過濾規則
d、ssh等效性驗證
e、檢測主庫儲存binlog指令碼(save_binary_logs) ,主要是用於在master死掉後從binlog讀取日誌
f、檢測各從庫能否apply差量binlog(apply_diff_relay_logs)
g、檢測IP切換,如果有部署指令碼

 

4、實際檢測過程
[root@vdbsrv4 ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf
Fri Apr 17 18:48:41 2015 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Fri Apr 17 18:48:41 2015 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Fri Apr 17 18:48:41 2015 - [info] Reading server configuration from /etc/masterha/app1.cnf.. ###讀取設定檔
Fri Apr 17 18:48:41 2015 - [info] MHA::MasterMonitor version 0.56.
Fri Apr 17 18:48:42 2015 - [info] GTID failover mode = 0
Fri Apr 17 18:48:42 2015 - [info] Dead Servers:  ###開始檢測設定檔中列出的mysql伺服器(識別主從)
Fri Apr 17 18:48:42 2015 - [info] Alive Servers:
Fri Apr 17 18:48:42 2015 - [info]  vdbsrv1(192.168.1.6:3306)
Fri Apr 17 18:48:42 2015 - [info]  vdbsrv2(192.168.1.7:3306)
Fri Apr 17 18:48:42 2015 - [info]  vdbsrv3(192.168.1.8:3306)
Fri Apr 17 18:48:42 2015 - [info] Alive Slaves:
Fri Apr 17 18:48:42 2015 - [info]  vdbsrv2(192.168.1.7:3306)  Version=5.6.22-log (oldest major version between slaves) log-bin:enabled
Fri Apr 17 18:48:42 2015 - [info]    Replicating from 192.168.1.6(192.168.1.6:3306)
Fri Apr 17 18:48:42 2015 - [info]  vdbsrv3(192.168.1.8:3306)  Version=5.6.22-log (oldest major version between slaves) log-bin:enabled
Fri Apr 17 18:48:42 2015 - [info]    Replicating from 192.168.1.6(192.168.1.6:3306)
Fri Apr 17 18:48:42 2015 - [info] Current Alive Master: vdbsrv1(192.168.1.6:3306)
Fri Apr 17 18:48:42 2015 - [info] Checking slave configurations..  ###檢測從庫配置資訊
Fri Apr 17 18:48:42 2015 - [info]  read_only=1 is not set on slave vdbsrv2(192.168.1.7:3306).
Fri Apr 17 18:48:42 2015 - [warning]  relay_log_purge=0 is not set on slave vdbsrv2(192.168.1.7:3306).
Fri Apr 17 18:48:42 2015 - [info]  read_only=1 is not set on slave vdbsrv3(192.168.1.8:3306).
Fri Apr 17 18:48:42 2015 - [warning]  relay_log_purge=0 is not set on slave vdbsrv3(192.168.1.8:3306).
Fri Apr 17 18:48:42 2015 - [info] Checking replication filtering settings..    ###檢測複製過濾規則
Fri Apr 17 18:48:42 2015 - [info]  binlog_do_db= , binlog_ignore_db=
Fri Apr 17 18:48:42 2015 - [info]  Replication filtering check ok.
Fri Apr 17 18:48:42 2015 - [info] GTID (with auto-pos) is not supported
Fri Apr 17 18:48:42 2015 - [info] Starting SSH connection tests..              ###ssh等效性驗證
Fri Apr 17 18:48:43 2015 - [info] All SSH connection tests passed successfully.
Fri Apr 17 18:48:43 2015 - [info] Checking MHA Node version..
Fri Apr 17 18:48:44 2015 - [info]  Version check ok.
Fri Apr 17 18:48:44 2015 - [info] Checking SSH publickey authentication settings on the current master..
Fri Apr 17 18:48:44 2015 - [info] HealthCheck: SSH to vdbsrv1 is reachable.
Fri Apr 17 18:48:44 2015 - [info] Master MHA Node version is 0.56.
Fri Apr 17 18:48:44 2015 - [info] Checking recovery script configurations on vdbsrv1(192.168.1.6:3306)..###檢測主庫儲存binlog指令碼
Fri Apr 17 18:48:44 2015 - [info]  Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/data/mysqldata
    --output_file=/var/tmp/save_binary_logs_test --manager_version=0.56 --start_file=mysql-bin.000012
Fri Apr 17 18:48:44 2015 - [info]  Connecting to [email protected](vdbsrv1:22)..
  Creating /var/tmp if not exists..    ok.
  Checking output directory is accessible or not..
  ok.
  Binlog found at /data/mysqldata, up to mysql-bin.000012
Fri Apr 17 18:48:44 2015 - [info] Binlog setting check done.  ###以下部分檢測各從庫能否apply差量binlog
Fri Apr 17 18:48:44 2015 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Fri Apr 17 18:48:44 2015 - [info]  Executing command : apply_diff_relay_logs --command=test --slave_user='mha' --slave_host=vdbsrv2
 --slave_ip=192.168.1.7 --slave_port=3306 --workdir=/var/tmp --target_version=5.6.22-log --manager_version=0.56
 --relay_log_info=/data/mysqldata/relay-log.info  --relay_dir=/data/mysqldata/  --slave_pass=xxx
Fri Apr 17 18:48:44 2015 - [info]  Connecting to [email protected](vdbsrv2:22)..
  Checking slave recovery environment settings..
    Opening /data/mysqldata/relay-log.info ... ok.
    Relay log found at /data/mysqldata, up to vdbsrv2-relay-bin.000006
    Temporary relay log file is /data/mysqldata/vdbsrv2-relay-bin.000006
    Testing mysql connection and privileges.. done.  #Author : Leshami
    Testing mysqlbinlog output.. done.              #Blog  : http://blog.csdn.net/leshami
    Cleaning up test file(s).. done.
Fri Apr 17 18:48:44 2015 - [info]  Executing command : apply_diff_relay_logs --command=test --slave_user='mha' --slave_host=vdbsrv3
 --slave_ip=192.168.1.8 --slave_port=3306 --workdir=/var/tmp --target_version=5.6.22-log --manager_version=0.56
 --relay_log_info=/data/mysqldata/relay-log.info  --relay_dir=/data/mysqldata/  --slave_pass=xxx
Fri Apr 17 18:48:44 2015 - [info]  Connecting to [email protected](vdbsrv3:22)..
  Checking slave recovery environment settings..
    Opening /data/mysqldata/relay-log.info ... ok.
    Relay log found at /data/mysqldata, up to vdbsrv3-relay-bin.000006
    Temporary relay log file is /data/mysqldata/vdbsrv3-relay-bin.000006
    Testing mysql connection and privileges.. done.
    Testing mysqlbinlog output.. done.
    Cleaning up test file(s).. done.
Fri Apr 17 18:48:45 2015 - [info] Slaves settings check done.
Fri Apr 17 18:48:45 2015 - [info]
vdbsrv1(192.168.1.6:3306) (current master)
 +--vdbsrv2(192.168.1.7:3306)
 +--vdbsrv3(192.168.1.8:3306)

Fri Apr 17 18:48:45 2015 - [info] Checking replication health on vdbsrv2..
Fri Apr 17 18:48:45 2015 - [info]  ok.
Fri Apr 17 18:48:45 2015 - [info] Checking replication health on vdbsrv3..
Fri Apr 17 18:48:45 2015 - [info]  ok.
Fri Apr 17 18:48:45 2015 - [info] Checking master_ip_failover_script status:  ###檢測IP切換
Fri Apr 17 18:48:45 2015 - [info]  /tmp/master_ip_failover --command=status --ssh_user=root --orig_master_host=vdbsrv1
  --orig_master_ip=192.168.1.6 --orig_master_port=3306

IN SCRIPT TEST====/sbin/ifconfig eth0:0 down==/sbin/ifconfig eth0:0 192.168.1.13/24===

Checking the Status of the script.. OK
Fri Apr 17 18:48:45 2015 - [info]  OK.
Fri Apr 17 18:48:45 2015 - [warning] shutdown_script is not defined.
Fri Apr 17 18:48:45 2015 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.