操作步骤

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.

8.3 MHA 搭建的更多相关文章

  1. mysql高可用架构MHA搭建(centos7+mysql5.7.28)

    无论是传统行业,还是互联网行业,数据可用性都是至关重要的,虽然现在已经步入大数据时代,nosql比较流行,但是作为数据持久化及事务性的关系型数据库依然是项目首选,比如mysql. 现在几乎所有的公司项 ...

  2. MySQL MHA 搭建&测试

    一:背景介绍 MHA(Master HA)是一款开源的MySQL的高可用工具,能在MySQL主从复制的基础上,实现自动化主服务器故障转移.虽然MHA试图从宕机的主服务器上保存二进制日志,但并不是总是可 ...

  3. MySQL MHA 搭建&测试(环境:CentOS7 + MySQL5.7.23)

    MySQL MHA架构介绍: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Face ...

  4. MySQL MHA搭建

    MHA算是业内比较成熟的MySQL高可用解决方案,在MySQL故障切换过程中,MHA能做到自动完成数据库的故障切换操作,并且在进行故障切换的过程中,MHA能在最大程度上保证数据的一致性,以达到真正意义 ...

  5. MySQL高可用之MHA搭建

    测试环境 节点1 172.16.200.231 6666               master         节点2 172.16.200.27 6666 slave1              ...

  6. MHA搭建及故障维护

    MHA是一种方便简单可靠的MySQL高可用架构,具体的介绍我在这里就不多说了,下面是我在网上找的一个教程,我在此基础上进行了一些修改: 大致步骤 (一).环境介绍 (二).用ssh-keygen实现四 ...

  7. MySQL 有关MHA搭建与切换的几个错误log

    1:masterha_check_repl 副本集方面报错  replicates is not defined in the configuration file! 具体信息如下: # /usr/l ...

  8. MHA搭建

    https://metacpan.org 下载perl依赖包的网站 ##################上传安装依赖包#################### mkdir /opt/soft_file ...

  9. MHA快速搭建

    很早之前写过MHA的文章,但是常常在技术群看到有同学问MHA搭建的问题,不是权限问题就是配置问题,我在这里就再次一写下配置过程以及快速的搭建.如果想知道更多的细节与原理,请参考:MySQL高可用架构之 ...

随机推荐

  1. Difference between trustStore and keyStore in Java - SSL

    Difference between trustStore and keyStore in Java - SSL   trustStore vs keyStore in Java trustStore ...

  2. SpringBoot 优雅配置跨域多种方式及Spring Security跨域访问配置的坑

    前言 最近在做项目的时候,基于前后端分离的权限管理系统,后台使用 Spring Security 作为权限控制管理, 然后在前端接口访问时候涉及到跨域,但我怎么配置跨域也没有生效,这里有一个坑,在使用 ...

  3. jdbc操作mysql(三):利用注解封装

    案例五:利用注解封装 重复步骤 我们使用jdbc操作mysql时发现,操作不同表中数据,所写的方法基本相同:比如我们根据id向用户表添加数据,根据id删除商品表的数据,或者查询所有数据并用list集合 ...

  4. String转double失去精度问题

    最近遇到一个坑,微信小程序中退款 19.9的字符串转double变成19.89,导致退不成功 . 坑死我了.现在把更改后的代码贴出来 public static void main(String[] ...

  5. asp语言中if判断语句的求助

    If a < 5 Then   Response.Redirect("1.asp")ElseIf a > 5 And a < 8 Then   Response. ...

  6. K8S的部署方式

    K8S部署主要有两种方式:

  7. MySQL——MySQL用户管理

    1.MySQL用户定义:用户名+主机域/ip/.. 2.用户作用: 1.登录 2.管理数据库及数据 3.权限: 读和写操作 4.角色: 数据库定义好的一组权限的定义 5.权限范围: 全库:*.* 单库 ...

  8. Django图片上传和前端展示

    1 - 模型 class Book(models.Model): #定义图书模型 book_name = models.CharField(max_length=100,verbose_name='书 ...

  9. MongoDB(2)- 安装 MongoDB

    MacOS 安装 MongoDB 博主目前都用 mac 电脑练习,所以这里重点讲 MacOS 安装方式 系统要求 MongoDB 4.4 社区版支持 macOS 10.13 或更高版本 安装 Home ...

  10. openswan协商流程之(四):main_inI2_outR2()

    主模式第四包:main_inI2_outR2 1. 序言 main_inI2_outR2()函数是ISAKMP协商过程中第四包的核心处理函数的入口,同时在此处理流程中已经获取到足够的隧道信息,可以生成 ...