目錄
- 一、概述
-
- 1、MHA簡介
- 2、MHA的組成
- 3、MHA特點
- 二、搭建MySQL MHA實驗
-
- 1、實驗環境
- 2、實驗目的
- 3、實驗步驟
一、概述
1、MHA簡介
- 一套優秀的MySQL高可用環境下故障切換和主從複制的軟體
- MHA的出現就是解決MySQL單點的問題
- MySQL故障過程中,MHA能做到0~30秒内自動完成故障切換
- MHA能在最大程度上保證資料的一緻性,以達到真正意義上的高可用
2、MHA的組成
-
MHA Manager(管理節點)
MHA Manager 可以單獨部署在一台獨立的機器上,管理多個 master-slave 叢集;也可以部署在一台 slave 節點上。
MHA Manager 會定時探測叢集中的 master 節點。當 master 出現故障時,它可以自動将最新資料的 slave 提升為新的 master, 然後将所有其他的 slave 重新指向新的 master。整個故障轉移過程對應用程式完全透明。
-
MHA Node(資料節點)
MHA Node運作在每台MySQL伺服器上
3、MHA特點
- 自動故障切換過程中,MHA視圖從當機的主伺服器上儲存二進制日志,最大程度的保證資料不丢失
- 使用半同步複制,可以大大降低資料丢失的風險,如果隻有一個slave已經收到了最新的二進制日志,MHA可以将最新的二進制日志應用于其他所有的slave伺服器上,是以可以保證所有節點的資料一緻性
- 目前MHA支援一主多從架構,最少三台服務,即一主兩從
二、搭建MySQL MHA實驗
1、實驗環境
2、實驗目的
- 通過MHA監控MySQL伺服器,在伺服器故障時自動進行切換,不影響業務
- 當主伺服器當機時,備選主伺服器自動成為主伺服器
3、實驗步驟
1)關閉所有伺服器的防火牆
systemctl stop firewalld
setenforce 0
2)Master、Slave1、Slave2 節點上安裝 mysql5.7
3)改 Master、Slave1、Slave2 節點的主機名
hostnamectl set-hostname Mysql1
su
hostnamectl set-hostname Mysql2
su
hostnamectl set-hostname Mysql3
su
4)修改 Master、Slave1、Slave2 節點的 Mysql主配置檔案/etc/my.cnf
##Master 節點##
vim /etc/my.cnf
[mysqld]
server-id = 1
log_bin = master-bin
log-slave-updates = true
systemctl restart mysqld
##Slave1、Slave2 節點##
vim /etc/my.cnf
server-id = 2 #三台伺服器的 server-id 不能一樣
log_bin = master-bin
relay-log = relay-log-bin
relay-log-index = slave-relay-bin.index
systemctl restart mysqld
5)在 Master、Slave1、Slave2 節點上都建立兩個軟連結
ln -s /usr/local/mysql/bin/mysql /usr/sbin/
ln -s /usr/local/mysql/bin/mysqlbinlog /usr/sbin/
6)配置 mysql 一主兩從
(1)所有資料庫節點進行 mysql 授權
mysql -uroot -p
grant replication slave on *.* to 'myslave'@'192.168.241.%' identified by '123'; #從資料庫同步使用
grant all privileges on *.* to 'mha'@'192.168.241.%' identified by 'manager'; #manager 使用
grant all privileges on *.* to 'mha'@'Mysql1' identified by 'manager'; #防止從庫通過主機名連接配接不上主庫
grant all privileges on *.* to 'mha'@'Mysql2' identified by 'manager';
grant all privileges on *.* to 'mha'@'Mysql3' identified by 'manager';
flush privileges;
(2)在 Master 節點檢視二進制檔案和同步點
show master status;
+-------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| master-bin.000001 | 2566 | | | |
+-------------------+----------+--------------+------------------+-------------------+
(3)在 Slave1、Slave2 節點執行同步操作
change master to master_host='192.168.241.4',master_user='myslave',master_password='123',master_log_file='master-bin.000001',master_log_pos=2566;
start slave;
(4)在 Slave1、Slave2 節點檢視資料同步結果
show slave status\G
//確定 IO 和 SQL 線程都是 Yes,代表同步正常。
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
(5)兩個從庫必須設定為隻讀模式:
(6)插入資料測試資料庫同步
create database hzh;
use hzh;
create table test(id int);
insert into test(id) values (1);
7)安裝 MHA 軟體
(1)所有伺服器上都安裝 MHA 依賴的環境,首先安裝 epel 源
epel源需要使用線上源安裝,如果使用本地源的話是沒法安裝的,需要将本地源給釋放出來
cd /etc/yum.repos.d
/etc/yum.repos.d
mv * ../
進行編譯安裝
yum install epel-release --nogpgcheck -y
yum install -y perl-DBD-MySQL \
perl-Config-Tiny \
perl-Log-Dispatch \
perl-Parallel-ForkManager \
perl-ExtUtils-CBuilder \
perl-ExtUtils-MakeMaker \
perl-CPAN
(2)安裝 MHA 軟體包,先在所有伺服器上必須先安裝 node 元件
對于每個作業系統版本不一樣,這裡 CentOS7.4 必須選擇 0.57 版本。
在所有伺服器上必須先安裝 node 元件,最後在 MHA-manager 節點上安裝 manager 元件,因為 manager 依賴 node 元件。
将安裝包拖入/opt目錄中進行解壓安裝
cd /opt
tar zxvf mha4mysql-node-0.57.tar.gz
cd mha4mysql-node-0.57
perl Makefile.PL
make && make install
(3)在 MHA manager 節點上安裝 manager 元件
cd /opt
tar zxvf mha4mysql-manager-0.57.tar.gz
cd mha4mysql-manager-0.57
perl Makefile.PL
make && make install
######################################################
#manager 元件安裝後在/usr/local/bin 下面會生成幾個工具,主要包括以下幾個:
masterha_check_ssh 檢查 MHA 的 SSH 配置狀況
masterha_check_repl 檢查 MySQL 複制狀況
masterha_manger 啟動 manager的腳本
masterha_check_status 檢測目前 MHA 運作狀态
masterha_master_monitor 檢測 master 是否當機
masterha_master_switch 控制故障轉移(自動或者手動)
masterha_conf_host 添加或删除配置的 server 資訊
masterha_stop 關閉manager
#node 元件安裝後也會在/usr/local/bin 下面會生成幾個腳本(這些工具通常由 MHAManager 的腳本觸發,無需人為操作)主要如下:
save_binary_logs 儲存和複制 master 的二進制日志
apply_diff_relay_logs 識别差異的中繼日志事件并将其差異的事件應用于其他的 slave
filter_mysqlbinlog 去除不必要的 ROLLBACK 事件(MHA 已不再使用這個工具)
purge_relay_logs 清除中繼日志(不會阻塞 SQL 線程)
8)在所有伺服器上配置無密碼認證
(1)在 manager 節點上配置到所有資料庫節點的無密碼認證
ssh-keygen -t rsa #一路按Enter鍵
ssh-copy-id 192.168.241.4
ssh-copy-id 192.168.241.5
ssh-copy-id 192.168.241.6
(2)在 mysql1 上配置到資料庫節點 mysql2 和 mysql3 的無密碼認證
ssh-keygen -t rsa
ssh-copy-id 192.168.241.5
ssh-copy-id 192.168.241.6
(3)在 mysql2 上配置到資料庫節點 mysql1 和 mysql3 的無密碼認證
ssh-keygen -t rsa
ssh-copy-id 192.168.241.4
ssh-copy-id 192.168.241.6
(4)在 mysql3 上配置到資料庫節點 mysql1 和 mysql2 的無密碼認證
ssh-keygen -t rsa
ssh-copy-id 192.168.241.4
ssh-copy-id 192.168.241.5
9)在 manager 節點上配置 MHA
(1)在 manager 節點上複制相關腳本到/usr/local/bin 目錄
cp -rp /opt/mha4mysql-manager-0.57/samples/scripts /usr/local/bin
//拷貝後會有四個執行檔案
ll /usr/local/bin/scripts/
####################################################
master_ip_failover #自動切換時 VIP 管理的腳本
master_ip_online_change #線上切換時 vip 的管理
power_manager #故障發生後關閉主機的腳本
send_report #因故障切換後發送報警的腳本
(2)複制上述的自動切換時 VIP 管理的腳本到 /usr/local/bin 目錄,這裡使用master_ip_failover腳本來管理 VIP 和故障切換
cp /usr/local/bin/scripts/master_ip_failover /usr/local/bin
(3)修改内容如下:(删除原有内容,直接複制并修改vip相關參數)
vim /usr/local/bin/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.241.200'; #指定vip的位址
my $brdc = '192.168.241.255'; #指定vip的廣播位址
my $ifdev = 'ens33'; #指定vip綁定的網卡
my $key = '1'; #指定vip綁定的虛拟網卡序列号
my $ssh_start_vip = "/sbin/ifconfig ens33:$key $vip"; #代表此變量值為ifconfig ens33:1 192.168.241.200
my $ssh_stop_vip = "/sbin/ifconfig ens33:$key down"; #代表此變量值為ifconfig ens33:1 192.168.241.200 down
my $exit_code = 0; #指定退出狀态碼為0
#my $ssh_start_vip = "/usr/sbin/ip addr add $vip/24 brd $brdc dev $ifdev label $ifdev:$key;/usr/sbin/arping -q -A -c 1 -I $ifdev $vip;iptables -F;";
#my $ssh_stop_vip = "/usr/sbin/ip addr del $vip/24 dev $ifdev label $ifdev:$key";
##################################################################################
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 \"`;
}
## A simple system call that disable the VIP on the old_master
sub stop_vip() {
`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";
}
這裡需要注意的是,複制後全是“#”号開頭,需要使用vi編輯器裡的快速編輯功能,快速删掉開頭為“#”
(4)建立 MHA 軟體目錄并拷貝配置檔案,這裡使用app1.cnf配置檔案來管理 mysql 節點伺服器
mkdir /etc/masterha
cp /opt/mha4mysql-manager-0.57/samples/conf/app1.cnf /etc/masterha
vim /etc/masterha/app1.cnf #删除原有内容,直接複制并修改節點伺服器的IP位址
[server default]
manager_log=/var/log/masterha/app1/manager.log
manager_workdir=/var/log/masterha/app1
master_binlog_dir=/usr/local/mysql/data
master_ip_failover_script=/usr/local/bin/master_ip_failover
master_ip_online_change_script=/usr/local/bin/master_ip_online_change
password=manager
ping_interval=1
remote_workdir=/tmp
repl_password=123
repl_user=myslave
secondary_check_script=/usr/local/bin/masterha_secondary_check -s 192.168.241.5 -s 192.168.241.6
shutdown_script=""
ssh_user=root
user=mha
[server1]
hostname=192.168.241.4
port=3306
[server2]
candidate_master=1
check_repl_delay=0
hostname=192.168.241.5
port=3306
[server3]
hostname=192.168.241.6
port=3306
解釋下:
[server default]
manager_log=/var/log/masterha/app1/manager.log #manager日志
manager_workdir=/var/log/masterha/app1.log #manager工作目錄
master_binlog_dir=/usr/local/mysql/data/ #master儲存binlog的位置,這裡的路徑要與master裡配置的binlog的路徑一緻,以便MHA能找到
master_ip_failover_script=/usr/local/bin/master_ip_failover #設定自動failover時候的切換腳本,也就是上面的那個腳本
master_ip_online_change_script=/usr/local/bin/master_ip_online_change #設定手動切換時候的切換腳本
password=manager #設定mysql中root使用者的密碼,這個密碼是前文中建立監控使用者的那個密碼
ping_interval=1 #設定監控主庫,發送ping包的時間間隔,預設是3秒,嘗試三次沒有回應的時候自動進行failover
remote_workdir=/tmp #設定遠端mysql在發生切換時binlog的儲存位置
repl_password=123 #設定複制使用者的密碼
repl_user=myslave #設定複制使用者的使用者
report_script=/usr/local/send_report #設定發生切換後發送的報警的腳本
secondary_check_script=/usr/local/bin/masterha_secondary_check -s 192.168.241.5 -s 192.168.241.6 #指定檢查的從伺服器IP位址
shutdown_script="" #設定故障發生後關閉故障主機腳本(該腳本的主要作用是關閉主機防止發生腦裂,這裡沒有使用)
ssh_user=root #設定ssh的登入使用者名
user=mha #設定監控使用者root
[server1]
hostname=192.168.241.4
port=3306
[server2]
hostname=192.168.241.5
port=3306
candidate_master=1
#設定為候選master,設定該參數以後,發生主從切換以後将會将此從庫提升為主庫,即使這個主庫不是叢集中最新的slave
check_repl_delay=0
#預設情況下如果一個slave落後master 超過100M的relay logs的話,MHA将不會選擇該slave作為一個新的master, 因為對于這個slave的恢複需要花費很長時間;通過設定check_repl_delay=0,MHA觸發切換在選擇一個新的master的時候将會忽略複制延時,這個參數對于設定了candidate_master=1的主機非常有用,因為這個候選主在切換的過程中一定是新的master
[server3]
hostname=192.168.241.6
port=3306
10)第一次配置需要在 Master 節點上手動開啟虛拟IP
ifconfig ens33:1 192.168.241.200/24
11)在 manager 節點上測試 ssh 無密碼認證,如果正常最後會輸出 successfully,如下所示。
[[email protected] /etc]# masterha_check_ssh -conf=/etc/masterha/app1.cnf
Sun Feb 21 20:18:57 2021 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sun Feb 21 20:18:57 2021 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Sun Feb 21 20:18:57 2021 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Sun Feb 21 20:18:57 2021 - [info] Starting SSH connection tests..
Sun Feb 21 20:18:58 2021 - [debug]
Sun Feb 21 20:18:57 2021 - [debug] Connecting via SSH from [email protected](192.168.241.4:22) to [email protected](192.168.241.5:22)..
Sun Feb 21 20:18:57 2021 - [debug] ok.
Sun Feb 21 20:18:57 2021 - [debug] Connecting via SSH from [email protected](192.168.241.4:22) to [email protected](192.168.241.6:22)..
Sun Feb 21 20:18:58 2021 - [debug] ok.
Sun Feb 21 20:18:59 2021 - [debug]
Sun Feb 21 20:18:58 2021 - [debug] Connecting via SSH from [email protected](192.168.241.6:22) to [email protected](192.168.241.4:22)..
Sun Feb 21 20:18:58 2021 - [debug] ok.
Sun Feb 21 20:18:58 2021 - [debug] Connecting via SSH from [email protected](192.168.241.6:22) to [email protected](192.168.241.5:22)..
Sun Feb 21 20:18:59 2021 - [debug] ok.
Sun Feb 21 20:18:59 2021 - [debug]
Sun Feb 21 20:18:57 2021 - [debug] Connecting via SSH from [email protected](192.168.241.5:22) to [email protected](192.168.241.4:22)..
Sun Feb 21 20:18:58 2021 - [debug] ok.
Sun Feb 21 20:18:58 2021 - [debug] Connecting via SSH from [email protected](192.168.241.5:22) to [email protected](192.168.241.6:22)..
Sun Feb 21 20:18:58 2021 - [debug] ok.
Sun Feb 21 20:18:59 2021 - [info] All SSH connection tests passed successfully.
12)在 manager 節點上測試 mysql 主從連接配接情況,最後出現 MySQL Replication Health is OK 字樣說明正常。如下所示。
masterha_check_repl -conf=/etc/masterha/app1.cnf
Sun Feb 21 20:39:14 2021 - [info] Slaves settings check done.
Sun Feb 21 20:39:14 2021 - [info]
192.168.241.4(192.168.241.4:3306) (current master)
+--192.168.241.5(192.168.241.5:3306)
+--192.168.241.6(192.168.241.6:3306)
Sun Feb 21 20:39:14 2021 - [info] Checking replication health on 192.168.241.5..
Sun Feb 21 20:39:14 2021 - [info] ok.
Sun Feb 21 20:39:14 2021 - [info] Checking replication health on 192.168.241.6..
Sun Feb 21 20:39:14 2021 - [info] ok.
Sun Feb 21 20:39:14 2021 - [info] Checking master_ip_failover_script status:
Sun Feb 21 20:39:14 2021 - [info] /usr/local/bin/master_ip_failover --command=status --ssh_user=root --orig_master_host=192.168.241.4 --orig_master_ip=192.168.241.4 --orig_master_port=3306
IN SCRIPT TEST====/sbin/ifconfig ens33:1 down==/sbin/ifconfig ens33:1 192.168.241.200===
Checking the Status of the script.. OK
Sun Feb 21 20:39:14 2021 - [info] OK.
Sun Feb 21 20:39:14 2021 - [warning] shutdown_script is not defined.
Sun Feb 21 20:39:14 2021 - [info] Got exit code 0 (Not master dead).
MySQL Replication Health is OK.
13)在 manager 節點上啟動 MHA
nohup masterha_manager --conf=/etc/masterha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/masterha/app1/manager.log 2>&1 &
#########################################################################
--remove_dead_master_conf:該參數代表當發生主從切換後,老的主庫的 ip 将會從配置檔案中移除。
--manger_log:日志存放位置。
--ignore_last_failover:在預設情況下,如果 MHA 檢測到連續發生當機,且兩次當機間隔不足 8 小時的話,則不會進行 Failover, 之是以這樣限制是為了避免 ping-pong 效應。該參數代表忽略上次 MHA 觸發切換産生的檔案,預設情況下,MHA 發生切換後會在日志記目錄,也就是上面設定的日志app1.failover.complete檔案,下次再次切換的時候如果發現該目錄下存在該檔案将不允許觸發切換,除非在第一次切換後收到删除該檔案,為了友善,這裡設定為--ignore_last_failover。
14)檢視 MHA 狀态,可以看到目前的 master 是 Mysql1 節點。
masterha_check_status --conf=/etc/masterha/app1.cnf
15)檢視 MHA 日志,也以看到目前的 master 是 192.168.241.4,如下所示。
16)檢視 Mysql1 的 VIP 位址 192.168.241.200 是否存在,這個 VIP 位址不會因為 manager 節點停止 MHA 服務而消失。
模拟下MySQL主伺服器故障
1)在 manager 節點上監控觀察日志記錄
tail -f /var/log/masterha/app1/manager.log
2)在 Master 節點 Mysql1 上停止mysql服務
systemctl stop mysqld
或
pkill -9 mysql
##############################
#正常自動切換一次後,MHA 程序會退出。HMA 會自動修改 app1.cnf 檔案内容,将當機的 mysql1 節點删除。檢視 mysql2 是否接管 VIP
ifconfig
故障切換備選主庫的算法:
1.一般判斷從庫的是從(position/GTID)判斷優劣,資料有差異,最接近于master的slave,成為備選主。
2.資料一緻的情況下,按照配置檔案順序,選擇備選主庫。
3.設定有權重(candidate_master=1),按照權重強制指定備選主。
(1)預設情況下如果一個slave落後master 100M的relay logs的話,即使有權重,也會失效。
(2)如果check_repl_delay=0的話,即使落後很多日志,也強制選擇其為備選主。
故障恢複
1) 修複mysql
systemctl restart mysqld
2)修複主從
1、在現主庫伺服器 Mysql2 檢視二進制檔案和同步點
2、在原主庫伺服器 mysql1 執行同步操作
change master to master_host='192.168.241.5',master_user='myslave',master_password='123',master_log_file='master-bin.000007',master_log_pos=1747;
start slave;
show slave status\G
###################
假如發現IO變成NO了
Slave_IO_Running: NO
Slave_SQL_Running: Yes
這是我的情況:
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.241.5
Master_User: myslave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000008
Read_Master_Log_Pos: 154
Relay_Log_File: mysql1-relay-bin.000002
Relay_Log_Pos: 4
Relay_Master_Log_File: master-bin.000008
Slave_IO_Running: No
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 154
Relay_Log_Space: 154
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 1236
Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2
Master_UUID: 8721c727-5d32-11eb-a430-000c2941b2e9
Master_Info_File: /usr/local/mysql/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp: 210219 15:00:48
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
此時你需要在新的主MySQL主伺服器上重新整理下日志
flush logs;
show master status;
然後再去MySQL1上進行授權
change master to master_log_file='mysql-bin.000009',master_log_pos=154;
start slave;
show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.241.5
Master_User: myslave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000009
Read_Master_Log_Pos: 154
Relay_Log_File: mysql1-relay-bin.000003
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000009
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 154
Relay_Log_Space: 528
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2
Master_UUID: 8721c727-5d32-11eb-a430-000c2941b2e9
Master_Info_File: /usr/local/mysql/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
這樣問題就解決了
3)在 manager 節點上修改配置檔案app1.cnf(再把這個記錄添加進去,因為它檢測掉失效時候會自動消失)
vim /etc/masterha/app1.cnf
......
secondary_check_script=/usr/local/bin/masterha_secondary_check -s 192.168.241.4 -s 192.168.241.6
......
[server1]
hostname=192.168.241.5
port=3306
[server2]
candidate_master=1
check_repl_delay=0
hostname=192.168.241.4
port=3306
[server3]
hostname=192.168.241.6
port=3306
4)在 manager 節點上啟動 MHA
再驗證下master是哪個MySQL
這樣簡單的MHA實驗就成功了。。。