一、MHA相关概念及原理:
1、MHA简介:
MHA(Master High Availability)是开源的MariaDB高可用解决方案。MHA在监控master节点故障时,会提升其中拥有最新数据的slave节点成为新的master节点。MHA还提供了master节点的在线切换功能,即按需切换master/slave节点。构建MHA的前提条件是要先构建主从复制。MHA集群中的各节点彼此之间均需要基于SSH互信通信,以实现远程控制及数据管理功能。
2、MHA工作原理:
MHA的目的在于维持MariaDB主从复制中master节点的高可用性,其最大特点是可以修复多个slave节点之间的差异日志,最终使所有slave节点保持数据一致,然后从中选择一个作为新的master节点,并将其它slave节点指向它。当master节点出现故障时,可以通过对比slave节点之间I/O线程读取master节点二进制日志的position事件位置,选取最接近的slave节点作为备选master节点,其它的slave节点可以通过与备选master节点对比生成差异的中继日志,在备选master节点上应用从原来master节点保存的二进制日志,同时将备选master节点提升为新的master节点,最后在其它slave节点上应用相应的差异中继日志并从新的master节点开始复制。
3、MHA的两种角色:
(1)MHA manager:管理节点,通常单独部署在一台独立的服务器上,用来管理多个master/slave集群,也可部署在一台slave节点上,每个master/slave集群称为一个application。MHA Manager会定时探测集群中的master节点,当发现master节点出现故障时,它可以自动将具有最新数据的slave节点提升为新的master节点,然后将所有其它的slave节点重新指向新的master节点。整个故障转移过程对应用程序完全透明,完成故障转移(即主从切换)后,MHA manager会自动停止。
(2)MHA node:数据节点,运行在每台MariaDB服务器上(manager/master/slave),它通过监控具备解析和清理logs功能的脚本来加快故障转移。
4、MHA组件:
(1)manager管理节点:
a、masterha_check_ssh:检测SSH环境
b、masterha_check_repl:检测MariaDB主从复制环境
c、masterha_manager:MHA服务主程序
d、masterha_check_status:检测MHA运行状态
e、masterha_master_monitor:监测master节点可用性
f、masterha_master_switch:master节点切换
g、masterha_conf_host:添加或删除已配置节点
h、masterha_stop:停止MHA服务
(2)node数据节点:
a、save_binary_logs:保存和复制master节点二进制日志
b、apply_diff_relay_logs:识别差异的中继日志事件,并应用于其它slave节点
c、filter_mysqlbinlog:去除不必要rollback事件的工具
d、purge_relay_logs:清除中继日志工具(不会阻塞SQL线程)
(3)自定义扩展:
a、secondary_check_script:通过多条网络路由检测master节点的可用性脚本
b、master_ip_failover_script:故障转移脚本
c、shutdown_script:强制关闭master节点脚本
d、report_script:以邮件告警的方式来发送failover报告脚本
e、init_conf_load_script:加载初始配置参数脚本
f、master_ip_online_change_script:在线切换主从节点脚本
二、准备工作:
1、演示环境:
IP
操作系统
主机名
角色
数据库版本
安装方式
复制方式
server id
192.168.1.143
CentOS 7.6
node1
MHA manager
无
无
无
无
192.168.1.144
CentOS 7.6
node2
master
MariaDB-10.3.15
yum
半同步
1
192.168.1.145
CentOS 7.6
node3
slave
MariaDB-10.3.15
yum
异步
2
192.168.1.146
CentOS 7.6
node4
slave(备选master)
MariaDB-10.3.15
yum
半同步
3
实现效果:一旦master节点宕机,VIP(192.168.1.130)自动漂移至备选master节点,将其提升为新的master节点,并将slave节点Master_Host中的IP指向它。
2、配置四个节点的epel源
3、配置四个节点的服务器时间同步
4、配置四个节点的主机名
5、配置四个节点的/etc/hosts文件:
# vim /etc/hosts
192.168.1.143 node1
192.168.1.144 node2
192.168.1.145 node3
192.168.1.146 node4
6、配置四个节点SSH互信通信(除了第(4)步,其余都在manager节点中执行):
(1)生成密钥对,基于密钥认证:# ssh-keygen -t rsa -P "" --> 回车
(2)将公钥文件中的内容追加写入authorized_keys文件:# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
备注:由于四个节点两两之间都需要基于密钥认证实现互信通信,所以此处不使用ssh-copy-id命令,太过麻烦
(3)修改authorized_keys文件的权限为600:# chmod 600 ~/.ssh/authorized_keys
(4)其它三个节点创建目录:# mkdir -pv ~/.ssh
(5)将私钥和authorized_keys文件复制至其它三个节点:
# scp -p ~/.ssh/id_rsa ~/.ssh/authorized_keys root@node2:/root/.ssh
# scp -p ~/.ssh/id_rsa ~/.ssh/authorized_keys root@node3:/root/.ssh
# scp -p ~/.ssh/id_rsa ~/.ssh/authorized_keys root@node4:/root/.ssh
(6)测试免密登录:# for (( i=1; i<=4; i++)); do ssh node$i 'ifconfig ens160'; done
备注:其它三个节点也需要进行测试
7、下载MHA相关软件包:mha4mysql-manager-0.57-0.el7.noarch.rpm、mha4mysql-node-0.57-0.el7.noarch.rpm
特别注意:https://github.com/yoshinorim/mha4mysql-manager/releases下载的mha4mysql-manager-0.58-0.el7.centos.noarch.rpm和https://github.com/yoshinorim/mha4mysql-node/releases下载的mha4mysql-node-0.58-0.el7.centos.noarch.rpm,目前最新版本均为0.58,MHA从0.58版本开始增加了super_read_only功能,而MariaDB-10.3.15中没有super_read_only这个变量:
执行命令# masterha_check_repl --conf=/etc/mha/app1.cnf时会提示如下错误信息:
Checking if super_read_only is defined and turned on..DBD::mysql::st execute failed: Unknown system variable 'super_read_only' at /usr/share/perl5/vendor_perl/MHA/SlaveUtil.pm line 245.
所以最新0.58版本的mha4mysql-manager和mha4mysql-node不能使用,只能使用0.57版本
三、配置主从复制:
1、master节点修改server.cnf配置文件:# vim /etc/my.cnf.d/server.cnf
[mysqld]
port=3306
socket=/var/lib/mysql/mysql.sock
datadir=/var/lib/mysql
log_error=/var/log/mariadb.log
lower_case_table_names=1
character_set_server=utf8mb4
collation_server=utf8mb4_general_ci
innodb_file_per_table=1
skip_name_resolve=1
slow_query_log=1
slow_query_log_file=mariadb-slow.log
rpl_semi_sync_master_enabled=1
rpl_semi_sync_slave_enabled=1
log_bin=mysql-bin
log_bin_index=mysql-bin.index
binlog_format=mixed
relay_log=relay-log
relay_log_index=relay-log.index
server_id=1
sync_binlog=1
innodb_flush_log_at_trx_commit=1
2、master节点创建拥有复制权限的用户:
MariaDB [(none)]> grant replication slave on *.* to 'repluser'@'192.168.1.%' identified by '123456';
MariaDB [(none)]> flush privileges;
3、master节点创建拥有管理MHA权限的用户:
MariaDB [(none)]> grant all on *.* to 'mhauser'@'192.168.1.%' identified by '123456';
MariaDB [(none)]> flush privileges;
4、master节点查看正在使用的二进制日志文件名称及事件位置:
MariaDB [(none)]> show master status;
5、slave节点修改server.cnf配置文件:# vim /etc/my.cnf.d/server.cnf
[mysqld]
port=3306
socket=/var/lib/mysql/mysql.sock
datadir=/var/lib/mysql
log_error=/var/log/mariadb.log
lower_case_table_names=1
character_set_server=utf8mb4
collation_server=utf8mb4_general_ci
innodb_file_per_table=1
skip_name_resolve=1
slow_query_log=1
slow_query_log_file=mariadb-slow.log
relay_log=relay-log
relay_log_index=relay-log.index
server_id=2
relay_log_purge=0
read_only=1
备注:
(1)slave节点只能读不能写
(2)中继日志默认不存在,只有当复制启动时才会自动生成
(3)relay_log_purge=0,表示在默认情况下,slave节点的中继日志会在SQL线程执行完毕后被自动删除,但是在MHA环境中,这些中继日志在恢复其它slave节点时可能会被用到,因此需要禁用中继日志的自动删除功能。
6、slave节点创建拥有管理MHA权限的用户:
MariaDB [(none)]> grant all on *.* to 'mhauser'@'192.168.1.%' identified by '123456';
MariaDB [(none)]> flush privileges;
7、slave节点使用拥有复制权限的用户连接至master节点:
MariaDB [(none)]> change master to master_host='192.168.1.144',master_user='repluser',master_password='123456',master_port=3306,master_log_file='mysql-bin.000001',master_log_pos=2320;
MariaDB [(none)]> show slave status\G
备注:
(1)Slave_IO_Running和Slave_SQL_Running的值,默认为No
(2)自动在数据目录/var/lib/mysql中创建relay-log.000001、relay-log.index和relay-log.info文件
(3)Master_Log_File的值为master节点的二进制日志文件名称
(4)Read_Master_Log_Pos的值为master节点二进制日志事件的位置
8、slave节点启动复制线程:
MariaDB [(none)]> start slave;
备注:
(1)start slave等同于分别执行start slave io_thread和start slave sql_thread
(2)stop slave表示停止主从复制线程
(3)重启slave节点所在的服务器,复制线程会自动启动
MariaDB [(none)]> show slave status\G
备注:
(1)只有当Slave_IO_Running和Slave_SQL_Running的值都为Yes时,复制线程才算启动成功
(2)Seconds_Behind_Master的值为0,说明slave节点没有落后于master节点
(3)复制时的详细信息记录在slave节点的错误日志/var/log/mariadb.log中
9、备选master节点修改server.cnf配置文件:# vim /etc/my.cnf.d/server.cnf
[mysqld]
port=3306
socket=/var/lib/mysql/mysql.sock
datadir=/var/lib/mysql
log_error=/var/log/mariadb.log
lower_case_table_names=1
character_set_server=utf8mb4
collation_server=utf8mb4_general_ci
innodb_file_per_table=1
skip_name_resolve=1
slow_query_log=1
slow_query_log_file=mariadb-slow.log
rpl_semi_sync_master_enabled=1
rpl_semi_sync_slave_enabled=1
log_bin=mysql-bin
log_bin_index=mysql-bin.index
binlog_format=mixed
relay_log=relay-log
relay_log_index=relay-log.index
server_id=3
sync_binlog=1
innodb_flush_log_at_trx_commit=1
relay_log_purge=0
read_only=1
10、备选master节点创建拥有复制权限的用户:
MariaDB [(none)]> grant replication slave on *.* to 'repluser'@'192.168.1.%' identified by '123456';
MariaDB [(none)]> flush privileges;
11、备选master节点创建拥有管理MHA权限的用户:
MariaDB [(none)]> grant all on *.* to 'mhauser'@'192.168.1.%' identified by '123456';
MariaDB [(none)]> flush privileges;
12、备选master节点使用拥有复制权限的用户连接至master节点:
MariaDB [(none)]> change master to master_host='192.168.1.144',master_user='repluser',master_password='123456',master_port=3306,master_log_file='mysql-bin.000001',master_log_pos=2320;
13、备选master节点启动复制线程:
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status\G
14、master节点查看与半同步复制相关的变量和状态值:
MariaDB [(none)]> show global variables like 'rpl_semi_sync%';
备注:
(1)rpl_semi_sync_master_enabled的值为ON
(2)rpl_semi_sync_slave_enabled的值为ON
MariaDB [(none)]> show global status like 'rpl_semi_sync%';
备注:
(1)Rpl_semi_sync_master_clients的值变为1
(2)Rpl_semi_sync_master_status的值变为ON
(3)Rpl_semi_sync_slave_status的值为OFF
(4)同时满足(1)和(2)说明半同步主从复制启动成功
15、备选master节点查看与半同步复制相关的变量和状态值:
MariaDB [(none)]> show global variables like 'rpl_semi_sync%';
备注:
(1)rpl_semi_sync_master_enabled的值为ON
(2)rpl_semi_sync_slave_enabled的值为ON
MariaDB [(none)]> show global status like 'rpl_semi_sync%';
备注:
(1)Rpl_semi_sync_master_clients的值为0
(2)Rpl_semi_sync_master_status的值为OFF
(3)Rpl_semi_sync_slave_status的值变为ON
16、master节点查看异步的slave节点和半同步的备选master节点的相关信息:
MariaDB [(none)]> show slave hosts;
四、构建MHA高可用集群:
1、manager节点安装mha4mysql-manager和mha4mysql-node:
# yum -y localinstall mha4mysql-manager-0.57-0.el7.noarch.rpm mha4mysql-node-0.57-0.el7.noarch.rpm
2、其它三个节点安装mha4mysql-node:# yum -y localinstall mha4mysql-node-0.57-0.el7.noarch.rpm
3、manager节点创建目录及MHA配置文件:
manager节点需要为每个监控的master/slave集群提供一个专用的配置文件,而所有的master/slave集群也可共享全局配置。全局配置文件默认为/etc/masterha_default.cnf,为可选配置。如果仅监控一组master/slave集群,也可直接通过application配置来提供各主机的默认配置信息,而每个application的配置文件路径可自定义。
# mkdir -pv /data/mha
# mkdir -pv /scripts
# mkdir -pv /etc/mha
# vim /etc/mha/app1.cnf
[server default]
user=mhauser
password=123456
manager_workdir=/data/mha
manager_log=/data/mha/manager.log
remote_workdir=/data/mha
ssh_user=root
repl_user=repluser
repl_password=123456
ping_interval=1
master_ip_failover_script=/scripts/master_ip_failover
report_script=/scripts/send_report
[server1]
hostname=192.168.1.144
ssh_port=22
port=3306
master_binlog_dir=/var/lib/mysql
candidate_master=1
check_repl_delay=0
[server2]
hostname=192.168.1.145
ssh_port=22
port=3306
no_master=1
[server3]
hostname=192.168.1.146
ssh_port=22
port=3306
master_binlog_dir=/var/lib/mysql
candidate_master=1
check_repl_delay=0
备注:配置参数详解
(1)user:管理MHA用户的名称
(2)password:管理MHA用户的密码
(3)manager_workdir:MHA manager使用的工作目录
(4)manager_log:MHA manager生成日志的保存路径及文件名
(5)remote_workdir:每一个MHA node保存从master节点复制而来的二进制日志的工作目录
(6)ssh_user:MHA manager和MHA node通过此用户连接至MariaDB所在的主机
(7)repl_user:主从复制时使用的用户名称
(8)repl_password:主从复制时使用的用户密码
(9)ping_interval:MHA manager ping master节点的时间间隔,单位为秒,当连续3次ping失败后,MHA manager认为此master节点宕机
(10)master_ip_failover_script:故障转移脚本
(11)master_ip_online_change_script:在线切换主从节点脚本
(12)report_script:以邮件告警的方式来发送failover报告脚本
(13)hostname:目标实例的主机名或IP
(14)ssh_port:目标数据库的SSH端口号,默认为22
(15)port:目标数据库的mysqld端口号,默认为3306
(16)master_binlog_dir:master节点生成二进制日志的目录
(17)candidate_master:从不同的slave节点中,提升一个可靠的节点作为新的master节点,如果此值设置为1,此slave节点会优先成为新的master节点,即使这个slave节点的事件不是最新的
(18)check_repl_delay:默认情况下如果一个slave节点落后master节点100M的中继日志,MHA将不会选择该slave节点作为一个新的master节点,因为对于这个slave节点的恢复需要花费很长时间,通过设置check_repl_delay=0,MHA在选择一个新的master节点时将会忽略复制延时,此参数对于设置了candidate_master=1的主机非常有用,因为此备选master节点在切换过程中一定是新的master节点
(19)no_master:此slave节点永远不会成为新的master节点
17、创建master_ip_failover脚本:
# vim /scripts/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.1.130';
my $key = '0';
my $ssh_start_vip = "/usr/sbin/ifconfig ens160:$key $vip";
my $ssh_stop_vip = "/usr/sbin/ifconfig ens160:$key down";
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";
exit 0;
}
else {
&usage();
exit 1;
}
}
sub start_vip() {
`ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;
}
sub stop_vip() {
return 0 unless ($ssh_user);
`ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;
}
sub usage {
"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";
}
# chmod +x /scripts/master_ip_failover
18、创建send_report脚本:
# vim /scripts/send_report
#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
use Mail::Sender;
use Getopt::Long;
my ( $dead_master_host, $new_master_host, $new_slave_hosts, $subject, $body );
my $smtp='smtp.qq.com';
my $mail_from='83xxxxx08@qq.com';
my $mail_user='83xxxxx08@qq.com';
my $mail_pass='邮箱授权码';
my $mail_to='83xxxxx08@qq.com';
GetOptions(
'orig_master_host=s' => \$dead_master_host,
'new_master_host=s' => \$new_master_host,
'new_slave_hosts=s' => \$new_slave_hosts,
'subject=s' => \$subject,
'body=s' => \$body,
);
mailToContacts( $smtp, $mail_from, $mail_user, $mail_pass, $mail_to, $subject, $body );
sub mailToContacts {
my ( $smtp, $mail_from, $mail_user, $mail_pass, $mail_to, $subject, $msg ) = @_;
open my $DEBUG, "> /var/log/mhamail.log"
or die "Can't open the debug file:$!\n";
my $sender = new Mail::Sender {
ctype => 'text/plain;charset=utf-8',
encoding => 'utf-8',
smtp => $smtp,
from => $mail_from,
auth => 'LOGIN',
TLS_allowed => '0',
authid => $mail_user,
authpwd => $mail_pass,
to => $mail_to,
subject => $subject,
debug => $DEBUG
};
$sender->MailMsg(
{
msg => $msg,
debug => $DEBUG
}
) or print $Mail::Sender::Error;
return 1;
}
exit 0;
# chmod +x /scripts/send_report
19、manager节点检测四个节点SSH互信通信配置:# masterha_check_ssh --conf=/etc/mha/app1.cnf
备注:提示 - [info] All SSH connection tests passed successfully.
20、manager节点检测MariaDB主从复制配置:# masterha_check_repl --conf=/etc/mha/app1.cnf
备注:提示
- [info] MHA::MasterMonitor version 0.57.
- [info] Master MHA Node version is 0.57.
192.168.1.144(192.168.1.144:3306) (current master)
+--192.168.1.145(192.168.1.145:3306)
+--192.168.1.146(192.168.1.146:3306)
Checking the Status of the script.. OK
MySQL Replication Health is OK.
21、master节点添加VIP(第一次需手动添加):
# ifconfig ens160:0 192.168.1.130
# ip a l ens160
22、manager节点后台启动MHA服务:
# nohup masterha_manager --conf=/etc/mha/app1.cnf &> /data/mha/manager.log &
23、manager节点查看master节点的状态:# masterha_check_status --conf=/etc/mha/app1.cnf
备注:如果要停止MHA服务,可以使用命令# masterha_stop --conf=/etc/mha/app1.cnf
五、测试MHA高可用集群:
1、master节点停止mariadb服务,模拟故障:# mysqladmin -uroot -p shutdown
2、manager节点查看/data/mha/manager.log日志文件
备注:提示
- [info] Master is down!
- [info] * Phase 1: Configuration Check Phase..
- [info] ** Phase 1: Configuration Check Phase completed.
- [info] * Phase 2: Dead Master Shutdown Phase..
- [info] * Phase 2: Dead Master Shutdown Phase completed.
- [info] * Phase 3: Master Recovery Phase..
- [info] * Phase 3.1: Getting Latest Slaves Phase..
- [info] * Phase 3.2: Saving Dead Master's Binlog Phase..
- [info] * Phase 3.3: Determining New Master Phase..
From:
192.168.1.144(192.168.1.144:3306) (current master)
+--192.168.1.145(192.168.1.145:3306)
+--192.168.1.146(192.168.1.146:3306)
To:
192.168.1.146(192.168.1.146:3306) (new master)
+--192.168.1.145(192.168.1.145:3306)
- [info] * Phase 3.3: New Master Diff Log Generation Phase..
- [info] * Phase 3.4: Master Log Apply Phase..
- [info] ** Finished master recovery successfully.
- [info] * Phase 3: Master Recovery Phase completed.
- [info] * Phase 4: Slaves Recovery Phase..
- [info] * Phase 4.1: Starting Parallel Slave Diff Log Generation Phase..
- [info] * Phase 4.2: Starting Parallel Slave Log Apply Phase..
- [info] All relay logs were successfully applied.
- [info] All new slave servers recovered successfully.
- [info] * Phase 5: New master cleanup phase..
- [info] 192.168.1.146: Resetting slave info succeeded.
- [info] Master failover to 192.168.1.146(192.168.1.146:3306) completed successfully.
3、查看master节点网卡信息:# ip a l ens160
4、查看备选master节点网卡信息:# ip a l ens160
备注:VIP已从master节点漂移至备选master节点
5、slave节点自动将Master_Host的地址指向备选master节点(192.168.1.146):
MariaDB [(none)]> show slave status\G
6、备选master节点查看全局变量read_only的值,已变为OFF:
MariaDB [(none)]> show global variables like 'read_only';
7、备选master节点查看slave节点的相关信息:
MariaDB [(none)]> show slave hosts;
8、故障转移后,MHA服务自动停止运行,且在/data/mha目录中生成app1.failover.complete文件:
# masterha_check_status --conf=/etc/mha/app1.cnf
9、查收告警邮件:
10、修复宕机的master节点(192.168.1.144),使其以新的slave节点身份重新上线:
(1)master节点修改server.cnf配置文件,新增relay_log_purge=0和read_only=1选项,并启动mariadb服务
(2)manager节点查看复制起始位置:# grep -i "All other slaves should start" /data/mha/manager.log
- [info] All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='192.168.1.146', MASTER_PORT=3306, MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=2320, MASTER_USER='repluser', MASTER_PASSWORD='xxx';
(3)master节点使用拥有复制权限的用户连接至备选master节点:
MariaDB [(none)]> change master to master_host='192.168.1.146',master_user='repluser',master_password='123456',master_port=3306,master_log_file='mysql-bin.000001',master_log_pos=2320;
(4)master节点启动复制线程:
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status\G
(5)master节点查看与半同步复制相关的状态值:
MariaDB [(none)]> show global status like 'rpl_semi_sync%';
备注:
a、Rpl_semi_sync_master_clients的值变为0
b、Rpl_semi_sync_master_status的值变为ON
c、Rpl_semi_sync_slave_status的值为ON
(6)备选master节点查看与半同步复制相关的状态值:
MariaDB [(none)]> show global status like 'rpl_semi_sync%';
备注:
a、Rpl_semi_sync_master_clients的值变为1
b、Rpl_semi_sync_master_status的值变为ON
c、Rpl_semi_sync_slave_status的值变为OFF
(7)备选master节点查看异步的slave节点和半同步的master节点的相关信息:
MariaDB [(none)]> show slave hosts;
备注:新的主从复制构建完成
(8)manager节点删除app1.failover.complete文件:# rm -rf /data/mha/app1.failover.complete
(9)manager节点后台启动MHA服务:
# nohup masterha_manager --conf=/etc/mha/app1.cnf &> /data/mha/manager.log &
(10)manager节点查看备选master节点的状态:# masterha_check_status --conf=/etc/mha/app1.cnf