数据库的高可用MHA实验步骤
阅读原文时间:2023年07月08日阅读:3

一、多机互信的步骤

双机互信的步骤

第一步:在master管理服务器上ssh-keygen

在master同一台管理服务器上重新开一个窗口ssh-copy-id 192.168.0.13自己给自己互信

ssh-copy-id 192.168.0.13两台管理服务器登录

第二步:在管理服务器上操作rsync -av .ssh 192.168.0.10:/root/

rsync -av .ssh 192.168.0.11:/root/

rsync -av .ssh 192.168.0.12:/root/将自己的秘钥复制到其他的服务器上

此时所有的服务器可以相互登录

配置了互信,那如果其中服务器的root用户修改了密码,需要重新配置互信吗?不需要

二、MHA实验步骤

1.部署一主两从

第一台服务器

###################################
#MHA
validate_password_policy=0
validate_password_length=4
log-bin=log-bin
server-id=1
skip-name-resolve
##################################

在第二台服务器/etc/my.cnf中添加

#############################
#MHA
validate_password_policy=0
validate_password_length=4
log-bin=log-bin
server-id=2
skip-name-resolve
#############################

并重启服务

第三台同样配置

############################################
#MHA
server-id=3
validate_password_policy=0
validate_password_length=4
log-bin=log-bin
skip-name-resolve
############################################

2.安装MHA

在管理服务器上安装

yum install perl-DBD-Mysql perl-Config-Tiny perl-Log-Dispatch perl-Parallel-G
ForkManager epel-*

yum repolist

yum install epel-* -y

yum localinstall mha4mysql-*.rpm -y

3.在第一主服务器、二从服务器、三从服务器台服务器以及管理服务器上操作:

yum localinstall mha4mysql-node-0.54-0.el6.noarch.rpm

4.在管理服务器上创建一个mha_manager目录

进入目录创建配置文件vim  app1.conf

编写内容

[server default]
manager_workdir=/etc/mha_manager
manager_log=/etc/mha_manager/manager.log
ssh_user=root
ssh_port=22
user=root
password=123456
repl_user=repl
repl_password=123456
[server1]
hostname=192.168.0.10
candidate_master=1
[server2]
hostname=192.168.0.11
candidate_master=1
[server3]
hostname=192.168.0.12

5.[root@localhost mha_manager]# masterha_check_ssh --conf=app.conf

masterha_check_repl --conf=app1.conf检查repl节点、、、报错

在第一台服务器上登录mysql

grant replication slave on *.* to repl@'192.168.0.%'identified by '123456';

grant all on *.* to root@'192.168.0.%'identified by '123456';

flush privileges;

6.在管理服务器上检测

masterha_check_repl --conf=app1.conf

在第一台服务器上/etc/my.cnf修改

###################################
#MHA
validate_password_policy=0
validate_password_length=4
log-bin=/var/lib/mysql/log-bin
server-id=1
skip-name-resolve
##################################并重启

在第一台服务器上重启mysql服务并刷新权限show master  status\G

在第二台服务器上刷新一样的pos节点号

在第三台服务器上刷新一样的pos节点号编写的脚本

mysql -p << EOF
change master to
master_host='192.168.0.10',
master_port=3306,
master_user='repl',
master_password='123456',
master_log_file='log-bin.000005',
master_log_pos=154;
EOF

7.在管理服务器上检测masterha_check_repl --conf=app1.conf

masterha_check_status --conf=app1.conf

masterha_check_manager --conf=app1.conf

在打开一个管理服务器终端

[root@localhost ~]# cd /etc/mha_manager/
[root@localhost mha_manager]# masterha_check_status --conf=app1.conf
app1 (pid:66906) is running(0:PING_OK), master:192.168.0.10配置成功

模拟主数据库宕机关闭mysql服务器service mysql stop

在管理服务器上观看

在第三台从服务器上查看master点换为刚刚设置的服务器了

在此之前MHA搭建完成      7.MHA manager 节点配置

mkdir /etc/mha_manager/建立mha manage工作目录
vim /etc/mha_manager/app1.conf 创建application1 集群


[server default]  # server默认配置
manager_workdir=/etc/mha_manager  # 指定mha 工作目录
manager_log=/etc/mha_manager/manager.log #指定 mha 日志
master_ip_failover_script=/etc/mha_manager/master_ip_failover  #指定mha 的vip漂移脚本
ssh_user=root     #指定ssh user
ssh_port=22    #指定ssh port
user=root    #指定mysql root
password=1234    # root密码
repl_user=repl     #repl user
repl_password=1234 #repl user passwd
[server1] #指定server mysql
hostname=192.168.50.171 #server ip
candidate_master=1  # 设置此server是否抢占master
[server2]
hostname=192.168.50.4
candidate_master=1
[server3]
hostname=192.168.50.130

8.yum localinstall mha4mysql-master-0.55-0.e16.noarch.rpm

9.master_check_ssh --conf=/etc/m

10.master_check_repl --conf=/etc/m

11.登录mysql  grant replication slave on *.* to repl@192.168.0.%' identified by '123456';

12.grant all on *.* to root@'192.168.0.%'identified by'123456';

13.flush privileges;

14.master_check_repl --conf=/etc/m

15.在主服务器的/etc/my.cnf下修改log-bin=log-bin修改为log-bin=/var/lib/mysql/log-bin

16.重启数据库

17.master_check_repl --conf=/etc/m

18.主从出错解决方法:重新搭建主从重新在主服务器查看pos点show master status\G

vim /var/lib/mysql/master,info修改pos点然后再数据库中stop  slave  重启slave

重启mysql   登录数据库show status slave\G  重新做主从vim slave.sh  启动mysql

19.master_check_status  --conf=app1.conf

20.master_manager  --conf=app1.conf

21.在第四台查看:masterha_check_statua  --cong=app1.conf

22.模拟master故障直接停止mysql 在第一台上service mysqld stop

23.在第四台上查看    在第三台上查看登录mysql   show slave status\G

24.还可以查看日志vim manager.log

8.3 MHA 搭建

操作步骤

1.配置主从

1.1 master
/etc/my.cnf
server-id
log-bin
skip-name-resolve
1.2 master 建立repl用户
grant replication slave on *.* to repl@'192.168.50.%' identied by '1234';
show master status\G
1.3 slave
/etc/my.cnf
server-id
log-bin
skip-name-resolve
read_only
relay_log_purge=0
1.4 star slave
change master to ...

2.多机互信

ssh-keygen
ssh-copy-id 192.168.50.108
ssh root@192.168.50.108
rsync -av .ssh 192.168.50.171:/root/
rsync -av .ssh 192.168.50.130:/root/
rsync -av .ssh 192.168.50.4:/root/

3.MHA node 节点安装

所有MySQL服务器安装:
安装依赖
yum install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager epel-* -y
安装软件包
yum localinstall mha4mysql-node-0.54-0.el6.noarch.rpm

4.MHA manager 节点安装

安装依赖
yum install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager epel-* -y
安装软件包
yum localinstall mha4mysql-manager-0.55-0.el6.noarch.rpm mha4mysql-node-0.54-0.el6.noarch.rpm 

5.MHA manager 节点配置

mkdir /etc/mha_manager/建立mha manage工作目录
vim /etc/mha_manager/app1.conf 创建application1 集群


[server default]  # server默认配置
manager_workdir=/etc/mha_manager  # 指定mha 工作目录
manager_log=/etc/mha_manager/manager.log #指定 mha 日志
master_ip_failover_script=/etc/mha_manager/master_ip_failover  #指定mha 的vip漂移脚本
ssh_user=root     #指定ssh user
ssh_port=22    #指定ssh port
user=root    #指定mysql root
password=1234    # root密码
repl_user=repl     #repl user
repl_password=1234 #repl user passwd
[server1] #指定server mysql
hostname=192.168.50.171 #server ip
candidate_master=1  # 设置此server是否抢占master
[server2]
hostname=192.168.50.4
candidate_master=1
[server3]
hostname=192.168.50.130
漂移脚本需要更改的地方:
```
my $vip = '192.168.50.60/24';  # Virtual IP
my $key = "1";
my $ssh_start_vip = "/sbin/ifconfig ens33:$key $vip";
my $ssh_stop_vip = "/sbin/ifconfig ens33:$key down";
```
主要是vip和网卡名字
完整放在百度 云盘
5.1 授权:
grant all on *.* to root@'192.168.50.%' identified by '1234';
grant replication slave on *.* to repl@'192.168.50.%' identified by '1234';
5.2 检测启动
masterha_check_ssh:检测MHA的ssh配置情况
    masterha_check_repl:检测MySQL复制情况
    masterha_manager:启动mha
    masterha_check_status 检测mha运行状态

masterha_check_ssh --conf=/etc/mha_manager/app1.conf
masterha_check_repl --conf=/etc/mha_manager/app1.conf
masterha_manager --conf=/etc/mha_manager/app1.conf

需要手动将 vip 配置在master上
ifconfig ens33:1 192.168.50.171
5.3 故障切换
关闭master MySQL,查看是否可以自动漂移ip和master是否重新指定即可。
5.4 如何恢复MHA
1.满足搭建MHA的条件
2.删除故障转移文件
rm /etc/mha_manager/app1.failover.complete

6.完整故障切换日志分析

Wed Aug 25 22:22:55 2021 - [info] MHA::MasterMonitor version 0.55.
Wed Aug 25 22:22:57 2021 - [info] Dead Servers:
Wed Aug 25 22:22:57 2021 - [info] Alive Servers:
Wed Aug 25 22:22:57 2021 - [info]   192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:22:57 2021 - [info]   192.168.50.4(192.168.50.4:3306)
Wed Aug 25 22:22:57 2021 - [info]   192.168.50.130(192.168.50.130:3306)
Wed Aug 25 22:22:57 2021 - [info] Alive Slaves:
Wed Aug 25 22:22:57 2021 - [info]   192.168.50.4(192.168.50.4:3306)  Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:22:57 2021 - [info]     Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:22:57 2021 - [info]     Primary candidate for the new Master (candidate_master is set)
Wed Aug 25 22:22:57 2021 - [info]   192.168.50.130(192.168.50.130:3306)  Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:22:57 2021 - [info]     Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:22:57 2021 - [info] Current Alive Master: 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:22:57 2021 - [info] Checking slave configurations..
Wed Aug 25 22:22:57 2021 - [info] Checking replication filtering settings..
Wed Aug 25 22:22:57 2021 - [info]  binlog_do_db= , binlog_ignore_db=
Wed Aug 25 22:22:57 2021 - [info]  Replication filtering check ok.
Wed Aug 25 22:22:57 2021 - [info] Starting SSH connection tests..
Wed Aug 25 22:22:59 2021 - [info] All SSH connection tests passed successfully.
Wed Aug 25 22:22:59 2021 - [info] Checking MHA Node version..
Wed Aug 25 22:23:00 2021 - [info]  Version check ok.
Wed Aug 25 22:23:00 2021 - [info] Checking SSH publickey authentication settings on the current master..
Wed Aug 25 22:23:00 2021 - [info] HealthCheck: SSH to 192.168.50.171 is reachable.
Wed Aug 25 22:23:00 2021 - [info] Master MHA Node version is 0.54.
Wed Aug 25 22:23:00 2021 - [info] Checking recovery script configurations on the current master..
Wed Aug 25 22:23:00 2021 - [info]   Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/var/lib/mysql,/var/log/mysql --output_file=/var/tmp/save_binary_logs_test --manager_version=0.55 --start_file=log-bin.000004
Wed Aug 25 22:23:00 2021 - [info]   Connecting to root@192.168.50.171(192.168.50.171)..
  Creating /var/tmp if not exists..    ok.
  Checking output directory is accessible or not..
   ok.
  Binlog found at /var/lib/mysql, up to log-bin.000004
Wed Aug 25 22:23:01 2021 - [info] Master setting check done.
Wed Aug 25 22:23:01 2021 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Wed Aug 25 22:23:01 2021 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.50.4 --slave_ip=192.168.50.4 --slave_port=3306 --workdir=/var/tmp --target_version=5.7.17-log --manager_version=0.55 --relay_log_info=/var/lib/mysql/relay-log.info  --relay_dir=/var/lib/mysql/  --slave_pass=xxx
Wed Aug 25 22:23:01 2021 - [info]   Connecting to root@192.168.50.4(192.168.50.4:22)..
  Checking slave recovery environment settings..
    Opening /var/lib/mysql/relay-log.info ... ok.
    Relay log found at /var/lib/mysql, up to centos7-24-3-relay-bin.000002
    Temporary relay log file is /var/lib/mysql/centos7-24-3-relay-bin.000002
    Testing 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.
Wed Aug 25 22:23:01 2021 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.50.130 --slave_ip=192.168.50.130 --slave_port=3306 --workdir=/var/tmp --target_version=5.7.17-log --manager_version=0.55 --relay_log_info=/var/lib/mysql/relay-log.info  --relay_dir=/var/lib/mysql/  --slave_pass=xxx
Wed Aug 25 22:23:01 2021 - [info]   Connecting to root@192.168.50.130(192.168.50.130:22)..
  Checking slave recovery environment settings..
    Opening /var/lib/mysql/relay-log.info ... ok.
    Relay log found at /var/lib/mysql, up to centos7-2-relay-bin.000002
    Temporary relay log file is /var/lib/mysql/centos7-2-relay-bin.000002
    Testing 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.
Wed Aug 25 22:23:02 2021 - [info] Slaves settings check done.
Wed Aug 25 22:23:02 2021 - [info]
192.168.50.171 (current master)
 +--192.168.50.4
 +--192.168.50.130

Wed Aug 25 22:23:02 2021 - [info] Checking master_ip_failover_script status:
Wed Aug 25 22:23:02 2021 - [info]   /etc/mha_manager/master_ip_failover --command=status --ssh_user=root --orig_master_host=192.168.50.171 --orig_master_ip=192.168.50.171 --orig_master_port=3306
Wed Aug 25 22:23:02 2021 - [info]  OK.
Wed Aug 25 22:23:02 2021 - [warning] shutdown_script is not defined.
Wed Aug 25 22:23:02 2021 - [info] Set master ping interval 3 seconds.
Wed Aug 25 22:23:02 2021 - [warning] secondary_check_script is not defined. It is highly recommended setting it to check master reachability from two or more routes.
Wed Aug 25 22:23:02 2021 - [info] Starting ping health check on 192.168.50.171(192.168.50.171:3306)..
Wed Aug 25 22:23:02 2021 - [info] Ping(SELECT) succeeded, waiting until MySQL doesn't respond..

#MHA启动日志
################################################################################

Wed Aug 25 22:24:08 2021 - [warning] Got error on MySQL select ping: 2006 (MySQL server has gone away)
Wed Aug 25 22:24:08 2021 - [info] Executing SSH check script: save_binary_logs --command=test --start_pos=4 --binlog_dir=/var/lib/mysql,/var/log/mysql --output_file=/var/tmp/save_binary_logs_test --manager_version=0.55 --binlog_prefix=log-bin
Wed Aug 25 22:24:08 2021 - [info] HealthCheck: SSH to 192.168.50.171 is reachable.
Wed Aug 25 22:24:11 2021 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.50.171' (111))
Wed Aug 25 22:24:11 2021 - [warning] Connection failed 1 time(s)..
Wed Aug 25 22:24:14 2021 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.50.171' (111))
Wed Aug 25 22:24:14 2021 - [warning] Connection failed 2 time(s)..
Wed Aug 25 22:24:17 2021 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.50.171' (111))
Wed Aug 25 22:24:17 2021 - [warning] Connection failed 3 time(s)..
Wed Aug 25 22:24:17 2021 - [warning] Master is not reachable from health checker!
Wed Aug 25 22:24:17 2021 - [warning] Master 192.168.50.171(192.168.50.171:3306) is not reachable!
Wed Aug 25 22:24:17 2021 - [warning] SSH is reachable.
Wed Aug 25 22:24:17 2021 - [info] Connecting to a master server failed. Reading configuration file /etc/masterha_default.cnf and app1.conf again, and trying to connect to all servers to check server status..
Wed Aug 25 22:24:17 2021 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Wed Aug 25 22:24:17 2021 - [info] Reading application default configurations from app1.conf..
Wed Aug 25 22:24:17 2021 - [info] Reading server configurations from app1.conf..
Wed Aug 25 22:24:18 2021 - [info] Dead Servers:
Wed Aug 25 22:24:18 2021 - [info]   192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:18 2021 - [info] Alive Servers:
Wed Aug 25 22:24:18 2021 - [info]   192.168.50.4(192.168.50.4:3306)
Wed Aug 25 22:24:18 2021 - [info]   192.168.50.130(192.168.50.130:3306)
Wed Aug 25 22:24:18 2021 - [info] Alive Slaves:
Wed Aug 25 22:24:18 2021 - [info]   192.168.50.4(192.168.50.4:3306)  Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:18 2021 - [info]     Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:18 2021 - [info]     Primary candidate for the new Master (candidate_master is set)
Wed Aug 25 22:24:18 2021 - [info]   192.168.50.130(192.168.50.130:3306)  Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:18 2021 - [info]     Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:18 2021 - [info] Checking slave configurations..
Wed Aug 25 22:24:18 2021 - [info] Checking replication filtering settings..
Wed Aug 25 22:24:18 2021 - [info]  Replication filtering check ok.
Wed Aug 25 22:24:18 2021 - [info] Master is down!
Wed Aug 25 22:24:18 2021 - [info] Terminating monitoring script.
Wed Aug 25 22:24:18 2021 - [info] Got exit code 20 (Master dead).
Wed Aug 25 22:24:18 2021 - [info] MHA::MasterFailover version 0.55.
###########################################################################
#开始故障转移
Wed Aug 25 22:24:18 2021 - [info] Starting master failover.
Wed Aug 25 22:24:18 2021 - [info]
Wed Aug 25 22:24:18 2021 - [info] * Phase 1: Configuration Check Phase..
Wed Aug 25 22:24:18 2021 - [info]
Wed Aug 25 22:24:19 2021 - [info] Dead Servers:
Wed Aug 25 22:24:19 2021 - [info]   192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:19 2021 - [info] Checking master reachability via mysql(double check)..
Wed Aug 25 22:24:19 2021 - [info]  ok.
Wed Aug 25 22:24:19 2021 - [info] Alive Servers:
Wed Aug 25 22:24:19 2021 - [info]   192.168.50.4(192.168.50.4:3306)
Wed Aug 25 22:24:19 2021 - [info]   192.168.50.130(192.168.50.130:3306)
Wed Aug 25 22:24:19 2021 - [info] Alive Slaves:
Wed Aug 25 22:24:19 2021 - [info]   192.168.50.4(192.168.50.4:3306)  Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:19 2021 - [info]     Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:19 2021 - [info]     Primary candidate for the new Master (candidate_master is set)
Wed Aug 25 22:24:19 2021 - [info]   192.168.50.130(192.168.50.130:3306)  Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:19 2021 - [info]     Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:19 2021 - [info] ** Phase 1: Configuration Check Phase completed.
Wed Aug 25 22:24:19 2021 - [info]
Wed Aug 25 22:24:19 2021 - [info] * Phase 2: Dead Master Shutdown Phase..
Wed Aug 25 22:24:19 2021 - [info]
Wed Aug 25 22:24:19 2021 - [info] Forcing shutdown so that applications never connect to the current master..
Wed Aug 25 22:24:19 2021 - [info] Executing master IP deactivatation script:
Wed Aug 25 22:24:19 2021 - [info]   /etc/mha_manager/master_ip_failover --orig_master_host=192.168.50.171 --orig_master_ip=192.168.50.171 --orig_master_port=3306 --command=stopssh --ssh_user=root
Wed Aug 25 22:24:19 2021 - [info]  done.
Wed Aug 25 22:24:19 2021 - [warning] shutdown_script is not set. Skipping explicit shutting down of the dead master.
Wed Aug 25 22:24:19 2021 - [info] * Phase 2: Dead Master Shutdown Phase completed.
Wed Aug 25 22:24:19 2021 - [info]
Wed Aug 25 22:24:19 2021 - [info] * Phase 3: Master Recovery Phase..
Wed Aug 25 22:24:19 2021 - [info]
Wed Aug 25 22:24:19 2021 - [info] * Phase 3.1: Getting Latest Slaves Phase..
Wed Aug 25 22:24:19 2021 - [info]
Wed Aug 25 22:24:19 2021 - [info] The latest binary log file/position on all slaves is log-bin.000004:154
Wed Aug 25 22:24:19 2021 - [info] Latest slaves (Slaves that received relay log files to the latest):
Wed Aug 25 22:24:19 2021 - [info]   192.168.50.4(192.168.50.4:3306)  Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:19 2021 - [info]     Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:19 2021 - [info]     Primary candidate for the new Master (candidate_master is set)
Wed Aug 25 22:24:19 2021 - [info]   192.168.50.130(192.168.50.130:3306)  Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:19 2021 - [info]     Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:19 2021 - [info] The oldest binary log file/position on all slaves is log-bin.000004:154
Wed Aug 25 22:24:19 2021 - [info] Oldest slaves:
Wed Aug 25 22:24:19 2021 - [info]   192.168.50.4(192.168.50.4:3306)  Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:19 2021 - [info]     Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:19 2021 - [info]     Primary candidate for the new Master (candidate_master is set)
Wed Aug 25 22:24:19 2021 - [info]   192.168.50.130(192.168.50.130:3306)  Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:19 2021 - [info]     Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:19 2021 - [info]
Wed Aug 25 22:24:19 2021 - [info] * Phase 3.2: Saving Dead Master's Binlog Phase..
Wed Aug 25 22:24:19 2021 - [info]
Wed Aug 25 22:24:20 2021 - [info] Fetching dead master's binary logs..
Wed Aug 25 22:24:20 2021 - [info] Executing command on the dead master 192.168.50.171(192.168.50.171:3306): save_binary_logs --command=save --start_file=log-bin.000004  --start_pos=154 --binlog_dir=/var/lib/mysql,/var/log/mysql --output_file=/var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog --handle_raw_binlog=1 --disable_log_bin=0 --manager_version=0.55
  Creating /var/tmp if not exists..    ok.
 Concat binary/relay logs from log-bin.000004 pos 154 to log-bin.000004 EOF into /var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog ..
  Dumping binlog format description event, from position 0 to 123.. ok.
  Dumping effective binlog data from /var/lib/mysql/log-bin.000004 position 154 to tail(177).. ok.
 Concat succeeded.
Wed Aug 25 22:24:20 2021 - [info] scp from root@192.168.50.171:/var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog to local:/etc/mha_manager/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog succeeded.
Wed Aug 25 22:24:21 2021 - [info] HealthCheck: SSH to 192.168.50.4 is reachable.
Wed Aug 25 22:24:22 2021 - [info] HealthCheck: SSH to 192.168.50.130 is reachable.
Wed Aug 25 22:24:22 2021 - [info]
Wed Aug 25 22:24:22 2021 - [info] * Phase 3.3: Determining New Master Phase..
Wed Aug 25 22:24:22 2021 - [info]
Wed Aug 25 22:24:22 2021 - [info] Finding the latest slave that has all relay logs for recovering other slaves..
Wed Aug 25 22:24:22 2021 - [info] All slaves received relay logs to the same position. No need to resync each other.
######################################################################
#选举新的master
Wed Aug 25 22:24:22 2021 - [info] Searching new master from slaves..
Wed Aug 25 22:24:22 2021 - [info]  Candidate masters from the configuration file:
Wed Aug 25 22:24:22 2021 - [info]   192.168.50.4(192.168.50.4:3306)  Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:22 2021 - [info]     Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:22 2021 - [info]     Primary candidate for the new Master (candidate_master is set)
Wed Aug 25 22:24:22 2021 - [info]  Non-candidate masters:
Wed Aug 25 22:24:22 2021 - [info]  Searching from candidate_master slaves which have received the latest relay log events..
Wed Aug 25 22:24:22 2021 - [info] New master is 192.168.50.4(192.168.50.4:3306)
Wed Aug 25 22:24:22 2021 - [info] Starting master failover..
Wed Aug 25 22:24:22 2021 - [info]
From:
192.168.50.171 (current master)
 +--192.168.50.4
 +--192.168.50.130

To:
192.168.50.4 (new master)
 +--192.168.50.130
Wed Aug 25 22:24:22 2021 - [info]
Wed Aug 25 22:24:22 2021 - [info] * Phase 3.3: New Master Diff Log Generation Phase..
Wed Aug 25 22:24:22 2021 - [info]
Wed Aug 25 22:24:22 2021 - [info]  This server has all relay logs. No need to generate diff files from the latest slave.
Wed Aug 25 22:24:22 2021 - [info] Sending binlog..
Wed Aug 25 22:24:23 2021 - [info] scp from local:/etc/mha_manager/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog to root@192.168.50.4:/var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog succeeded.
Wed Aug 25 22:24:23 2021 - [info]
Wed Aug 25 22:24:23 2021 - [info] * Phase 3.4: Master Log Apply Phase..
Wed Aug 25 22:24:23 2021 - [info]
Wed Aug 25 22:24:23 2021 - [info] *NOTICE: If any error happens from this phase, manual recovery is needed.
Wed Aug 25 22:24:23 2021 - [info] Starting recovery on 192.168.50.4(192.168.50.4:3306)..
Wed Aug 25 22:24:23 2021 - [info]  Generating diffs succeeded.
Wed Aug 25 22:24:23 2021 - [info] Waiting until all relay logs are applied.
Wed Aug 25 22:24:23 2021 - [info]  done.
Wed Aug 25 22:24:23 2021 - [info] Getting slave status..
Wed Aug 25 22:24:23 2021 - [info] This slave(192.168.50.4)'s Exec_Master_Log_Pos equals to Read_Master_Log_Pos(log-bin.000004:154). No need to recover from Exec_Master_Log_Pos.
Wed Aug 25 22:24:23 2021 - [info] Connecting to the target slave host 192.168.50.4, running recover script..
Wed Aug 25 22:24:23 2021 - [info] Executing command: apply_diff_relay_logs --command=apply --slave_user='root' --slave_host=192.168.50.4 --slave_ip=192.168.50.4  --slave_port=3306 --apply_files=/var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog --workdir=/var/tmp --target_version=5.7.17-log --timestamp=20210825222418 --handle_raw_binlog=1 --disable_log_bin=0 --manager_version=0.55 --slave_pass=xxx
Wed Aug 25 22:24:23 2021 - [info]
MySQL client version is 5.7.17. Using --binary-mode.
Applying differential binary/relay log files /var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog on 192.168.50.4:3306. This may take long time...
Applying log files succeeded.
Wed Aug 25 22:24:23 2021 - [info]  All relay logs were successfully applied.
Wed Aug 25 22:24:23 2021 - [info] Getting new master's binlog name and position..
Wed Aug 25 22:24:23 2021 - [info]  log-bin.000005:154
Wed Aug 25 22:24:23 2021 - [info]  All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='192.168.50.4', MASTER_PORT=3306, MASTER_LOG_FILE='log-bin.000005', MASTER_LOG_POS=154, MASTER_USER='repl', MASTER_PASSWORD='xxx';
Wed Aug 25 22:24:23 2021 - [info] Executing master IP activate script:
Wed Aug 25 22:24:23 2021 - [info]   /etc/mha_manager/master_ip_failover --command=start --ssh_user=root --orig_master_host=192.168.50.171 --orig_master_ip=192.168.50.171 --orig_master_port=3306 --new_master_host=192.168.50.4 --new_master_ip=192.168.50.4 --new_master_port=3306 --new_master_user='root' --new_master_password='1234'
Set read_only=0 on the new master.
Creating app user on the new master..
Wed Aug 25 22:24:24 2021 - [info]  OK.
Wed Aug 25 22:24:24 2021 - [info] ** Finished master recovery successfully.
Wed Aug 25 22:24:24 2021 - [info] * Phase 3: Master Recovery Phase completed.
Wed Aug 25 22:24:24 2021 - [info]
Wed Aug 25 22:24:24 2021 - [info] * Phase 4: Slaves Recovery Phase..
Wed Aug 25 22:24:24 2021 - [info]
Wed Aug 25 22:24:24 2021 - [info] * Phase 4.1: Starting Parallel Slave Diff Log Generation Phase..
Wed Aug 25 22:24:24 2021 - [info]
Wed Aug 25 22:24:24 2021 - [info] -- Slave diff file generation on host 192.168.50.130(192.168.50.130:3306) started, pid: 80982. Check tmp log /etc/mha_manager/192.168.50.130_3306_20210825222418.log if it takes time..
Wed Aug 25 22:24:25 2021 - [info]
Wed Aug 25 22:24:25 2021 - [info] Log messages from 192.168.50.130 ...
Wed Aug 25 22:24:25 2021 - [info]
Wed Aug 25 22:24:24 2021 - [info]  This server has all relay logs. No need to generate diff files from the latest slave.
Wed Aug 25 22:24:25 2021 - [info] End of log messages from 192.168.50.130.
Wed Aug 25 22:24:25 2021 - [info] -- 192.168.50.130(192.168.50.130:3306) has the latest relay log events.
Wed Aug 25 22:24:25 2021 - [info] Generating relay diff files from the latest slave succeeded.
Wed Aug 25 22:24:25 2021 - [info]
Wed Aug 25 22:24:25 2021 - [info] * Phase 4.2: Starting Parallel Slave Log Apply Phase..
Wed Aug 25 22:24:25 2021 - [info]
Wed Aug 25 22:24:25 2021 - [info] -- Slave recovery on host 192.168.50.130(192.168.50.130:3306) started, pid: 80984. Check tmp log /etc/mha_manager/192.168.50.130_3306_20210825222418.log if it takes time..
Wed Aug 25 22:24:27 2021 - [info]
Wed Aug 25 22:24:27 2021 - [info] Log messages from 192.168.50.130 ...
Wed Aug 25 22:24:27 2021 - [info]
Wed Aug 25 22:24:25 2021 - [info] Sending binlog..
Wed Aug 25 22:24:25 2021 - [info] scp from local:/etc/mha_manager/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog to root@192.168.50.130:/var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog succeeded.
Wed Aug 25 22:24:25 2021 - [info] Starting recovery on 192.168.50.130(192.168.50.130:3306)..
Wed Aug 25 22:24:25 2021 - [info]  Generating diffs succeeded.
Wed Aug 25 22:24:25 2021 - [info] Waiting until all relay logs are applied.
Wed Aug 25 22:24:25 2021 - [info]  done.
Wed Aug 25 22:24:25 2021 - [info] Getting slave status..
Wed Aug 25 22:24:25 2021 - [info] This slave(192.168.50.130)'s Exec_Master_Log_Pos equals to Read_Master_Log_Pos(log-bin.000004:154). No need to recover from Exec_Master_Log_Pos.
Wed Aug 25 22:24:25 2021 - [info] Connecting to the target slave host 192.168.50.130, running recover script..
Wed Aug 25 22:24:25 2021 - [info] Executing command: apply_diff_relay_logs --command=apply --slave_user='root' --slave_host=192.168.50.130 --slave_ip=192.168.50.130  --slave_port=3306 --apply_files=/var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog --workdir=/var/tmp --target_version=5.7.17-log --timestamp=20210825222418 --handle_raw_binlog=1 --disable_log_bin=0 --manager_version=0.55 --slave_pass=xxx
Wed Aug 25 22:24:26 2021 - [info]
MySQL client version is 5.7.17. Using --binary-mode.
Applying differential binary/relay log files /var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog on 192.168.50.130:3306. This may take long time...
Applying log files succeeded.
Wed Aug 25 22:24:26 2021 - [info]  All relay logs were successfully applied.
Wed Aug 25 22:24:26 2021 - [info]  Resetting slave 192.168.50.130(192.168.50.130:3306) and starting replication from the new master 192.168.50.4(192.168.50.4:3306)..
Wed Aug 25 22:24:26 2021 - [info]  Executed CHANGE MASTER.
Wed Aug 25 22:24:26 2021 - [info]  Slave started.
Wed Aug 25 22:24:27 2021 - [info] End of log messages from 192.168.50.130.
Wed Aug 25 22:24:27 2021 - [info] -- Slave recovery on host 192.168.50.130(192.168.50.130:3306) succeeded.
Wed Aug 25 22:24:27 2021 - [info] All new slave servers recovered successfully.
Wed Aug 25 22:24:27 2021 - [info]
Wed Aug 25 22:24:27 2021 - [info] * Phase 5: New master cleanup phase..
Wed Aug 25 22:24:27 2021 - [info]
Wed Aug 25 22:24:27 2021 - [info] Resetting slave info on the new master..
Wed Aug 25 22:24:27 2021 - [info]  192.168.50.4: Resetting slave info succeeded.
Wed Aug 25 22:24:27 2021 - [info] Master failover to 192.168.50.4(192.168.50.4:3306) completed successfully.
Wed Aug 25 22:24:27 2021 - [info] 

----- Failover Report -----

app1: MySQL Master failover 192.168.50.171 to 192.168.50.4 succeeded

Master 192.168.50.171 is down!

Check MHA Manager logs at centos7-24-4:/etc/mha_manager/manager.log for details.

Started automated(non-interactive) failover.
Invalidated master IP address on 192.168.50.171.
The latest slave 192.168.50.4(192.168.50.4:3306) has all relay logs for recovery.
Selected 192.168.50.4 as a new master.
192.168.50.4: OK: Applying all logs succeeded.
192.168.50.4: OK: Activated master IP address.
192.168.50.130: This host has the latest relay log events.
Generating relay diff files from the latest slave succeeded.
192.168.50.130: OK: Applying all logs succeeded. Slave started, replicating from 192.168.50.4.
192.168.50.4: Resetting slave info succeeded.
Master failover to 192.168.50.4(192.168.50.4:3306) completed successfully.