欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Centos7下部署MySql5.7.31高可用MHA之故障转移(VIP漂移)

程序员文章站 2022-06-26 17:27:33
Centos7下部署MySql5.7.31高可用MHA之故障转移(VIP漂移)一、背景描述本篇文章接上文《Centos7下部署MySql5.7.31高可用之MHA》实现了Mysql高可用环境搭建,但是事情还没有结束,当master(192.168.6.101)故障时虽然MHA实现了Master自动切换到192.168.6.102,但是客户端需要修改连接mysql地址。此篇文章主要解决该问题,解决思路就是使用VIP,Master有一个虚拟IP地址,当Master故障时自动将虚拟IP转移到新Master。...

Centos7下部署MySql5.7.31高可用MHA之故障转移(VIP漂移)

一、背景描述
本篇文章接上文《Centos7下部署MySql5.7.31高可用之MHA》实现了Mysql高可用环境搭建,但是事情还没有结束,当master(192.168.6.101)故障时虽然MHA实现了Master自动切换到192.168.6.102,但是客户端需要修改连接mysql地址。
此篇文章主要解决该问题,解决思路就是使用VIP,Master有一个虚拟IP地址,当Master故障时自动将虚拟IP转移到新Master。

二、修改MHA-Manager节点配置

①、清空master_ip_failover文件并替换为以下内容

[root@server3 scripts]# pwd
/scripts
[root@server3 scripts]# ls -l
total 36
-rwxr-xr-x 1 root root  2083 Jan 12 17:59 master_ip_failover
-rwxr-xr-x 1 root root  3648 Jan 12 17:57 master_ip_failover_backup
-rwxr-xr-x 1 root root  9870 Jan 11 16:24 master_ip_online_change
-rwxr-xr-x 1 root root 11867 Jan 11 16:24 power_manager
-rwxr-xr-x 1 root root  1360 Jan 11 16:24 send_report
[root@server3 scripts]# vi master_ip_failover

#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
use Getopt::Long;
my (
 $command,$ssh_user,$orig_master_host,$orig_master_ip,$orig_master_port,
$new_master_host,$new_master_ip,$new_master_port
);
my $vip = '192.168.6.235';         #这里指定VIP地址
my $key = '0';
my $ssh_start_vip = "/sbin/ifconfig ens160:$key $vip";      #这条指令是启动VIP,ens160为网卡名称
my $ssh_stop_vip = "/sbin/ifconfig ens160:$key down";       #这条指令是停止VIPens160为网卡名称
GetOptions(
 'command=s' => \$command,
 'ssh_user=s' => \$ssh_user,
 'orig_master_host=s' => \$orig_master_host,
 'orig_master_ip=s' => \$orig_master_ip,
 'orig_master_port=i' => \$orig_master_port,
 'new_master_host=s' => \$new_master_host,
 'new_master_ip=s' => \$new_master_ip,
 'new_master_port=i' => \$new_master_port,
);
exit &main();
sub main {
 print "\n\nIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===\n\n";
 if ( $command eq "stop" || $command eq "stopssh" ) {
 my $exit_code = 1;
 eval {
 print "Disabling the VIP on old master: $orig_master_host \n";
 &stop_vip();
 $exit_code = 0;
 };
 if ($@) {
 warn "Got Error: $@\n";
 exit $exit_code;
 }
 exit $exit_code;
 }
 elsif ( $command eq "start" ) {
 my $exit_code = 10;
 eval {
 print "Enabling the VIP - $vip on the new master - $new_master_host
\n";
 &start_vip();
 $exit_code = 0;
 };
 if ($@) {
 warn $@;
 exit $exit_code;
 }
 exit $exit_code;
 }
 elsif ( $command eq "status" ) {
 print "Checking the Status of the script.. OK \n";
 #`ssh $ssh_user\@cluster1 \" $ssh_start_vip \"`;
 exit 0;
 }
 else {
 &usage();
 exit 1;
 }
}
# A simple system call that enable the VIP on the new master
sub start_vip() {
 `ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;
}
# A simple system call that disable the VIP on the old_master
sub stop_vip() {
 return 0 unless ($ssh_user);
 `ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;
}
sub usage {
 print
 "Usage: master_ip_failover --command=start|stop|stopssh|status --
orig_master_host=host --orig_master_ip=ip --orig_master_port=port --
new_master_host=host --new_master_ip=ip --new_master_port=port\n";
}

②、修改manager配置文件

[root@server3 scripts]# cat /etc/masterha/app1.cnf 
[server default]
manager_workdir=/masterha/app1
manager_log=/masterha/app1/manager.log
user=manager
password=123456
ssh_user=root
repl_user=testrepl
repl_password=123456
ping_interval=1
master_ip_failover_script=/scripts/master_ip_failover #添加这条故障转移配置

[server1]
hostname=192.168.6.101
port=3301
master_binlog_dir=/data/log/binlog/
candidate_master=1

[server2]
hostname=192.168.6.102
port=3301
master_binlog_dir=/data/log/binlog/
candidate_master=1

[server3]
hostname=192.168.6.103
port=3301
master_binlog_dir=/data/log/binlog/
no_master=1

三、测试VIP漂移

①、主库Master配置VIP地址

[root@server1 mysql]# ip addr add 192.168.6.235/24 dev ens160
[root@server1 mysql]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:0f:45:7f brd ff:ff:ff:ff:ff:ff
    inet 192.168.6.101/24 brd 192.168.6.255 scope global noprefixroute dynamic ens160
       valid_lft 68410sec preferred_lft 68410sec
    inet 192.168.6.235/24 scope global secondary ens160
       valid_lft forever preferred_lft forever
    inet6 fe80::ddbd:36be:b510:ef06/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

②、测试shutdown Master主数据库

关闭后查看原备库IP地址

[root@server2 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:34:7c:2a brd ff:ff:ff:ff:ff:ff
    inet 192.168.6.102/24 brd 192.168.6.255 scope global noprefixroute dynamic ens160
       valid_lft 70609sec preferred_lft 70609sec
    inet 192.168.6.235/24 brd 192.168.6.255 scope global secondary ens160:0
       valid_lft forever preferred_lft forever
    inet6 fe80::b64c:812c:68f0:6591/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

从上图可知VIP已漂移到server2服务器!
③、查看MHA Manager日志

Wed Jan 13 10:41:56 2021 - [warning] Got error on MySQL select ping: 2006 (MySQL server has gone away)
Wed Jan 13 10:41:56 2021 - [info] Executing SSH check script: exit 0
Wed Jan 13 10:41:58 2021 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.6.101' (4))
Wed Jan 13 10:41:58 2021 - [warning] Connection failed 2 time(s)..
Wed Jan 13 10:41:59 2021 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.6.101' (4))
Wed Jan 13 10:41:59 2021 - [warning] Connection failed 3 time(s)..
Wed Jan 13 10:42:00 2021 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.6.101' (4))
Wed Jan 13 10:42:00 2021 - [warning] Connection failed 4 time(s)..
Wed Jan 13 10:42:01 2021 - [warning] HealthCheck: Got timeout on checking SSH connection to 192.168.6.101! at /usr/local/share/perl5/MHA/HealthCheck.pm line 343.
Wed Jan 13 10:42:01 2021 - [warning] Master is not reachable from health checker!
Wed Jan 13 10:42:01 2021 - [warning] Master 192.168.6.101(192.168.6.101:3301) is not reachable!
Wed Jan 13 10:42:01 2021 - [warning] SSH is NOT reachable.
Wed Jan 13 10:42:01 2021 - [info] Connecting to a master server failed. Reading configuration file /etc/masterha_default.cnf and /etc/masterha/app1.cnf again, and trying to connect to all servers to check server status..
Wed Jan 13 10:42:01 2021 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Wed Jan 13 10:42:01 2021 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Wed Jan 13 10:42:01 2021 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Wed Jan 13 10:42:02 2021 - [info] GTID failover mode = 1
Wed Jan 13 10:42:02 2021 - [info] Dead Servers:
Wed Jan 13 10:42:02 2021 - [info]   192.168.6.101(192.168.6.101:3301)
Wed Jan 13 10:42:02 2021 - [info] Alive Servers:
Wed Jan 13 10:42:02 2021 - [info]   192.168.6.102(192.168.6.102:3301)
Wed Jan 13 10:42:02 2021 - [info]   192.168.6.103(192.168.6.103:3301)
Wed Jan 13 10:42:02 2021 - [info] Alive Slaves:
Wed Jan 13 10:42:02 2021 - [info]   192.168.6.102(192.168.6.102:3301)  Version=5.7.31-log (oldest major version between slaves) log-bin:enabled
Wed Jan 13 10:42:02 2021 - [info]     GTID ON
Wed Jan 13 10:42:02 2021 - [info]     Replicating from 192.168.6.101(192.168.6.101:3301)
Wed Jan 13 10:42:02 2021 - [info]     Primary candidate for the new Master (candidate_master is set)
Wed Jan 13 10:42:02 2021 - [info]   192.168.6.103(192.168.6.103:3301)  Version=5.7.31-log (oldest major version between slaves) log-bin:enabled
Wed Jan 13 10:42:02 2021 - [info]     GTID ON
Wed Jan 13 10:42:02 2021 - [info]     Replicating from 192.168.6.101(192.168.6.101:3301)
Wed Jan 13 10:42:02 2021 - [info]     Not candidate for the new Master (no_master is set)
Wed Jan 13 10:42:02 2021 - [info] Checking slave configurations..
Wed Jan 13 10:42:02 2021 - [info]  read_only=1 is not set on slave 192.168.6.102(192.168.6.102:3301).
Wed Jan 13 10:42:02 2021 - [info]  read_only=1 is not set on slave 192.168.6.103(192.168.6.103:3301).
Wed Jan 13 10:42:02 2021 - [info] Checking replication filtering settings..
Wed Jan 13 10:42:02 2021 - [info]  Replication filtering check ok.
Wed Jan 13 10:42:02 2021 - [info] Master is down!
Wed Jan 13 10:42:02 2021 - [info] Terminating monitoring script.
Wed Jan 13 10:42:02 2021 - [info] Got exit code 20 (Master dead).
Wed Jan 13 10:42:02 2021 - [info] MHA::MasterFailover version 0.58.
Wed Jan 13 10:42:02 2021 - [info] Starting master failover.
Wed Jan 13 10:42:02 2021 - [info] 
Wed Jan 13 10:42:02 2021 - [info] * Phase 1: Configuration Check Phase..
Wed Jan 13 10:42:02 2021 - [info] 
Wed Jan 13 10:42:03 2021 - [info] GTID failover mode = 1
Wed Jan 13 10:42:03 2021 - [info] Dead Servers:
Wed Jan 13 10:42:03 2021 - [info]   192.168.6.101(192.168.6.101:3301)
Wed Jan 13 10:42:03 2021 - [info] Checking master reachability via MySQL(double check)...
Wed Jan 13 10:42:04 2021 - [info]  ok.
Wed Jan 13 10:42:04 2021 - [info] Alive Servers:
Wed Jan 13 10:42:04 2021 - [info]   192.168.6.102(192.168.6.102:3301)
Wed Jan 13 10:42:04 2021 - [info]   192.168.6.103(192.168.6.103:3301)
Wed Jan 13 10:42:04 2021 - [info] Alive Slaves:
Wed Jan 13 10:42:04 2021 - [info]   192.168.6.102(192.168.6.102:3301)  Version=5.7.31-log (oldest major version between slaves) log-bin:enabled
Wed Jan 13 10:42:04 2021 - [info]     GTID ON
Wed Jan 13 10:42:04 2021 - [info]     Replicating from 192.168.6.101(192.168.6.101:3301)
Wed Jan 13 10:42:04 2021 - [info]     Primary candidate for the new Master (candidate_master is set)
Wed Jan 13 10:42:04 2021 - [info]   192.168.6.103(192.168.6.103:3301)  Version=5.7.31-log (oldest major version between slaves) log-bin:enabled
Wed Jan 13 10:42:04 2021 - [info]     GTID ON
Wed Jan 13 10:42:04 2021 - [info]     Replicating from 192.168.6.101(192.168.6.101:3301)
Wed Jan 13 10:42:04 2021 - [info]     Not candidate for the new Master (no_master is set)
Wed Jan 13 10:42:04 2021 - [info] Starting GTID based failover.
Wed Jan 13 10:42:04 2021 - [info] 
Wed Jan 13 10:42:04 2021 - [info] ** Phase 1: Configuration Check Phase completed.
Wed Jan 13 10:42:04 2021 - [info] 
Wed Jan 13 10:42:04 2021 - [info] * Phase 2: Dead Master Shutdown Phase..
Wed Jan 13 10:42:04 2021 - [info] 
Wed Jan 13 10:42:04 2021 - [info] Forcing shutdown so that applications never connect to the current master..
Wed Jan 13 10:42:04 2021 - [info] Executing master IP deactivation script:
Wed Jan 13 10:42:04 2021 - [info]   /scripts/master_ip_failover --orig_master_host=192.168.6.101 --orig_master_ip=192.168.6.101 --orig_master_port=3301 --command=stop 


IN SCRIPT TEST====/sbin/ifconfig ens160:0 down==/sbin/ifconfig ens160:0 192.168.6.235===

Disabling the VIP on old master: 192.168.6.101 
Wed Jan 13 10:42:04 2021 - [info]  done.
Wed Jan 13 10:42:04 2021 - [warning] shutdown_script is not set. Skipping explicit shutting down of the dead master.
Wed Jan 13 10:42:04 2021 - [info] * Phase 2: Dead Master Shutdown Phase completed.
Wed Jan 13 10:42:04 2021 - [info] 
Wed Jan 13 10:42:04 2021 - [info] * Phase 3: Master Recovery Phase..
Wed Jan 13 10:42:04 2021 - [info] 
Wed Jan 13 10:42:04 2021 - [info] * Phase 3.1: Getting Latest Slaves Phase..
Wed Jan 13 10:42:04 2021 - [info] 
Wed Jan 13 10:42:04 2021 - [info] The latest binary log file/position on all slaves is binlog.000008:194
Wed Jan 13 10:42:04 2021 - [info] Retrieved Gtid Set: 267b27d0-48b5-11eb-92ec-000c290f457f:1-23
Wed Jan 13 10:42:04 2021 - [info] Latest slaves (Slaves that received relay log files to the latest):
Wed Jan 13 10:42:04 2021 - [info]   192.168.6.102(192.168.6.102:3301)  Version=5.7.31-log (oldest major version between slaves) log-bin:enabled
Wed Jan 13 10:42:04 2021 - [info]     GTID ON
Wed Jan 13 10:42:04 2021 - [info]     Replicating from 192.168.6.101(192.168.6.101:3301)
Wed Jan 13 10:42:04 2021 - [info]     Primary candidate for the new Master (candidate_master is set)
Wed Jan 13 10:42:04 2021 - [info]   192.168.6.103(192.168.6.103:3301)  Version=5.7.31-log (oldest major version between slaves) log-bin:enabled
Wed Jan 13 10:42:04 2021 - [info]     GTID ON
Wed Jan 13 10:42:04 2021 - [info]     Replicating from 192.168.6.101(192.168.6.101:3301)
Wed Jan 13 10:42:04 2021 - [info]     Not candidate for the new Master (no_master is set)
Wed Jan 13 10:42:04 2021 - [info] The oldest binary log file/position on all slaves is binlog.000008:194
Wed Jan 13 10:42:04 2021 - [info] Retrieved Gtid Set: 267b27d0-48b5-11eb-92ec-000c290f457f:1-23
Wed Jan 13 10:42:04 2021 - [info] Oldest slaves:
Wed Jan 13 10:42:04 2021 - [info]   192.168.6.102(192.168.6.102:3301)  Version=5.7.31-log (oldest major version between slaves) log-bin:enabled
Wed Jan 13 10:42:04 2021 - [info]     GTID ON
Wed Jan 13 10:42:04 2021 - [info]     Replicating from 192.168.6.101(192.168.6.101:3301)
Wed Jan 13 10:42:04 2021 - [info]     Primary candidate for the new Master (candidate_master is set)
Wed Jan 13 10:42:04 2021 - [info]   192.168.6.103(192.168.6.103:3301)  Version=5.7.31-log (oldest major version between slaves) log-bin:enabled
Wed Jan 13 10:42:04 2021 - [info]     GTID ON
Wed Jan 13 10:42:04 2021 - [info]     Replicating from 192.168.6.101(192.168.6.101:3301)
Wed Jan 13 10:42:04 2021 - [info]     Not candidate for the new Master (no_master is set)
Wed Jan 13 10:42:04 2021 - [info] 
Wed Jan 13 10:42:04 2021 - [info] * Phase 3.3: Determining New Master Phase..
Wed Jan 13 10:42:04 2021 - [info] 
Wed Jan 13 10:42:04 2021 - [info] Searching new master from slaves..
Wed Jan 13 10:42:04 2021 - [info]  Candidate masters from the configuration file:
Wed Jan 13 10:42:04 2021 - [info]   192.168.6.102(192.168.6.102:3301)  Version=5.7.31-log (oldest major version between slaves) log-bin:enabled
Wed Jan 13 10:42:04 2021 - [info]     GTID ON
Wed Jan 13 10:42:04 2021 - [info]     Replicating from 192.168.6.101(192.168.6.101:3301)
Wed Jan 13 10:42:04 2021 - [info]     Primary candidate for the new Master (candidate_master is set)
Wed Jan 13 10:42:04 2021 - [info]  Non-candidate masters:
Wed Jan 13 10:42:04 2021 - [info]   192.168.6.103(192.168.6.103:3301)  Version=5.7.31-log (oldest major version between slaves) log-bin:enabled
Wed Jan 13 10:42:04 2021 - [info]     GTID ON
Wed Jan 13 10:42:04 2021 - [info]     Replicating from 192.168.6.101(192.168.6.101:3301)
Wed Jan 13 10:42:04 2021 - [info]     Not candidate for the new Master (no_master is set)
Wed Jan 13 10:42:04 2021 - [info]  Searching from candidate_master slaves which have received the latest relay log events..
Wed Jan 13 10:42:04 2021 - [info] New master is 192.168.6.102(192.168.6.102:3301)
Wed Jan 13 10:42:04 2021 - [info] Starting master failover..
Wed Jan 13 10:42:04 2021 - [info] 
From:
192.168.6.101(192.168.6.101:3301) (current master)
 +--192.168.6.102(192.168.6.102:3301)
 +--192.168.6.103(192.168.6.103:3301)

To:
192.168.6.102(192.168.6.102:3301) (new master)
 +--192.168.6.103(192.168.6.103:3301)
Wed Jan 13 10:42:04 2021 - [info] 
Wed Jan 13 10:42:04 2021 - [info] * Phase 3.3: New Master Recovery Phase..
Wed Jan 13 10:42:04 2021 - [info] 
Wed Jan 13 10:42:04 2021 - [info]  Waiting all logs to be applied.. 
Wed Jan 13 10:42:04 2021 - [info]   done.
Wed Jan 13 10:42:04 2021 - [info] Getting new master's binlog name and position..
Wed Jan 13 10:42:04 2021 - [info]  binlog.000001:2476
Wed Jan 13 10:42:04 2021 - [info]  All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='192.168.6.102', MASTER_PORT=3301, MASTER_AUTO_POSITION=1, MASTER_USER='testrepl', MASTER_PASSWORD='xxx';
Wed Jan 13 10:42:04 2021 - [info] Master Recovery succeeded. File:Pos:Exec_Gtid_Set: binlog.000001, 2476, 267b27d0-48b5-11eb-92ec-000c290f457f:22-23,
d8a3e74e-48db-11eb-b05f-000c29347c2a:1-11
Wed Jan 13 10:42:04 2021 - [info] Executing master IP activate script:
Wed Jan 13 10:42:04 2021 - [info]   /scripts/master_ip_failover --command=start --ssh_user=root --orig_master_host=192.168.6.101 --orig_master_ip=192.168.6.101 --orig_master_port=3301 --new_master_host=192.168.6.102 --new_master_ip=192.168.6.102 --new_master_port=3301 --new_master_user='manager'   --new_master_password=xxx
Unknown option: new_master_user
Unknown option: new_master_password


IN SCRIPT TEST====/sbin/ifconfig ens160:0 down==/sbin/ifconfig ens160:0 192.168.6.235===

Enabling the VIP - 192.168.6.235 on the new master - 192.168.6.102

Wed Jan 13 10:42:04 2021 - [info]  OK.
Wed Jan 13 10:42:04 2021 - [info] ** Finished master recovery successfully.
Wed Jan 13 10:42:04 2021 - [info] * Phase 3: Master Recovery Phase completed.
Wed Jan 13 10:42:04 2021 - [info] 
Wed Jan 13 10:42:04 2021 - [info] * Phase 4: Slaves Recovery Phase..
Wed Jan 13 10:42:04 2021 - [info] 
Wed Jan 13 10:42:04 2021 - [info] 
Wed Jan 13 10:42:04 2021 - [info] * Phase 4.1: Starting Slaves in parallel..
Wed Jan 13 10:42:04 2021 - [info] 
Wed Jan 13 10:42:04 2021 - [info] -- Slave recovery on host 192.168.6.103(192.168.6.103:3301) started, pid: 3205. Check tmp log /masterha/app1/192.168.6.103_3301_20210113104202.log if it takes time..
Wed Jan 13 10:42:06 2021 - [info] 
Wed Jan 13 10:42:06 2021 - [info] Log messages from 192.168.6.103 ...
Wed Jan 13 10:42:06 2021 - [info] 
Wed Jan 13 10:42:04 2021 - [info]  Resetting slave 192.168.6.103(192.168.6.103:3301) and starting replication from the new master 192.168.6.102(192.168.6.102:3301)..
Wed Jan 13 10:42:04 2021 - [info]  Executed CHANGE MASTER.
Wed Jan 13 10:42:05 2021 - [info]  Slave started.
Wed Jan 13 10:42:05 2021 - [info]  gtid_wait(267b27d0-48b5-11eb-92ec-000c290f457f:22-23,
d8a3e74e-48db-11eb-b05f-000c29347c2a:1-11) completed on 192.168.6.103(192.168.6.103:3301). Executed 0 events.
Wed Jan 13 10:42:06 2021 - [info] End of log messages from 192.168.6.103.
Wed Jan 13 10:42:06 2021 - [info] -- Slave on host 192.168.6.103(192.168.6.103:3301) started.
Wed Jan 13 10:42:06 2021 - [info] All new slave servers recovered successfully.
Wed Jan 13 10:42:06 2021 - [info] 
Wed Jan 13 10:42:06 2021 - [info] * Phase 5: New master cleanup phase..
Wed Jan 13 10:42:06 2021 - [info] 
Wed Jan 13 10:42:06 2021 - [info] Resetting slave info on the new master..
Wed Jan 13 10:42:06 2021 - [info]  192.168.6.102: Resetting slave info succeeded.
Wed Jan 13 10:42:06 2021 - [info] Master failover to 192.168.6.102(192.168.6.102:3301) completed successfully.
Wed Jan 13 10:42:06 2021 - [info] 

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

app1: MySQL Master failover 192.168.6.101(192.168.6.101:3301) to 192.168.6.102(192.168.6.102:3301) succeeded

Master 192.168.6.101(192.168.6.101:3301) is down!

Check MHA Manager logs at server3:/masterha/app1/manager.log for details.

Started automated(non-interactive) failover.
Invalidated master IP address on 192.168.6.101(192.168.6.101:3301)
Selected 192.168.6.102(192.168.6.102:3301) as a new master.
192.168.6.102(192.168.6.102:3301): OK: Applying all logs succeeded.
192.168.6.102(192.168.6.102:3301): OK: Activated master IP address.
192.168.6.103(192.168.6.103:3301): OK: Slave started, replicating from 192.168.6.102(192.168.6.102:3301)
192.168.6.102(192.168.6.102:3301): Resetting slave info succeeded.
Master failover to 192.168.6.102(192.168.6.102:3301) completed successfully.

④、手动切换VIP(未测试)

[root@server4 bin]# masterha_master_switch --conf=/etc/masterha/app1.cnf --master_state=alive --new_master_host=192.168.6.102 --new_master_port=3301 --orig_master_is_new_slave --running_updates_limit=10000

可以看到切换vip

***************************************************************
Disabling the VIP - 192.168.6.235/24 on old master: 192.168.6.101
***************************************************************


***************************************************************
Enabling the VIP - 192.168.6.235/24 on new master: 192.168.6.102 

参考:https://blog.51cto.com/14154700/2473272
参考:https://blog.csdn.net/asufeiya/article/details/102865808

本文地址:https://blog.csdn.net/xjjj064/article/details/112555644

相关标签: Mysql