1. 前言


MHA可以在较短的时间内实现自己主动故障检測和故障转移,通常在10-30秒以内;在复制框架中,MHA可以非常好地解决复制过程中的数据一致性问题,因为不须要在现有的replication中加入额外的server,仅须要一个manager节点,而一个Manager能管理多套复制。所以能大大地节约server的数量;另外,安装简单,无性能损耗,以及不须要改动现有的复制部署也是它的优势之处。

MHA还提供在线主库切换的功能,可以安全地切换当前执行的主库到一个新的主库中(通过将从库提升为主库),大概0.5-2秒内就可以完毕。

MHA提供了上述功能。使得其在适用于对高可用性。数据完整性要求高的场合。还有要求差点儿non-stop的主库维护。

这次主要是解说MHA的高速部署和简单配置。兴许补充高级特性以及相关架构吧。

2. 环境介绍

环境有限。我使用的是vmware虚拟机,搭建三台server,1主2从结构。

当中manager管理节点放在当中一台从库中。

1)server1(node节点)
OS:CentOS 6.4 X64
IPADDR:172.16.21.12(eth0);192.168.8.6(eth1)
HOSTNAME:mysql-mha01
DB:Mysql 5.5.43-log MySQL Community Server (GPL)
SOFTWARE:mha4mysql-node-0.56-0.el6.noarch.rpm
防火墙关闭;selinux关闭。

2)server2(node节点)
OS:CentOS 6.4 X64
IPADDR:172.16.21.13(eth2)。192.168.8.7(eth3)
HOSTNAME:mysql-mha02
DB:Mysql 5.5.43-log MySQL Community Server (GPL)
SOFTWARE:mha4mysql-node-0.56-0.el6.noarch.rpm
防火墙关闭。selinux关闭;

3)server3(node节点。manager节点)
OS:CentOS 6.4 X64
IPADDR:172.16.21.15(eth2);192.168.8.8(eth3)
HOSTNAME:mysql-mha01
DB:Mysql 5.5.43-log MySQL Community Server (GPL)
SOFTWARE:mha4mysql-node-0.56-0.el6.noarch.rpm。mha4mysql-manager-0.56-0.el6.noarch.rpm
防火墙关闭;selinux关闭;

MHA软件下载地址 

tm=2">https://code.google.com/p/mysql-master-ha/wiki/Downloads?tm=2

3. 软件安装

3.1 Node节点安装

在3个节点上安装node软件包。首先安装依赖包
  1. yum install perl-DBD-MySQL

安装node软件包

  1. rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm

3.2 Manager节点安装

安装依赖包
  1. yum install perl-Params-Validate perl-LWP-Simple perl-Config-Tiny perl-Time-HiRes perl-Log-Dispatch perl-Parallel-ForkManager
我当时配置的163的yum源没有perl-Log-Dispatch和perl-Parallel-ForkManager,所以就自己下载的rpm包安装,大家能够到http://pkgs.repoforge.org/ 下载自己须要的包。

  1. rpm -ivh perl-Log-Dispatch-2.26-1.el6.rf.noarch.rpm perl-Parallel-ForkManager-0.7.5-2.2.el6.rf.noarch.rpm

安装manager软件包

  1. rpm -ivh mha4mysql-manager-0.56-0.el6.noarch.rpm

4. MHA配置

4.1 Mysql复制配置

        此处就不具体说明了,大家能够參考我曾经的文章。http://blog.csdn.net/wjf870128/article/details/45170089 和 http://blog.csdn.net/wjf870128/article/details/45149573

我搭建的是半同步复制的一主双从结构。当中mysql-mha02为master节点,其它为slave节点。

复制账户passwordrepl/slavepass。(PS我们公司环境是5.5的所以这里的虚拟机也是用到的mysql5.5。如今MHA支持5.6的GTID复制。因此大家能够考虑使用5.6的gtid搭建。能够方便master因为崩溃恢复后又一次增加集群管理)


4.2 MHA配置

在管理节点mysql-mha02中建立配置文件
  1. mkdir -p /etc/MHA
  2. touch /etc/MHA/MHAmanager.conf

查看manager配置文件

  1. [server default]
  2. # mysql user and password
  3. user=root
  4. password=123456
  5. ssh_user=root
  6.  
  7. # mysql replication user and password
  8. repl_user=repl
  9. repl_password=slavepass
  10.  
  11. # working directory on the manager
  12. manager_workdir=/var/log/masterha/manager
  13.  
  14. # working directory on MySQL servers
  15. remote_workdir=/var/log/masterha/node
  16.  
  17. #Master Binlog dir
  18. master_binlog_dir=/var/lib/mysql/logs
  19.  
  20. #secondary route to detect the reachable of master
  21. secondary_check_script= masterha_secondary_check -s mysql-mha03 --user=root --master_host=mysql-mha02 --master_ip=172.16.21.13 --master_port=3306
  22.  
  23. #define the manager log
  24. manager_log=/var/log/masterha/manager.log
  25.  
  26. [server1]
  27. hostname=mysql-mha01
  28.  
  29. [server2]
  30. hostname=mysql-mha02
  31.  
  32. [server3]
  33. hostname=mysql-mha03

MHA其中具体參数大家能够參考 https://code.google.com/p/mysql-master-ha/wiki/Parameters

master_binlog_dir标志着master节点binlog的存放位置。假设大家没有使用默认的/var/lib/mysql的话须要单独制定。MHA在故障切换的时候假设master节点能够ssh联通的话会自己主动到该文件夹抓取日志文件来防止slave节点日志不完整。
workdir是manager节点和node节点的工作文件夹。在MHA管理启动时候。假设文件夹不存在,会通过ssh来进行创建。请保证ssh用户的权限。

4.3 主机信任

MHA环境须要保证manager和node之间的信任。
  1. ssh-keygen -t rsa
  2. ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.8.6
  3. ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.8.7
  4. ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.8.8

验证机器信任

  1. [root@mysql-mha03 ~]# masterha_check_ssh --conf=/etc/MHA/MHAmanager.conf
  2. Thu Jul 23 14:33:26 2015 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
  3. Thu Jul 23 14:33:26 2015 - [info] Reading application default configuration from /etc/MHA/MHAmanager.conf..
  4. Thu Jul 23 14:33:26 2015 - [info] Reading server configuration from /etc/MHA/MHAmanager.conf..
  5. Thu Jul 23 14:33:26 2015 - [info] Starting SSH connection tests..
  6. Thu Jul 23 14:33:26 2015 - [debug]
  7. Thu Jul 23 14:33:26 2015 - [debug] Connecting via SSH from root@mysql-mha01(192.168.8.6:22) to root@mysql-mha02(192.168.8.7:22)..
  8. Thu Jul 23 14:33:26 2015 - [debug] ok.
  9. Thu Jul 23 14:33:26 2015 - [debug] Connecting via SSH from root@mysql-mha01(192.168.8.6:22) to root@mysql-mha03(192.168.8.8:22)..
  10. Thu Jul 23 14:33:26 2015 - [debug] ok.
  11. Thu Jul 23 14:33:27 2015 - [debug]
  12. Thu Jul 23 14:33:26 2015 - [debug] Connecting via SSH from root@mysql-mha02(192.168.8.7:22) to root@mysql-mha01(192.168.8.6:22)..
  13. Thu Jul 23 14:33:26 2015 - [debug] ok.
  14. Thu Jul 23 14:33:26 2015 - [debug] Connecting via SSH from root@mysql-mha02(192.168.8.7:22) to root@mysql-mha03(192.168.8.8:22)..
  15. Thu Jul 23 14:33:27 2015 - [debug] ok.
  16. Thu Jul 23 14:33:27 2015 - [debug]
  17. Thu Jul 23 14:33:27 2015 - [debug] Connecting via SSH from root@mysql-mha03(192.168.8.8:22) to root@mysql-mha01(192.168.8.6:22)..
  18. Thu Jul 23 14:33:27 2015 - [debug] ok.
  19. Thu Jul 23 14:33:27 2015 - [debug] Connecting via SSH from root@mysql-mha03(192.168.8.8:22) to root@mysql-mha02(192.168.8.7:22)..
  20. Thu Jul 23 14:33:27 2015 - [debug] ok.
  21. Thu Jul 23 14:33:27 2015 - [info] All SSH connection tests passed successfully.

4.4 开启MHA

验证复制环境
  1. [root@mysql-mha03 ~]# masterha_check_repl --conf=/etc/MHA/MHAmanager.conf
  2. Thu Jul 23 14:40:27 2015 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
  3. Thu Jul 23 14:40:27 2015 - [info] Reading application default configuration from /etc/MHA/MHAmanager.conf..
  4. Thu Jul 23 14:40:27 2015 - [info] Reading server configuration from /etc/MHA/MHAmanager.conf..
  5. Thu Jul 23 14:40:27 2015 - [info] MHA::MasterMonitor version 0.56.
  6. Thu Jul 23 14:40:28 2015 - [info] GTID failover mode = 0
  7. Thu Jul 23 14:40:28 2015 - [info] Dead Servers:
  8. Thu Jul 23 14:40:28 2015 - [info] Alive Servers:
  9. Thu Jul 23 14:40:28 2015 - [info] mysql-mha01(192.168.8.6:3306)
  10. Thu Jul 23 14:40:28 2015 - [info] mysql-mha02(192.168.8.7:3306)
  11. Thu Jul 23 14:40:28 2015 - [info] mysql-mha03(192.168.8.8:3306)
  12. Thu Jul 23 14:40:28 2015 - [info] Alive Slaves:
  13. Thu Jul 23 14:40:28 2015 - [info] mysql-mha01(192.168.8.6:3306) Version=5.5.43-log (oldest major version between slaves) log-bin:enabled
  14. Thu Jul 23 14:40:28 2015 - [info] Replicating from 192.168.8.7(192.168.8.7:3306)
  15. Thu Jul 23 14:40:28 2015 - [info] mysql-mha03(192.168.8.8:3306) Version=5.5.43-log (oldest major version between slaves) log-bin:enabled
  16. Thu Jul 23 14:40:28 2015 - [info] Replicating from 192.168.8.7(192.168.8.7:3306)
  17. Thu Jul 23 14:40:28 2015 - [info] Current Alive Master: mysql-mha02(192.168.8.7:3306)
  18. Thu Jul 23 14:40:28 2015 - [info] Checking slave configurations..
  19. Thu Jul 23 14:40:28 2015 - [info] read_only=1 is not set on slave mysql-mha01(192.168.8.6:3306).
  20. Thu Jul 23 14:40:28 2015 - [info] read_only=1 is not set on slave mysql-mha03(192.168.8.8:3306).
  21. Thu Jul 23 14:40:28 2015 - [info] Checking replication filtering settings..
  22. Thu Jul 23 14:40:28 2015 - [info] binlog_do_db= , binlog_ignore_db=
  23. Thu Jul 23 14:40:28 2015 - [info] Replication filtering check ok.
  24. Thu Jul 23 14:40:28 2015 - [info] GTID (with auto-pos) is not supported
  25. Thu Jul 23 14:40:28 2015 - [info] Starting SSH connection tests..
  26. Thu Jul 23 14:40:29 2015 - [info] All SSH connection tests passed successfully.
  27. Thu Jul 23 14:40:29 2015 - [info] Checking MHA Node version..
  28. Thu Jul 23 14:40:29 2015 - [info] Version check ok.
  29. Thu Jul 23 14:40:29 2015 - [info] Checking SSH publickey authentication settings on the current master..
  30. Thu Jul 23 14:40:30 2015 - [info] HealthCheck: SSH to mysql-mha02 is reachable.
  31. Thu Jul 23 14:40:30 2015 - [info] Master MHA Node version is 0.56.
  32. Thu Jul 23 14:40:30 2015 - [info] Checking recovery script configurations on mysql-mha02(192.168.8.7:3306)..
  33. Thu Jul 23 14:40:30 2015 - [info] Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/var/lib/mysql/logs --output_file=/var/log/masterha/node/save_binary_logs_test --manager_version=0.56 --start_file=mysql-bin.000013
  34. Thu Jul 23 14:40:30 2015 - [info] Connecting to root@192.168.8.7(mysql-mha02:22)..
  35. Creating /var/log/masterha/node if not exists.. ok.
  36. Checking output directory is accessible or not..
  37. ok.
  38. Binlog found at /var/lib/mysql/logs, up to mysql-bin.000013
  39. Thu Jul 23 14:40:30 2015 - [info] Binlog setting check done.
  40. Thu Jul 23 14:40:30 2015 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
  41. Thu Jul 23 14:40:30 2015 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=mysql-mha01 --slave_ip=192.168.8.6 --slave_port=3306 --workdir=/var/log/masterha/node --target_version=5.5.43-log --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxx
  42. Thu Jul 23 14:40:30 2015 - [info] Connecting to root@192.168.8.6(mysql-mha01:22)..
  43. Checking slave recovery environment settings..
  44. Opening /var/lib/mysql/relay-log.info ... ok.
  45. Relay log found at /var/lib/mysql, up to mysql-mha01-relay-bin.000005
  46. Temporary relay log file is /var/lib/mysql/mysql-mha01-relay-bin.000005
  47. Testing mysql connection and privileges.. done.
  48. Testing mysqlbinlog output.. done.
  49. Cleaning up test file(s).. done.
  50. Thu Jul 23 14:40:30 2015 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=mysql-mha03 --slave_ip=192.168.8.8 --slave_port=3306 --workdir=/var/log/masterha/node --target_version=5.5.43-log --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxx
  51. Thu Jul 23 14:40:30 2015 - [info] Connecting to root@192.168.8.8(mysql-mha03:22)..
  52. Checking slave recovery environment settings..
  53. Opening /var/lib/mysql/relay-log.info ... ok.
  54. Relay log found at /var/lib/mysql, up to mysql-mha03-relay-bin.000005
  55. Temporary relay log file is /var/lib/mysql/mysql-mha03-relay-bin.000005
  56. Testing mysql connection and privileges.. done.
  57. Testing mysqlbinlog output.. done.
  58. Cleaning up test file(s).. done.
  59. Thu Jul 23 14:40:30 2015 - [info] Slaves settings check done.
  60. Thu Jul 23 14:40:30 2015 - [info]
  61. mysql-mha02(192.168.8.7:3306) (current master)
  62. +--mysql-mha01(192.168.8.6:3306)
  63. +--mysql-mha03(192.168.8.8:3306)
  64.  
  65. Thu Jul 23 14:40:30 2015 - [info] Checking replication health on mysql-mha01..
  66. Thu Jul 23 14:40:30 2015 - [info] ok.
  67. Thu Jul 23 14:40:30 2015 - [info] Checking replication health on mysql-mha03..
  68. Thu Jul 23 14:40:30 2015 - [info] ok.
  69. Thu Jul 23 14:40:30 2015 - [warning] master_ip_failover_script is not defined.
  70. Thu Jul 23 14:40:30 2015 - [warning] shutdown_script is not defined.
  71. Thu Jul 23 14:40:30 2015 - [info] Got exit code 0 (Not master dead).
  72.  
  73. MySQL Replication Health is OK.

启动mha manager

  1. [root@mysql-mha03 ~]# nohup masterha_manager --conf=/etc/MHA/MHAmanager.conf &
  2. [1] 5552

查看启动日志
  1. Thu Jul 23 14:49:01 2015 - [info] MHA::MasterMonitor version 0.56.
  2. Thu Jul 23 14:49:01 2015 - [info] GTID failover mode = 0
  3. Thu Jul 23 14:49:01 2015 - [info] Dead Servers:
  4. Thu Jul 23 14:49:01 2015 - [info] Alive Servers:
  5. Thu Jul 23 14:49:01 2015 - [info] mysql-mha01(192.168.8.6:3306)
  6. Thu Jul 23 14:49:01 2015 - [info] mysql-mha02(192.168.8.7:3306)
  7. Thu Jul 23 14:49:01 2015 - [info] mysql-mha03(192.168.8.8:3306)
  8. Thu Jul 23 14:49:01 2015 - [info] Alive Slaves:
  9. Thu Jul 23 14:49:01 2015 - [info] mysql-mha01(192.168.8.6:3306) Version=5.5.43-log (oldest major version between slaves) log-bin:enabled
  10. Thu Jul 23 14:49:01 2015 - [info] Replicating from 192.168.8.7(192.168.8.7:3306)
  11. Thu Jul 23 14:49:01 2015 - [info] mysql-mha03(192.168.8.8:3306) Version=5.5.43-log (oldest major version between slaves) log-bin:enabled
  12. Thu Jul 23 14:49:01 2015 - [info] Replicating from 192.168.8.7(192.168.8.7:3306)
  13. Thu Jul 23 14:49:01 2015 - [info] Current Alive Master: mysql-mha02(192.168.8.7:3306)
  14. Thu Jul 23 14:49:01 2015 - [info] Checking slave configurations..
  15. Thu Jul 23 14:49:01 2015 - [info] read_only=1 is not set on slave mysql-mha01(192.168.8.6:3306).
  16. Thu Jul 23 14:49:01 2015 - [info] read_only=1 is not set on slave mysql-mha03(192.168.8.8:3306).
  17. Thu Jul 23 14:49:01 2015 - [info] Checking replication filtering settings..
  18. Thu Jul 23 14:49:01 2015 - [info] binlog_do_db= , binlog_ignore_db=
  19. Thu Jul 23 14:49:01 2015 - [info] Replication filtering check ok.
  20. Thu Jul 23 14:49:01 2015 - [info] GTID (with auto-pos) is not supported
  21. Thu Jul 23 14:49:01 2015 - [info] Starting SSH connection tests..
  22. Thu Jul 23 14:49:02 2015 - [info] All SSH connection tests passed successfully.
  23. Thu Jul 23 14:49:02 2015 - [info] Checking MHA Node version..
  24. Thu Jul 23 14:49:03 2015 - [info] Version check ok.
  25. Thu Jul 23 14:49:03 2015 - [info] Checking SSH publickey authentication settings on the current master..
  26. Thu Jul 23 14:49:03 2015 - [info] HealthCheck: SSH to mysql-mha02 is reachable.
  27. Thu Jul 23 14:49:03 2015 - [info] Master MHA Node version is 0.56.
  28. Thu Jul 23 14:49:03 2015 - [info] Checking recovery script configurations on mysql-mha02(192.168.8.7:3306)..
  29. Thu Jul 23 14:49:03 2015 - [info] Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/var/lib/mysql/logs --output_file=/var/log/masterha/node/save_binary_logs_test --manager_version=0.56 --start_file=mysql-bin.000013
  30. Thu Jul 23 14:49:03 2015 - [info] Connecting to root@192.168.8.7(mysql-mha02:22)..
  31. Creating /var/log/masterha/node if not exists.. ok.
  32. Checking output directory is accessible or not..
  33. ok.
  34. Binlog found at /var/lib/mysql/logs, up to mysql-bin.000013
  35. Thu Jul 23 14:49:03 2015 - [info] Binlog setting check done.
  36. Thu Jul 23 14:49:03 2015 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
  37. Thu Jul 23 14:49:03 2015 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=mysql-mha01 --slave_ip=192.168.8.6 --slave_port=3306 --workdir=/var/log/masterha/node --target_version=5.5.43-log --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxx
  38. Thu Jul 23 14:49:03 2015 - [info] Connecting to root@192.168.8.6(mysql-mha01:22)..
  39. Checking slave recovery environment settings..
  40. Opening /var/lib/mysql/relay-log.info ... ok.
  41. Relay log found at /var/lib/mysql, up to mysql-mha01-relay-bin.000005
  42. Temporary relay log file is /var/lib/mysql/mysql-mha01-relay-bin.000005
  43. Testing mysql connection and privileges.. done.
  44. Testing mysqlbinlog output.. done.
  45. Cleaning up test file(s).. done.
  46. Thu Jul 23 14:49:03 2015 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=mysql-mha03 --slave_ip=192.168.8.8 --slave_port=3306 --workdir=/var/log/masterha/node --target_version=5.5.43-log --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxx
  47. Thu Jul 23 14:49:03 2015 - [info] Connecting to root@192.168.8.8(mysql-mha03:22)..
  48. Checking slave recovery environment settings..
  49. Opening /var/lib/mysql/relay-log.info ... ok.
  50. Relay log found at /var/lib/mysql, up to mysql-mha03-relay-bin.000005
  51. Temporary relay log file is /var/lib/mysql/mysql-mha03-relay-bin.000005
  52. Testing mysql connection and privileges.. done.
  53. Testing mysqlbinlog output.. done.
  54. Cleaning up test file(s).. done.
  55. Thu Jul 23 14:49:04 2015 - [info] Slaves settings check done.
  56. Thu Jul 23 14:49:04 2015 - [info]
  57. mysql-mha02(192.168.8.7:3306) (current master)
  58. +--mysql-mha01(192.168.8.6:3306)
  59. +--mysql-mha03(192.168.8.8:3306)
  60.  
  61. Thu Jul 23 14:49:04 2015 - [warning] master_ip_failover_script is not defined.
  62. Thu Jul 23 14:49:04 2015 - [warning] shutdown_script is not defined.
  63. Thu Jul 23 14:49:04 2015 - [info] Set master ping interval 3 seconds.
  64. Thu Jul 23 14:49:04 2015 - [info] Set secondary check script: masterha_secondary_check -s mysql-mha03 --user=root --master_host=mysql-mha02 --master_ip=172.16.21.13 --master_port=3306
  65. Thu Jul 23 14:49:04 2015 - [info] Starting ping health check on mysql-mha02(192.168.8.7:3306)..
  66. Thu Jul 23 14:49:04 2015 - [info] Ping(SELECT) succeeded, waiting until MySQL doesn't respond..

5. 验证MHA

5.1 故障切换

我们将master节点关闭
  1. [root@mysql-mha02 ~]# service mysql stop
  2. Shutting down MySQL...[ OK ]

查看manager的输出日志

  1. Thu Jul 23 14:59:13 2015 - [warning] Got error on MySQL select ping: 2006 (MySQL server has gone away)
  2. Thu Jul 23 14:59:13 2015 - [info] Executing SSH check script: save_binary_logs --command=test --start_pos=4 --binlog_dir=/var/lib/mysql/logs --output_file=/var/log/masterha/node/save_binary_logs_test --manager_version=0.56 --binlog_prefix=mysql-bin
  3. Thu Jul 23 14:59:13 2015 - [info] Executing secondary network check script: masterha_secondary_check -s mysql-mha03 --user=root --master_host=mysql-mha02 --master_ip=172.16.21.13 --master_port=3306 --user=root --master_host=mysql-mha02 --master_ip=192.168.8.7 --master_port=3306 --master_user=root --master_password=123456 --ping_type=SELECT
  4. Thu Jul 23 14:59:14 2015 - [info] HealthCheck: SSH to mysql-mha02 is reachable.
  5. Monitoring server mysql-mha03 is reachable, Master is not reachable from mysql-mha03. OK.
  6. Thu Jul 23 14:59:14 2015 - [info] Master is not reachable from all other monitoring servers. Failover should start.
  7. Thu Jul 23 14:59:16 2015 - [warning] Got error on MySQL connect: 2013 (Lost connection to MySQL server at 'reading initial communication packet', system error: 111)
  8. Thu Jul 23 14:59:16 2015 - [warning] Connection failed 2 time(s)..
  9. Thu Jul 23 14:59:19 2015 - [warning] Got error on MySQL connect: 2013 (Lost connection to MySQL server at 'reading initial communication packet', system error: 111)
  10. Thu Jul 23 14:59:19 2015 - [warning] Connection failed 3 time(s)..
  11. Thu Jul 23 14:59:22 2015 - [warning] Got error on MySQL connect: 2013 (Lost connection to MySQL server at 'reading initial communication packet', system error: 111)
  12. Thu Jul 23 14:59:22 2015 - [warning] Connection failed 4 time(s)..
  13. Thu Jul 23 14:59:22 2015 - [warning] Master is not reachable from health checker!
  14. Thu Jul 23 14:59:22 2015 - [warning] Master mysql-mha02(192.168.8.7:3306) is not reachable!
  15. Thu Jul 23 14:59:22 2015 - [warning] SSH is reachable.
  16. Thu Jul 23 14:59:22 2015 - [info] Connecting to a master server failed. Reading configuration file /etc/masterha_default.cnf and /etc/MHA/MHAmanager.conf again, and trying to connect to all servers to check server status..
  17. Thu Jul 23 14:59:22 2015 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
  18. Thu Jul 23 14:59:22 2015 - [info] Reading application default configuration from /etc/MHA/MHAmanager.conf..
  19. Thu Jul 23 14:59:22 2015 - [info] Reading server configuration from /etc/MHA/MHAmanager.conf..
  20. Thu Jul 23 14:59:22 2015 - [info] GTID failover mode = 0
  21. Thu Jul 23 14:59:22 2015 - [info] Dead Servers:
  22. Thu Jul 23 14:59:22 2015 - [info] mysql-mha02(192.168.8.7:3306)
  23. Thu Jul 23 14:59:22 2015 - [info] Alive Servers:
  24. Thu Jul 23 14:59:22 2015 - [info] mysql-mha01(192.168.8.6:3306)
  25. Thu Jul 23 14:59:22 2015 - [info] mysql-mha03(192.168.8.8:3306)
  26. Thu Jul 23 14:59:22 2015 - [info] Alive Slaves:
  27. Thu Jul 23 14:59:22 2015 - [info] mysql-mha01(192.168.8.6:3306) Version=5.5.43-log (oldest major version between slaves) log-bin:enabled
  28. Thu Jul 23 14:59:22 2015 - [info] Replicating from 192.168.8.7(192.168.8.7:3306)
  29. Thu Jul 23 14:59:22 2015 - [info] mysql-mha03(192.168.8.8:3306) Version=5.5.43-log (oldest major version between slaves) log-bin:enabled
  30. Thu Jul 23 14:59:22 2015 - [info] Replicating from 192.168.8.7(192.168.8.7:3306)
  31. Thu Jul 23 14:59:22 2015 - [info] Checking slave configurations..
  32. Thu Jul 23 14:59:22 2015 - [info] read_only=1 is not set on slave mysql-mha01(192.168.8.6:3306).
  33. Thu Jul 23 14:59:22 2015 - [info] read_only=1 is not set on slave mysql-mha03(192.168.8.8:3306).
  34. Thu Jul 23 14:59:22 2015 - [info] Checking replication filtering settings..
  35. Thu Jul 23 14:59:22 2015 - [info] Replication filtering check ok.
  36. Thu Jul 23 14:59:22 2015 - [info] Master is down!
  37. Thu Jul 23 14:59:22 2015 - [info] Terminating monitoring script.
  38. Thu Jul 23 14:59:22 2015 - [info] Got exit code 20 (Master dead).
  39. Thu Jul 23 14:59:22 2015 - [info] MHA::MasterFailover version 0.56.
  40. Thu Jul 23 14:59:22 2015 - [info] Starting master failover.
  41. Thu Jul 23 14:59:22 2015 - [info]
  42. Thu Jul 23 14:59:22 2015 - [info] * Phase 1: Configuration Check Phase..
  43. Thu Jul 23 14:59:22 2015 - [info]
  44. Thu Jul 23 14:59:23 2015 - [info] GTID failover mode = 0
  45. Thu Jul 23 14:59:23 2015 - [info] Dead Servers:
  46. Thu Jul 23 14:59:23 2015 - [info] mysql-mha02(192.168.8.7:3306)
  47. Thu Jul 23 14:59:23 2015 - [info] Checking master reachability via MySQL(double check)...
  48. Thu Jul 23 14:59:23 2015 - [info] ok.
  49. Thu Jul 23 14:59:23 2015 - [info] Alive Servers:
  50. Thu Jul 23 14:59:23 2015 - [info] mysql-mha01(192.168.8.6:3306)
  51. Thu Jul 23 14:59:23 2015 - [info] mysql-mha03(192.168.8.8:3306)
  52. Thu Jul 23 14:59:23 2015 - [info] Alive Slaves:
  53. Thu Jul 23 14:59:23 2015 - [info] mysql-mha01(192.168.8.6:3306) Version=5.5.43-log (oldest major version between slaves) log-bin:enabled
  54. Thu Jul 23 14:59:23 2015 - [info] Replicating from 192.168.8.7(192.168.8.7:3306)
  55. Thu Jul 23 14:59:23 2015 - [info] mysql-mha03(192.168.8.8:3306) Version=5.5.43-log (oldest major version between slaves) log-bin:enabled
  56. Thu Jul 23 14:59:23 2015 - [info] Replicating from 192.168.8.7(192.168.8.7:3306)
  57. Thu Jul 23 14:59:23 2015 - [info] Starting Non-GTID based failover.
  58. Thu Jul 23 14:59:23 2015 - [info]
  59. Thu Jul 23 14:59:23 2015 - [info] ** Phase 1: Configuration Check Phase completed.
  60. Thu Jul 23 14:59:23 2015 - [info]
  61. Thu Jul 23 14:59:23 2015 - [info] * Phase 2: Dead Master Shutdown Phase..
  62. Thu Jul 23 14:59:23 2015 - [info]
  63. Thu Jul 23 14:59:23 2015 - [info] Forcing shutdown so that applications never connect to the current master..
  64. Thu Jul 23 14:59:23 2015 - [warning] master_ip_failover_script is not set. Skipping invalidating dead master IP address.
  65. Thu Jul 23 14:59:23 2015 - [warning] shutdown_script is not set. Skipping explicit shutting down of the dead master.
  66. Thu Jul 23 14:59:23 2015 - [info] * Phase 2: Dead Master Shutdown Phase completed.
  67. Thu Jul 23 14:59:23 2015 - [info]
  68. Thu Jul 23 14:59:23 2015 - [info] * Phase 3: Master Recovery Phase..
  69. Thu Jul 23 14:59:23 2015 - [info]
  70. Thu Jul 23 14:59:23 2015 - [info] * Phase 3.1: Getting Latest Slaves Phase..
  71. Thu Jul 23 14:59:23 2015 - [info]
  72. Thu Jul 23 14:59:23 2015 - [info] The latest binary log file/position on all slaves is mysql-bin.000014:107
  73. Thu Jul 23 14:59:23 2015 - [info] Latest slaves (Slaves that received relay log files to the latest):
  74. Thu Jul 23 14:59:23 2015 - [info] mysql-mha01(192.168.8.6:3306) Version=5.5.43-log (oldest major version between slaves) log-bin:enabled
  75. Thu Jul 23 14:59:23 2015 - [info] Replicating from 192.168.8.7(192.168.8.7:3306)
  76. Thu Jul 23 14:59:23 2015 - [info] mysql-mha03(192.168.8.8:3306) Version=5.5.43-log (oldest major version between slaves) log-bin:enabled
  77. Thu Jul 23 14:59:23 2015 - [info] Replicating from 192.168.8.7(192.168.8.7:3306)
  78. Thu Jul 23 14:59:23 2015 - [info] The oldest binary log file/position on all slaves is mysql-bin.000014:107
  79. Thu Jul 23 14:59:23 2015 - [info] Oldest slaves:
  80. Thu Jul 23 14:59:23 2015 - [info] mysql-mha01(192.168.8.6:3306) Version=5.5.43-log (oldest major version between slaves) log-bin:enabled
  81. Thu Jul 23 14:59:23 2015 - [info] Replicating from 192.168.8.7(192.168.8.7:3306)
  82. Thu Jul 23 14:59:23 2015 - [info] mysql-mha03(192.168.8.8:3306) Version=5.5.43-log (oldest major version between slaves) log-bin:enabled
  83. Thu Jul 23 14:59:23 2015 - [info] Replicating from 192.168.8.7(192.168.8.7:3306)
  84. Thu Jul 23 14:59:23 2015 - [info]
  85. Thu Jul 23 14:59:23 2015 - [info] * Phase 3.2: Saving Dead Master's Binlog Phase..
  86. Thu Jul 23 14:59:23 2015 - [info]
  87. Thu Jul 23 14:59:23 2015 - [info] Fetching dead master's binary logs..
  88. Thu Jul 23 14:59:23 2015 - [info] Executing command on the dead master mysql-mha02(192.168.8.7:3306): save_binary_logs --command=save --start_file=mysql-bin.000014 --start_pos=107 --binlog_dir=/var/lib/mysql/logs --output_file=/var/log/masterha/node/saved_master_binlog_from_mysql-mha02_3306_20150723145922.binlog --handle_raw_binlog=1 --disable_log_bin=0 --manager_version=0.56
  89. Creating /var/log/masterha/node if not exists.. ok.
  90. Concat binary/relay logs from mysql-bin.000014 pos 107 to mysql-bin.000014 EOF into /var/log/masterha/node/saved_master_binlog_from_mysql-mha02_3306_20150723145922.binlog ..
  91. Dumping binlog format description event, from position 0 to 107.. ok.
  92. Dumping effective binlog data from /var/lib/mysql/logs/mysql-bin.000014 position 107 to tail(126).. ok.
  93. Concat succeeded.
  94. Thu Jul 23 14:59:23 2015 - [info] scp from root@192.168.8.7:/var/log/masterha/node/saved_master_binlog_from_mysql-mha02_3306_20150723145922.binlog to local:/var/log/masterha/manager/saved_master_binlog_from_mysql-mha02_3306_20150723145922.binlog succeeded.
  95. Thu Jul 23 14:59:23 2015 - [info] HealthCheck: SSH to mysql-mha01 is reachable.
  96. Thu Jul 23 14:59:24 2015 - [info] HealthCheck: SSH to mysql-mha03 is reachable.
  97. Thu Jul 23 14:59:24 2015 - [info]
  98. Thu Jul 23 14:59:24 2015 - [info] * Phase 3.3: Determining New Master Phase..
  99. Thu Jul 23 14:59:24 2015 - [info]
  100. Thu Jul 23 14:59:24 2015 - [info] Finding the latest slave that has all relay logs for recovering other slaves..
  101. Thu Jul 23 14:59:24 2015 - [info] All slaves received relay logs to the same position. No need to resync each other.
  102. Thu Jul 23 14:59:24 2015 - [info] Searching new master from slaves..
  103. Thu Jul 23 14:59:24 2015 - [info] Candidate masters from the configuration file:
  104. Thu Jul 23 14:59:24 2015 - [info] Non-candidate masters:
  105. Thu Jul 23 14:59:24 2015 - [info] New master is mysql-mha01(192.168.8.6:3306)
  106. Thu Jul 23 14:59:24 2015 - [info] Starting master failover..
  107. Thu Jul 23 14:59:24 2015 - [info]
  108. From:
  109. mysql-mha02(192.168.8.7:3306) (current master)
  110. +--mysql-mha01(192.168.8.6:3306)
  111. +--mysql-mha03(192.168.8.8:3306)
  112.  
  113. To:
  114. mysql-mha01(192.168.8.6:3306) (new master)
  115. +--mysql-mha03(192.168.8.8:3306)
  116. Thu Jul 23 14:59:24 2015 - [info]
  117. Thu Jul 23 14:59:24 2015 - [info] * Phase 3.3: New Master Diff Log Generation Phase..
  118. Thu Jul 23 14:59:24 2015 - [info]
  119. Thu Jul 23 14:59:24 2015 - [info] This server has all relay logs. No need to generate diff files from the latest slave.
  120. Thu Jul 23 14:59:24 2015 - [info] Sending binlog..
  121. Thu Jul 23 14:59:24 2015 - [info] scp from local:/var/log/masterha/manager/saved_master_binlog_from_mysql-mha02_3306_20150723145922.binlog to root@mysql-mha01:/var/log/masterha/node/saved_master_binlog_from_mysql-mha02_3306_20150723145922.binlog succeeded.
  122. Thu Jul 23 14:59:24 2015 - [info]
  123. Thu Jul 23 14:59:24 2015 - [info] * Phase 3.4: Master Log Apply Phase..
  124. Thu Jul 23 14:59:24 2015 - [info]
  125. Thu Jul 23 14:59:24 2015 - [info] *NOTICE: If any error happens from this phase, manual recovery is needed.
  126. Thu Jul 23 14:59:24 2015 - [info] Starting recovery on mysql-mha01(192.168.8.6:3306)..
  127. Thu Jul 23 14:59:24 2015 - [info] Generating diffs succeeded.
  128. Thu Jul 23 14:59:24 2015 - [info] Waiting until all relay logs are applied.
  129. Thu Jul 23 14:59:24 2015 - [info] done.
  130. Thu Jul 23 14:59:24 2015 - [info] Getting slave status..
  131. Thu Jul 23 14:59:24 2015 - [info] This slave(mysql-mha01)'s Exec_Master_Log_Pos equals to Read_Master_Log_Pos(mysql-bin.000014:107). No need to recover from Exec_Master_Log_Pos.
  132. Thu Jul 23 14:59:24 2015 - [info] Connecting to the target slave host mysql-mha01, running recover script..
  133. Thu Jul 23 14:59:24 2015 - [info] Executing command: apply_diff_relay_logs --command=apply --slave_user='root' --slave_host=mysql-mha01 --slave_ip=192.168.8.6 --slave_port=3306 --apply_files=/var/log/masterha/node/saved_master_binlog_from_mysql-mha02_3306_20150723145922.binlog --workdir=/var/log/masterha/node --target_version=5.5.43-log --timestamp=20150723145922 --handle_raw_binlog=1 --disable_log_bin=0 --manager_version=0.56 --slave_pass=xxx
  134. Thu Jul 23 14:59:24 2015 - [info]
  135. Applying differential binary/relay log files /var/log/masterha/node/saved_master_binlog_from_mysql-mha02_3306_20150723145922.binlog on mysql-mha01:3306. This may take long time...
  136. Applying log files succeeded.
  137. Thu Jul 23 14:59:24 2015 - [info] All relay logs were successfully applied.
  138. Thu Jul 23 14:59:24 2015 - [info] Getting new master's binlog name and position..
  139. Thu Jul 23 14:59:24 2015 - [info] mysql-bin.000014:107
  140. Thu Jul 23 14:59:24 2015 - [info] All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='mysql-mha01 or 192.168.8.6', MASTER_PORT=3306, MASTER_LOG_FILE='mysql-bin.000014', MASTER_LOG_POS=107, MASTER_USER='repl', MASTER_PASSWORD='xxx';
  141. Thu Jul 23 14:59:24 2015 - [warning] master_ip_failover_script is not set. Skipping taking over new master IP address.
  142. Thu Jul 23 14:59:24 2015 - [info] ** Finished master recovery successfully.
  143. Thu Jul 23 14:59:24 2015 - [info] * Phase 3: Master Recovery Phase completed.
  144. Thu Jul 23 14:59:24 2015 - [info]
  145. Thu Jul 23 14:59:24 2015 - [info] * Phase 4: Slaves Recovery Phase..
  146. Thu Jul 23 14:59:24 2015 - [info]
  147. Thu Jul 23 14:59:24 2015 - [info] * Phase 4.1: Starting Parallel Slave Diff Log Generation Phase..
  148. Thu Jul 23 14:59:24 2015 - [info]
  149. Thu Jul 23 14:59:24 2015 - [info] -- Slave diff file generation on host mysql-mha03(192.168.8.8:3306) started, pid: 6359. Check tmp log /var/log/masterha/manager/mysql-mha03_3306_20150723145922.log if it takes time..
  150. Thu Jul 23 14:59:24 2015 - [info]
  151. Thu Jul 23 14:59:24 2015 - [info] Log messages from mysql-mha03 ...
  152. Thu Jul 23 14:59:24 2015 - [info]
  153. Thu Jul 23 14:59:24 2015 - [info] This server has all relay logs. No need to generate diff files from the latest slave.
  154. Thu Jul 23 14:59:24 2015 - [info] End of log messages from mysql-mha03.
  155. Thu Jul 23 14:59:24 2015 - [info] -- mysql-mha03(192.168.8.8:3306) has the latest relay log events.
  156. Thu Jul 23 14:59:24 2015 - [info] Generating relay diff files from the latest slave succeeded.
  157. Thu Jul 23 14:59:24 2015 - [info]
  158. Thu Jul 23 14:59:24 2015 - [info] * Phase 4.2: Starting Parallel Slave Log Apply Phase..
  159. Thu Jul 23 14:59:24 2015 - [info]
  160. Thu Jul 23 14:59:24 2015 - [info] -- Slave recovery on host mysql-mha03(192.168.8.8:3306) started, pid: 6361. Check tmp log /var/log/masterha/manager/mysql-mha03_3306_20150723145922.log if it takes time..
  161. Thu Jul 23 14:59:25 2015 - [info]
  162. Thu Jul 23 14:59:25 2015 - [info] Log messages from mysql-mha03 ...
  163. Thu Jul 23 14:59:25 2015 - [info]
  164. Thu Jul 23 14:59:24 2015 - [info] Sending binlog..
  165. Thu Jul 23 14:59:24 2015 - [info] scp from local:/var/log/masterha/manager/saved_master_binlog_from_mysql-mha02_3306_20150723145922.binlog to root@mysql-mha03:/var/log/masterha/node/saved_master_binlog_from_mysql-mha02_3306_20150723145922.binlog succeeded.
  166. Thu Jul 23 14:59:24 2015 - [info] Starting recovery on mysql-mha03(192.168.8.8:3306)..
  167. Thu Jul 23 14:59:24 2015 - [info] Generating diffs succeeded.
  168. Thu Jul 23 14:59:24 2015 - [info] Waiting until all relay logs are applied.
  169. Thu Jul 23 14:59:24 2015 - [info] done.
  170. Thu Jul 23 14:59:24 2015 - [info] Getting slave status..
  171. Thu Jul 23 14:59:24 2015 - [info] This slave(mysql-mha03)'s Exec_Master_Log_Pos equals to Read_Master_Log_Pos(mysql-bin.000014:107). No need to recover from Exec_Master_Log_Pos.
  172. Thu Jul 23 14:59:24 2015 - [info] Connecting to the target slave host mysql-mha03, running recover script..
  173. Thu Jul 23 14:59:24 2015 - [info] Executing command: apply_diff_relay_logs --command=apply --slave_user='root' --slave_host=mysql-mha03 --slave_ip=192.168.8.8 --slave_port=3306 --apply_files=/var/log/masterha/node/saved_master_binlog_from_mysql-mha02_3306_20150723145922.binlog --workdir=/var/log/masterha/node --target_version=5.5.43-log --timestamp=20150723145922 --handle_raw_binlog=1 --disable_log_bin=0 --manager_version=0.56 --slave_pass=xxx
  174. Thu Jul 23 14:59:24 2015 - [info]
  175. Applying differential binary/relay log files /var/log/masterha/node/saved_master_binlog_from_mysql-mha02_3306_20150723145922.binlog on mysql-mha03:3306. This may take long time...
  176. Applying log files succeeded.
  177. Thu Jul 23 14:59:24 2015 - [info] All relay logs were successfully applied.
  178. Thu Jul 23 14:59:24 2015 - [info] Resetting slave mysql-mha03(192.168.8.8:3306) and starting replication from the new master mysql-mha01(192.168.8.6:3306)..
  179. Thu Jul 23 14:59:24 2015 - [info] Executed CHANGE MASTER.
  180. Thu Jul 23 14:59:25 2015 - [info] Slave started.
  181. Thu Jul 23 14:59:25 2015 - [info] End of log messages from mysql-mha03.
  182. Thu Jul 23 14:59:25 2015 - [info] -- Slave recovery on host mysql-mha03(192.168.8.8:3306) succeeded.
  183. Thu Jul 23 14:59:25 2015 - [info] All new slave servers recovered successfully.
  184. Thu Jul 23 14:59:25 2015 - [info]
  185. Thu Jul 23 14:59:25 2015 - [info] * Phase 5: New master cleanup phase..
  186. Thu Jul 23 14:59:25 2015 - [info]
  187. Thu Jul 23 14:59:25 2015 - [info] Resetting slave info on the new master..
  188. Thu Jul 23 14:59:25 2015 - [info] mysql-mha01: Resetting slave info succeeded.
  189. Thu Jul 23 14:59:25 2015 - [info] Master failover to mysql-mha01(192.168.8.6:3306) completed successfully.
  190. Thu Jul 23 14:59:25 2015 - [info]
  191.  
  192. ----- Failover Report -----
  193.  
  194. MHAmanager: MySQL Master failover mysql-mha02(192.168.8.7:3306) to mysql-mha01(192.168.8.6:3306) succeeded
  195.  
  196. Master mysql-mha02(192.168.8.7:3306) is down!
  197.  
  198. Check MHA Manager logs at mysql-mha03:/var/log/masterha/manager.log for details.
  199.  
  200. Started automated(non-interactive) failover.
  201. The latest slave mysql-mha01(192.168.8.6:3306) has all relay logs for recovery.
  202. Selected mysql-mha01(192.168.8.6:3306) as a new master.
  203. mysql-mha01(192.168.8.6:3306): OK: Applying all logs succeeded.
  204. mysql-mha03(192.168.8.8:3306): This host has the latest relay log events.
  205. Generating relay diff files from the latest slave succeeded.
  206. mysql-mha03(192.168.8.8:3306): OK: Applying all logs succeeded. Slave started, replicating from mysql-mha01(192.168.8.6:3306)
  207. mysql-mha01(192.168.8.6:3306): Resetting slave info succeeded.
  208. Master failover to mysql-mha01(192.168.8.6:3306) completed successfully.

发现MHA已经成功将主节点配置到mysql-mha01上。切换后manager节点自己主动关闭。

  1. [root@mysql-mha03 ~]# ps -ef|grep -i master
  2. root 6414 3295 0 15:00 pts/1 00:00:00 grep -i master

登录到mysql-mha03节点查看

  1. mysql> show slave status\G
  2. *************************** 1. row ***************************
  3. Slave_IO_State: Waiting for master to send event
  4. Master_Host: 192.168.8.6
  5. Master_User: repl
  6. Master_Port: 3306
  7. Connect_Retry: 20
  8. Master_Log_File: mysql-bin.000014
  9. Read_Master_Log_Pos: 107
  10. Relay_Log_File: mysql-mha03-relay-bin.000002
  11. Relay_Log_Pos: 253
  12. Relay_Master_Log_File: mysql-bin.000014
  13. Slave_IO_Running: Yes
  14. Slave_SQL_Running: Yes
  15. Replicate_Do_DB:
  16. Replicate_Ignore_DB:
  17. Replicate_Do_Table:
  18. Replicate_Ignore_Table:
  19. Replicate_Wild_Do_Table:
  20. Replicate_Wild_Ignore_Table:
  21. Last_Errno: 0
  22. Last_Error:
  23. Skip_Counter: 0
  24. Exec_Master_Log_Pos: 107
  25. Relay_Log_Space: 415
  26. Until_Condition: None
  27. Until_Log_File:
  28. Until_Log_Pos: 0
  29. Master_SSL_Allowed: No
  30. Master_SSL_CA_File:
  31. Master_SSL_CA_Path:
  32. Master_SSL_Cert:
  33. Master_SSL_Cipher:
  34. Master_SSL_Key:
  35. Seconds_Behind_Master: 0
  36. Master_SSL_Verify_Server_Cert: No
  37. Last_IO_Errno: 0
  38. Last_IO_Error:
  39. Last_SQL_Errno: 0
  40. Last_SQL_Error:
  41. Replicate_Ignore_Server_Ids:
  42. Master_Server_Id: 1
  43. 1 row in set (0.00 sec)

host已经改变成功。

MHA配置成功。


5.2 主动切换

mha能够实现master的主动切换,能够让我们方便的维护集群环境。如我们能够将master切换到别的节点,维护原master节点。
须要将启动的manager节点关闭掉。否则会报错。
  1. [root@mysql-mha03 ~]# masterha_stop --conf=/etc/MHA/MHAmanager.conf
  2. Stopped MHAmanager successfully.
  3. [1]+ Exit 1 nohup masterha_manager --conf=/etc/MHA/MHAmanager.conf

我们主动切换master节点。原master节点成为slave节点
  1. [root@mysql-mha03 ~]# masterha_master_switch --master_state=alive --conf=/etc/MHA/MHAmanager.conf

查看输出

  1. Thu Jul 23 15:29:38 2015 - [info] MHA::MasterRotate version 0.56.
  2. Thu Jul 23 15:29:38 2015 - [info] Starting online master switch..
  3. Thu Jul 23 15:29:38 2015 - [info]
  4. Thu Jul 23 15:29:38 2015 - [info] * Phase 1: Configuration Check Phase..
  5. Thu Jul 23 15:29:38 2015 - [info]
  6. Thu Jul 23 15:29:38 2015 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
  7. Thu Jul 23 15:29:38 2015 - [info] Reading application default configuration from /etc/MHA/MHAmanager.conf..
  8. Thu Jul 23 15:29:38 2015 - [info] Reading server configuration from /etc/MHA/MHAmanager.conf..
  9. Thu Jul 23 15:29:39 2015 - [info] GTID failover mode = 0
  10. Thu Jul 23 15:29:39 2015 - [info] Current Alive Master: mysql-mha01(192.168.8.6:3306)
  11. Thu Jul 23 15:29:39 2015 - [info] Alive Slaves:
  12. Thu Jul 23 15:29:39 2015 - [info] mysql-mha02(192.168.8.7:3306) Version=5.5.43-log (oldest major version between slaves) log-bin:enabled
  13. Thu Jul 23 15:29:39 2015 - [info] Replicating from 192.168.8.6(192.168.8.6:3306)
  14. Thu Jul 23 15:29:39 2015 - [info] mysql-mha03(192.168.8.8:3306) Version=5.5.43-log (oldest major version between slaves) log-bin:enabled
  15. Thu Jul 23 15:29:39 2015 - [info] Replicating from 192.168.8.6(192.168.8.6:3306)
  16.  
  17. It is better to execute FLUSH NO_WRITE_TO_BINLOG TABLES on the master before switching. Is it ok to execute on mysql-mha01(192.168.8.6:3306)? (YES/no): yes
  18. Thu Jul 23 15:29:41 2015 - [info] Executing FLUSH NO_WRITE_TO_BINLOG TABLES. This may take long time..
  19. Thu Jul 23 15:29:41 2015 - [info] ok.
  20. Thu Jul 23 15:29:41 2015 - [info] Checking MHA is not monitoring or doing failover..
  21. Thu Jul 23 15:29:41 2015 - [info] Checking replication health on mysql-mha02..
  22. Thu Jul 23 15:29:41 2015 - [info] ok.
  23. Thu Jul 23 15:29:41 2015 - [info] Checking replication health on mysql-mha03..
  24. Thu Jul 23 15:29:41 2015 - [info] ok.
  25. Thu Jul 23 15:29:41 2015 - [info] Searching new master from slaves..
  26. Thu Jul 23 15:29:41 2015 - [info] Candidate masters from the configuration file:
  27. Thu Jul 23 15:29:41 2015 - [info] Non-candidate masters:
  28. Thu Jul 23 15:29:41 2015 - [info]
  29. From:
  30. mysql-mha01(192.168.8.6:3306) (current master)
  31. +--mysql-mha02(192.168.8.7:3306)
  32. +--mysql-mha03(192.168.8.8:3306)
  33.  
  34. To:
  35. mysql-mha02(192.168.8.7:3306) (new master)
  36. +--mysql-mha03(192.168.8.8:3306)
  37.  
  38. Starting master switch from mysql-mha01(192.168.8.6:3306) to mysql-mha02(192.168.8.7:3306)? (yes/NO): yes
  39. Thu Jul 23 15:29:48 2015 - [info] Checking whether mysql-mha02(192.168.8.7:3306) is ok for the new master..
  40. Thu Jul 23 15:29:48 2015 - [info] ok.
  41. Thu Jul 23 15:29:48 2015 - [info] ** Phase 1: Configuration Check Phase completed.
  42. Thu Jul 23 15:29:48 2015 - [info]
  43. Thu Jul 23 15:29:48 2015 - [info] * Phase 2: Rejecting updates Phase..
  44. Thu Jul 23 15:29:48 2015 - [info]
  45. master_ip_online_change_script is not defined. If you do not disable writes on the current master manually, applications keep writing on the current master. Is it ok to proceed? (yes/NO): yes
  46. Thu Jul 23 15:29:59 2015 - [info] Locking all tables on the orig master to reject updates from everybody (including root):
  47. Thu Jul 23 15:29:59 2015 - [info] Executing FLUSH TABLES WITH READ LOCK..
  48. Thu Jul 23 15:29:59 2015 - [info] ok.
  49. Thu Jul 23 15:29:59 2015 - [info] Orig master binlog:pos is mysql-bin.000014:107.
  50. Thu Jul 23 15:29:59 2015 - [info] Waiting to execute all relay logs on mysql-mha02(192.168.8.7:3306)..
  51. Thu Jul 23 15:29:59 2015 - [info] master_pos_wait(mysql-bin.000014:107) completed on mysql-mha02(192.168.8.7:3306). Executed 0 events.
  52. Thu Jul 23 15:29:59 2015 - [info] done.
  53. Thu Jul 23 15:29:59 2015 - [info] Getting new master's binlog name and position..
  54. Thu Jul 23 15:29:59 2015 - [info] mysql-bin.000015:107
  55. Thu Jul 23 15:29:59 2015 - [info] All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='mysql-mha02 or 192.168.8.7', MASTER_PORT=3306, MASTER_LOG_FILE='mysql-bin.000015', MASTER_LOG_POS=107, MASTER_USER='repl', MASTER_PASSWORD='xxx';
  56. Thu Jul 23 15:29:59 2015 - [info]
  57. Thu Jul 23 15:29:59 2015 - [info] * Switching slaves in parallel..
  58. Thu Jul 23 15:29:59 2015 - [info]
  59. Thu Jul 23 15:29:59 2015 - [info] -- Slave switch on host mysql-mha03(192.168.8.8:3306) started, pid: 6819
  60. Thu Jul 23 15:29:59 2015 - [info]
  61. Thu Jul 23 15:29:59 2015 - [info] Log messages from mysql-mha03 ...
  62. Thu Jul 23 15:29:59 2015 - [info]
  63. Thu Jul 23 15:29:59 2015 - [info] Waiting to execute all relay logs on mysql-mha03(192.168.8.8:3306)..
  64. Thu Jul 23 15:29:59 2015 - [info] master_pos_wait(mysql-bin.000014:107) completed on mysql-mha03(192.168.8.8:3306). Executed 0 events.
  65. Thu Jul 23 15:29:59 2015 - [info] done.
  66. Thu Jul 23 15:29:59 2015 - [info] Resetting slave mysql-mha03(192.168.8.8:3306) and starting replication from the new master mysql-mha02(192.168.8.7:3306)..
  67. Thu Jul 23 15:29:59 2015 - [info] Executed CHANGE MASTER.
  68. Thu Jul 23 15:29:59 2015 - [info] Slave started.
  69. Thu Jul 23 15:29:59 2015 - [info] End of log messages from mysql-mha03 ...
  70. Thu Jul 23 15:29:59 2015 - [info]
  71. Thu Jul 23 15:29:59 2015 - [info] -- Slave switch on host mysql-mha03(192.168.8.8:3306) succeeded.
  72. Thu Jul 23 15:29:59 2015 - [info] Unlocking all tables on the orig master:
  73. Thu Jul 23 15:29:59 2015 - [info] Executing UNLOCK TABLES..
  74. Thu Jul 23 15:29:59 2015 - [info] ok.
  75. Thu Jul 23 15:29:59 2015 - [info] All new slave servers switched successfully.
  76. Thu Jul 23 15:29:59 2015 - [info]
  77. Thu Jul 23 15:29:59 2015 - [info] * Phase 5: New master cleanup phase..
  78. Thu Jul 23 15:29:59 2015 - [info]
  79. Thu Jul 23 15:29:59 2015 - [info] mysql-mha02: Resetting slave info succeeded.
  80. Thu Jul 23 15:29:59 2015 - [info] Switching master to mysql-mha02(192.168.8.7:3306) completed successfully.

查看mysql-mysql03节点。已经成功切换到mysql-mha02为master

  1. mysql> show slave status\G
  2. *************************** 1. row ***************************
  3. Slave_IO_State: Waiting for master to send event
  4. Master_Host: 192.168.8.7
  5. Master_User: repl
  6. Master_Port: 3306
  7. Connect_Retry: 20
  8. Master_Log_File: mysql-bin.000015
  9. Read_Master_Log_Pos: 107
  10. Relay_Log_File: mysql-mha03-relay-bin.000002
  11. Relay_Log_Pos: 253
  12. Relay_Master_Log_File: mysql-bin.000015
  13. Slave_IO_Running: Yes
  14. Slave_SQL_Running: Yes
  15. Replicate_Do_DB:
  16. Replicate_Ignore_DB:
  17. Replicate_Do_Table:
  18. Replicate_Ignore_Table:

MHA安装配置的更多相关文章

  1. MySQL学习笔记-MHA安装配置

    一.配置主从同步   1. 本例中主从ip及端口 Master:10.1.5.8:3306 Slave1:10.1.5.9:3306 (候选master) Slave2:10.1.5.195:3306 ...

  2. MySQL MHA安装配置

    1.环境规划 192.168.12.131 node01 192.168.12.132 node02 192.168.12.133 node03 2.环境准备 一主两从GTID,略. 3.配置关键程序 ...

  3. MYSQL + MHA +keepalive + VIP安装配置(二)--MHA的配置

    一.总概 1.MHA介绍 MHA(Master High Availability)是自动的master故障转移和Slave提升的软件包.它是基于标准的MySQL复制(异步/半同步).      MH ...

  4. mha安装使用手册

    mha安装使用手册 注:目前mha最新的版本代码已经不放到google code网站了,而是放在github上,最新的版本为0.57,github链接如下: mha manager:https://g ...

  5. Hive安装配置指北(含Hive Metastore详解)

    个人主页: http://www.linbingdong.com 本文介绍Hive安装配置的整个过程,包括MySQL.Hive及Metastore的安装配置,并分析了Metastore三种配置方式的区 ...

  6. Hive on Spark安装配置详解(都是坑啊)

    个人主页:http://www.linbingdong.com 简书地址:http://www.jianshu.com/p/a7f75b868568 简介 本文主要记录如何安装配置Hive on Sp ...

  7. ADFS3.0与SharePoint2013安装配置(原创)

    现在越来越多的企业使用ADFS作为单点登录,我希望今天的内容能帮助大家了解如何配置ADFS和SharePoint 2013.安装配置SharePoint2013这块就不做具体描述了,今天主要讲一下怎么 ...

  8. Hadoop的学习--安装配置与使用

    安装配置 系统:Ubuntu14.04 java:1.7.0_75 相关资料 官网 下载地址 官网文档 安装 我们需要关闭掉防火墙,命令如下: sudo ufw disable 下载2.6.5的版本, ...

  9. redis的安装配置

    主要讲下redis的安装配置,以及以服务的方式启动redis 1.下载最新版本的redis-3.0.7  到http://redis.io/download中下载最新版的redis-3.0.7 下载后 ...

随机推荐

  1. JSK 11: 移除数组中的重复元素

    题目描述 给定一个升序排列的数组,去掉重复的数,并输出新的数组的长度. 例如:数组 $A = \{1, 1, 2\}$,你的程序应该输出 $2$ 即新数组的长度,新数组为 $\{1, 2\}$. 要求 ...

  2. [BZOJ5110]Yazid的新生舞会

    题目大意: 给你一个长度为$n(n\leq 5\times 10^5)$的序列$A_{1\sim n}$.求满足区间众数在区间内出现次数严格大于$\lfloor\frac{r-l+1}{2}\rflo ...

  3. 每天一个linux命令8之grep高级篇

    1语法       grep -[acinv] '搜索内容串' filename -a 以文本文件方式搜索-c 计算找到的符合行的次数-i 忽略大小写-n 顺便输出行号-v 反向选择,即找 没有搜索字 ...

  4. 在ArcGIS Desktop中进行三参数或七参数精确投影转换

    转自 在ArcGIS Desktop中进行三参数或七参数精确投影转换     ArcGIS中定义的投影转换方法,在对数据的空间信息要求较高的工程中往往不能适用,有比较明显的偏差.在项目的前期数据准备工 ...

  5. DATASNAP数据序列之FIREDAC的TFDJSONDataSets

    DATASNAP数据序列之FIREDAC的TFDJSONDataSets DELPHI XE5开始增加了新的数据引擎——FIREDAC,它是跨平台的数据引擎,WINDOWS.LINUX.MAC.APP ...

  6. 【微信】微信小程序 新建页面目录后,怎么自动生成目中的的四个基本文件呢? 新建目录报错如下VM458:2 未找到 app.json 中的定义的 pages "pages/module/module" 对应的 WXML 文件

    如下图,在使用微信开发者工具过程中,新创建了页面目录,想要页面文件夹中自动生成四个基本文件 但是新创建了一个页面文件夹,里面的四个基本文件并没有展示出来 然后在app.json添加这个路径,ctrl+ ...

  7. JAVA常见算法题(十五)

    package com.xiaowu.demo; /** * * 输入三个整数x,y,z,请把这三个数由小到大输出. * * @author WQ * */ public class Demo15 { ...

  8. react with JSX for {if…else…}

    在react中用jsx渲染dom的时候经常会遇到if条件判断,然而在jsx中竟是不允许if条件判断的.以下有几种判断方式,可以根据自己的应用场景,挑选适合的 https://blog.csdn.net ...

  9. flask的session解读及flask_login登录过程研究

    #!/usr/bin/env python # -*- coding: utf-8 -*- from itsdangerous import URLSafeTimedSerializer from f ...

  10. ES6中的迭代器(Iterator)和生成器(Generator)(一)

    用循环语句迭代数据时,必须要初始化一个变量来记录每一次迭代在数据集合中的位置,而在许多编程语言中,已经开始通过程序化的方式用迭代器对象返回迭代过程中集合的每一个元素 迭代器的使用可以极大地简化数据操作 ...