操作步骤

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. idea项目在maven projects中显示灰色的解决办法。建新建module src变成标准的文件夹

    在使用idea的过程中,有时会遇到其中一个maven模块变成灰色(可以通过view - tool windows -> maven projects 现实),如下所示: 造成这个的原因可能是忽略 ...

  2. plsql developer中各个window的作用【转】

    转载自,原文链接: -程序窗口(program window) :可以执行 sql,sqlplus 相关的语句,例如存储过程,方法,一般用来开发程序用的. -测试窗口(test window):一般是 ...

  3. Vue.JS快速上手(指令和实例方法)

    1.声明式渲染 首先,我们要知道Vue是声明式渲染,那啥是声明式渲染,我们只需要告诉程序我们想要什么结果,其他的交给程序来做.与声明式渲染相对的是命令式渲染,即命令我们的程序去做什么,程序就会跟着你的 ...

  4. promise小案例

    页面中有个板块,需要多张图片加载完之后才能进行显示 //页面中有个板块 需要多张图片加载完之后才能进行显示 const loadImg = (src) => { return new Promi ...

  5. VMware workstation16 中Centos7下MySQL8.0安装过程+Navicat远程连接

    1.MySQL yum源安装 2.安装后,首次登录mysql以及密码配置3.远程登录问题(Navicat15为例) 一.CentOS7+MySQL8.0,yum源安装1.安装mysql前应卸载原有my ...

  6. 基于Linux系统的MariaDB数据库的安装配置

    数据库是指长期存储在计算机内.有组织的和可共享的数据集合.表是数据库存储数据的基本单位,一个表由若干个字段组成 MariaDB 数据库管理系统是 MySQL 的一个分支,主要由开源社区在维护,采用 G ...

  7. Django+Ansible构建任务中心思路

    Ansible作为老牌的自动化运维工具,由Python开发,应用广泛,但其默认只提供了命令行下的使用方式,好在提供有完善的API支持二次开发,可以很方便的集成到我们的自动化运维系统中 最近一个朋友跳槽 ...

  8. leetcode 括号

    1. 括号(0809) 设计一种算法,打印n对括号的所有合法的(例如,开闭一一对应)组合. 说明:解集不能包含重复的子集. 例如,给出 n = 3,生成结果为: [ "((()))" ...

  9. Mysql - You can't specify target table '表名' for update in FROM clause 错误解决办法

    背景 在MySQL中,写SQL语句的时候 ,可能会遇到 You can't specify target table '表名' for update in FROM clause 这样的错误 错误含义 ...

  10. Identity用户管理入门四(修改、删除用户)

    修改用户不能修改Id及用户名所以创建视图模型时需要去除,新增用户跟修改用户基本视图一直,所以不再做演示 一.新建UpdateUserViewModel视图模型 using System.Compone ...