当前位置: 首页 > news >正文

企业级 MySQL 8 全流程指南:源码编译安装、主从同步、延迟复制、半同步与 MHA 高可用搭建

1.安装依赖

安装mysql8的依赖软件:

yum install -y git bison openssl-devel ncurses-devel -y

安装cmake3:
解压:

tar xzf cmake3.tar.gz

来到make3文件夹:

 cd make3/

将下面的rpm包全部安装:

yum install *.rpm

查看安装版本:

cmake3 -version

安装gcc-11:

解压:

unzip gcc-11.zip

来到解压好的目录:

cd gcc-11/

将里面的rpm包全部安装:

yum install *.rpm
mkdir build

启动gcc并设置开机启动:

source /opt/rh/devtoolset-11/enable 
cat /opt/rh/devtoolset-11/enable >> ~/.bash_profile

查看版本:

gcc --version


解压mysql8源码包:

tar xzf mysql-boost-8.3.0.tar.gz 

进入目录:

cd mysql-8.3.0/

创建编译目录,防止编译污染目录环境:

mkdir build

进入编译目录进行编译:

cd build/

进行编译:

cmake3 .. 
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
-DMYSQL_DATADIR=/data/mysql 
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_EXTRA_CHARSETS=all 
-DDEFAULT_CHARSET=utf8mb4 
-DDEFAULT_COLLATION=utf8mb4_unicode_ci 
-DWITH_SSL=system 
-DWITH_BOOST=bundled 
-DWITH_DEBUG=OFF

#- j4 表示有几个核心就跑 几个进程

make -j4

完成如下图: 

安装:

make install

2.部署mysql:

#生成启动脚本:

cd /usr/local/mysql/support-files/
cp -p mysql.server /etc/init.d/mysqld

#修改环境变量:

vim ~/.bash_profile
export PATH=$PATH:/usr/local/mysql/bin

source ~/.bash_profile

#建立数据库程序运行用户:

useradd -M -s /sbin/nologin mysql

#建立数据库数据目录:

cd ~
mkdir -p /data/mysql/
chown mysql.mysql /data/mysql/

#生成配置文件:

vim /etc/my.cnf
[mysqld]
server-id=10
datadir=/data/mysql
socket=/data/mysql/mysql.sock
default_authentication_plugin=mysql_native_password

#数据库初始化建立mysql基本数据:

 mysqld --initialize --user=mysql

 将密码记住!!如下图圈起来的地方所示:

chkconfig mysqld on

#数据库安全初始化:

mysql_secure_installation

Securing the MySQL server deployment.Enter password for user root: #输入当前密码

The existing password for the user account root has expired. Please set a new

password.

New password: #输入新密码

Re-enter new password: #重复密码

VALIDATE PASSWORD PLUGIN can be used to test passwords

and improve security. It checks the strength of password

and allows the users to set only those passwords which are

secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: no #是否启用密码插件

Using existing password for root.

Change the password for root ? ((Press y|Y for Yes, any other key for No) : no

#是否要重置密码

... skipping.

By default, a MySQL installation has an anonymous user,

allowing anyone to log into MySQL without having to have

a user account created for them. This is intended only for

testing, and to make the installation go a bit smoother.

You should remove them before moving into a production

environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y  #回车

Success.

Normally, root should only be allowed to connect from

'localhost'. This ensures that someone cannot guess at

the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y #回车

Success.

By default, MySQL comes with a database named 'test' that

anyone can access. This is also intended only for testing,

and should be removed before moving into a production

environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No)

: y #回车

- Dropping test database...

Success.

- Removing privileges on test database...

Success.

Reloading the privilege tables will ensure that all changes

made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y #回车

Success.

测试:

 mysql -uroot -p密码

mysql -uroot -p123

3.mysql安装排错:

如果上面的实验步骤出错,想要重新部署:

第一步先将mysql停止:

/etc/init.d/mysqld stop

stop运行不了就直接kill掉进程:
先查看mysql进程号:

netstat -antplue | grep mysql

kill -9 31477

将进程删除后将前面建立的/data/mysql文件夹清空,重新部署:

rm -rf /data/mysql/*

再重新进行数据库初始化:

mysqld --initialize --user=mysql

将新密码记住:

启动mysql服务:

/etc/init.d/mysqld start

 将 mysqld 服务设置为系统开机自动启动

chkconfig mysqld on

进行数据库安全初始化:

mysql_secure_installation

Securing the MySQL server deployment.Enter password for user root: #输入当前密码

The existing password for the user account root has expired. Please set a new

password.

New password: #输入新密码

Re-enter new password: #重复密码

VALIDATE PASSWORD PLUGIN can be used to test passwords

and improve security. It checks the strength of password

and allows the users to set only those passwords which are

secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: no #是否启用密码插件

Using existing password for root.

Change the password for root ? ((Press y|Y for Yes, any other key for No) : no

#是否要重置密码

... skipping.

By default, a MySQL installation has an anonymous user,

allowing anyone to log into MySQL without having to have

a user account created for them. This is intended only for

testing, and to make the installation go a bit smoother.

You should remove them before moving into a production

environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y  #回车

Success.

Normally, root should only be allowed to connect from

'localhost'. This ensures that someone cannot guess at

the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y #回车

Success.

By default, MySQL comes with a database named 'test' that

anyone can access. This is also intended only for testing,

and should be removed before moving into a production

environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No)

: y #回车

- Dropping test database...

Success.

- Removing privileges on test database...

Success.

Reloading the privilege tables will ensure that all changes

made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y #回车

Success.

登录mysql:

mysql -uroot -p123

4.mysql的主从复制

4.1配置master:

vim /etc/my.cnf
[mysqld]
server-id=10
datadir=/data/mysql
socket=/data/mysql/mysql.sock
default_authentication_plugin=mysql_native_password
symbolic-links=0
log-bin=mysql-bin

重启mysql服务:

/etc/init.d/mysqld restart

#进入数据库配置用户权限:

mysql -p123

#生成专门用来做复制的用户,此用户是用于slave端做认证用

CREATE USER rin@'%' IDENTIFIED WITH mysql_native_password BY 'rin';

#对这个用户进行授权

GRANT REPLICATION SLAVE ON *.* TO 'rin'@'%';

#查看master的状态

SHOW MASTER STATUS;

##查看二进制日志

cd /data/mysql/
mysqlbinlog mysql-bin.000001 -vv

4.2配置salve:

4.2.1对从库安装mysql

(如果从库已经安装就跳过)
让从库的目录结构与主库一致,先进行目录创建:

mkdir -p /usr/local/mysql
mkdir -p /data/mysql

将主库编译好的mysql文件复制过来:

scp -r root@172.25.254.10:/usr/local/mysql/* /usr/local/mysql/

生成启动脚本:

cd /usr/local/mysql/support-files/
cp -p mysql.server /etc/init.d/mysqld

修改环境变量:

vim ~/.bash_profile 
export PATH=$PATH:/usr/local/mysql/bin

重新加载环境配置:

source ~/.bash_profile

建立数据库程序运行用户:

useradd -M -s /sbin/nologin mysql

对数据库用给予权限:

chown mysql.mysql /data/mysql/

生成配置文件:

vim /etc/my.cnf
[mysqld]
server-id=20
datadir=/data/mysql
socket=/data/mysql/mysql.sock
default_authentication_plugin=mysql_native_password
symbolic-links=0
log-bin=mysql-bin

数据库初始化建立mysql基本数据:

mysqld --initialize --user=mysql

 记住密码:

启动mysql:

/etc/init.d/mysqld start

 将 mysqld 服务设置为系统开机自动启动

chkconfig mysqld on

数据库安全初始化:

mysql_secure_installation

4.2.2对从库进行主从配置:

编辑配置文件

vim /etc/my.cnf

 配置内容如下:

[mysqld]
server-id=20
datadir=/data/mysql
socket=/data/mysql/mysql.sock
default_authentication_plugin=mysql_native_password
symbolic-links=0
log-bin=mysql-bin

重启服务:

/etc/init.d/mysqld restart

登录mysql:

 mysql -uroot -p
-- 方法1:单行书写(推荐,避免换行问题)
CHANGE MASTER TO MASTER_HOST='172.25.254.10', MASTER_USER='rin', MASTER_PASSWORD='rin', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=691;-- 方法2:换行时确保关键字完整
CHANGE MASTER TOMASTER_HOST='172.25.254.10',MASTER_USER='rin',MASTER_PASSWORD='rin',MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=691;

启动从库复制进程

START SLAVE;

查看主从服务是否配置成功:

 SHOW SLAVE STATUS\G

 若 Slave_IO_Running: Yes 且 Slave_SQL_Running: Yes,则成功。

测试:

在主库建立数据库并且建表插入数据,查看从库是否同步:

CREATE DATABASE rin_2;
SELECT * FROM rin_2.userlist;
INSERT INTO rin_2.userlist VALUE ('rin','123');
show databases;

在从库进行查看:

SELECT * FROM rin_2.userlist;

4.3当有数据时添加salve2:

vim /etc/my.cnf
[mysqld]
server-id=30
datadir=/data/mysql
socket=/data/mysql/mysql.sock
default_authentication_plugin=mysql_native_password
symbolic-links=0
log-bin=mysql-bin

重启服务:

/etc/init.d/mysqld restart

在master节点(主库)备份数据:

[!NOTE]

生产环境中备份时需要锁表,保证备份前后的数据一致

mysql> FLUSH TABLES WITH READ LOCK;

备份后再解锁

mysql> UNLOCK TABLES;

mysqldump命令备份的数据文件,在还原时先DROP TABLE,需要合并数据时需要删除此语句

-- Table structure for table `userlist`

--

DROP TABLE IF EXISTS `userlist`; #需要合并数据时需要删除此语句

/*!40101 SET @saved_cs_client = @@character_set_client */;

/*!40101 SET character_set_client = utf8 */;

show databases;

进行备份:

mysqldump -uroot -p123 rin_2 > rin_2.sql

将备份好的sql文件传到salve(从库):

scp -r root@172.25.254.10:~/rin_2.sql .

#利用master节点中备份出来的lee.sql在slave2中拉平数据

mysql -uroot -p123 -e "create database rin_2;"
mysql -uroot -p123 rin_2 < rin_2.sql
mysql -uroot -p123 -e "select * from rin_2.userlist;"

测试:
在主库插入内容:

mysql -uroot -p123 -e "INSERT INTO rin_2.userlist values('user9','123');"

分别查看插入内容:

主库:

mysql -uroot -p123 -e "select * from rin_2.userlist;"

从库:

mysql -uroot -p123 -e "select * from rin_2.userlist;"

5.延迟复制:

延迟复制时用来控制sql线程的,和i/o线程无关

这个延迟复制不是i/o线程过段时间来复制,i/o是正常工作的

是日志已经保存在slave端了,那个sql要等多久进行回放

#在slave端

mysql> STOP SLAVE SQL_THREAD;

mysql> CHANGE MASTER TO MASTER_DELAY=60;

mysql> START SLAVE SQL_THREAD;

mysql> SHOW SLAVE STATUS\G;

Master_Server_Id: 1

Master_UUID: db2d8c92-4dc2-11ef-b6b0-000c299355ea

Master_Info_File: /data/mysql/master.info

SQL_Delay: 60 ##延迟效果

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waiting for more

updates

Master_Retry_Count: 86400

测试:

在master中写入数据后过了延迟时间才能被查询到

6.半同步模式:

6.1gtid模式:

vim /etc/my.cnf

重启服务:

/etc/init.d/mysqld restart

停止slave端:

mysql -uroot -p123
stop slave;

开启slave端的gtid:

CHANGE MASTER TO MASTER_HOST='172.25.254.10', MASTER_USER='root',MASTER_PASSWORD='123', MASTER_AUTO_POSITION=1;
start slave;
show slave status\G;

开启成功如图:

6.2启用半同步模式:

6.2.1在master端配置开启半同步功能:

配置文件:

 vim /etc/my.cnf
rpl_semi_sync_master_enabled=1

安装半同步插件:

INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';

查看插件情况:

SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME LIKE '%semi%';

打开半同步功能:

SET GLOBAL rpl_semi_sync_master_enabled = 1;

查看半同步功能:

SHOW VARIABLES LIKE 'rpl_semi_sync%';

SHOW STATUS LIKE 'Rpl_semi_sync%';

6.2.2在slave端配置开启半同步功能:

vim /etc/my.cnf
rpl_semi_sync_slave_enabled=1

mysql -uroot -p123
INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
SET GLOBAL rpl_semi_sync_slave_enabled =1;
STOP SLAVE IO_THREAD;
START SLAVE IO_THREAD;

查看开启状况:

SHOW VARIABLES LIKE 'rpl_semi_sync%';
SHOW STATUS LIKE 'Rpl_semi_sync%';

测试:

插入三次数据:
insert into rin_2.userlist values ('user455','123');
insert into rin_2.userlist values ('user45','123');
insert into rin_2.userlist values ('user456','123');

查看:

SHOW STATUS LIKE 'Rpl_semi_sync%';

模拟故障情况:
将两个slave端都关闭,

STOP SLAVE IO_THREAD;

 测试插入数据:

insert into rin_2.userlist values ('user5','555');

再将slave端全部开启:

START SLAVE IO_THREAD;

测试插入数据:

insert into rin_2.userlist values ('user5','555');

7.配置MHA管理环境:

类别主库(Server1)候选从库(Server2)从库(Server3)MHA 管理节点
节点标识[server1][server2][server3]-
IP 地址172.25.254.10172.25.254.20172.25.254.30与实验节点同网段(如复用 Server1/2/3)
主机名172.25.254.10(IP 直接配置)172.25.254.20(IP 直接配置)172.25.254.30(修正后 IP)-
MySQL 角色主库(写入节点)从库 + 候选主库(故障时优先切换)从库(非候选主库)无 MySQL 服务(仅运行 MHA 管理器)
核心配置参数candidate_master=1
check_repl_delay=0
candidate_master=1
check_repl_delay=0
no_master=1-
MySQL 账号用户名:root
密码:123
用户名:root
密码:123
用户名:root
密码:123
-
复制配置复制用户:rin
密码:rin
binlog 目录:/data/mysql
复制用户:rin
密码:rin
同步源:172.25.254.10
复制用户:rin
密码:rin
同步源:172.25.254.10
-
SSH 配置SSH 用户:root
与所有节点免密互信
SSH 用户:root
与所有节点免密互信
SSH 用户:root
与所有节点免密互信
SSH 用户:root
与所有 MySQL 节点免密互信

  7.1关于软件安装:

 在MHA节点:

安装MHA需要的软件:

unzip MHA-7.zip
cd ./MHA-7/
yum install ./*.rpm

将 mha4mysql-node-0.58-0.el7.centos.noarch.rpm 包传到各个服务器节点上:

scp mha4mysql-node-0.58-0.el7.centos.noarch.rpm root@172.25.254.10:/mnt
scp mha4mysql-node-0.58-0.el7.centos.noarch.rpm root@172.25.254.20:/mnt
scp mha4mysql-node-0.58-0.el7.centos.noarch.rpm root@172.25.254.30:/mnt
yum install /mnt/mha4mysql-node-0.58-0.el7.centos.noarch.rpm -y
yum install /mnt/mha4mysql-node-0.58-0.el7.centos.noarch.rpm -y
yum install /mnt/mha4mysql-node-0.58-0.el7.centos.noarch.rpm -y

 mha配置:

7.2所有节点配置如下:

以下为所有节点通用配置:

/etc/init.d/mysqld stop
rm -fr /data/mysql/*

 编辑配置文件内容:

vim /etc/my.cnf

 内容如下:

[mysqld]
server-id=10
datadir=/data/mysql
socket=/data/mysql/mysql.sock
default_authentication_plugin=mysql_native_password
log-bin=binlog
gtid_mode=ON
skip-name-resolve
binlog_format=ROW
enforce-gtid-consistency=ON

mysqld --user mysql --initialize

/etc/init.d/mysqld start
mysql_secure_installation

7.2.1master:

master节点单独配置:

mysql> CREATE USER IF NOT EXISTS 'repl_rin'@'%' IDENTIFIED BY 'rin';
Query OK, 0 rows affected (10.02 sec)mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl_rin'@'%';
Query OK, 0 rows affected (0.01 sec)mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)mysql> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
Query OK, 0 rows affected, 1 warning (0.01 sec)mysql> SET GLOBAL sql_slave_skip_counter = 1;
Query OK, 0 rows affected, 2 warnings (0.00 sec)mysql> SET GLOBAL rpl_semi_sync_master_enabled = 1;
Query OK, 0 rows affected (0.00 sec)

7.2.2slave:

slave节点单独配置:

mysql> CHANGE MASTER TO MASTER_HOST='172.25.254.10', MASTER_USER='repl_rin', MASTER_PASSWORD='rin', MASTER_AUTO_POSITION=1;
Query OK, 0 rows affected, 7 warnings (0.02 sec)mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.06 sec)mysql> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
Query OK, 0 rows affected, 1 warning (0.01 sec)mysql> SET GLOBAL rpl_semi_sync_slave_enabled =1;
Query OK, 0 rows affected (0.00 sec)mysql> STOP SLAVE IO_THREAD;
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> START SLAVE IO_THREAD;
Query OK, 0 rows affected, 1 warning (0.01 sec)mysql> SHOW STATUS LIKE 'Rpl_semi_sync%';
+----------------------------+-------+
| Variable_name              | Value |
+----------------------------+-------+
| Rpl_semi_sync_slave_status | ON    |
+----------------------------+-------+
1 row in set (0.01 sec)mysql> SET GLOBAL sql_slave_skip_counter = 1;
Query OK, 0 rows affected, 2 warnings (0.00 sec)

ssl免密认证:

 ssh-keygen -t rsassh-copy-id -i ~/.ssh/id_rsa.pub root@其余节点IP

查看从库节点状况:

show slave status\G;
mysql> show slave status\G;
*************************** 1. row ***************************Slave_IO_State: Waiting for source to send eventMaster_Host: 172.25.254.10Master_User: repl_rinMaster_Port: 3306Connect_Retry: 60Master_Log_File: binlog.000002Read_Master_Log_Pos: 1654Relay_Log_File: mysql-b-relay-bin.000003Relay_Log_Pos: 451Relay_Master_Log_File: binlog.000002Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 1654Relay_Log_Space: 2370Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_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: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 10Master_UUID: 506a67d6-7129-11f0-8460-000c29b1341fMaster_Info_File: mysql.slave_master_infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Replica has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: 506a67d6-7129-11f0-8460-000c29b1341f:1-6Executed_Gtid_Set: 506a67d6-7129-11f0-8460-000c29b1341f:1-6,
528ca525-7129-11f0-8ea4-000c2923893f:1Auto_Position: 1Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: Master_public_key_path: Get_master_public_key: 0Network_Namespace: 
1 row in set, 1 warning (0.00 sec)ERROR: 
No query specified

7.2.3mha中:

mha节点单独配置:

配置MHA 的管理环境:

[root@mysql-mha ~]# mkdir  /etc/masterha
[root@mysql-mha MHA-7]# tar zxf mha4mysql-manager-0.58.tar.gz
[root@mysql-mha MHA-7]# cd  mha4mysql-manager-0.58/samples/conf/
[root@mysql-mha conf]# cat masterha_default.cnf app1.cnf  > /etc/masterha/app1.cnf

[root@MHA ~]# vim /etc/masterha/app1.cnf
[root@MHA ~]# cat /etc/masterha/app1.cnf
[server default]
user=root
password=123
ssh_user=root
repl_user=repl_rin
repl_password=rin
master_binlog_dir= /data/mysql
remote_workdir=/tmp
secondary_check_script= masterha_secondary_check -s 172.25.254.10 -s 172.25.254.30
ping_interval=3
# master_ip_failover_script= /script/masterha/master_ip_failover
# shutdown_script= /script/masterha/power_manager
# report_script= /script/masterha/send_report
# master_ip_online_change_script= /script/masterha/master_ip_online_change
[server default]
manager_workdir=/var/log/masterha/app1
manager_log=/var/log/masterha/app1/manager.log[server1]
hostname=172.25.254.10
candidate_master=1
check_repl_delay=0[server2]
hostname=172.25.254.20
candidate_master=1
check_repl_delay=0[server3]
hostname=172.25.254.30
no_master=1

允许root用户远程登录:

mysql> CREATE USER IF NOT EXISTS root@'%' identified by '123';
Query OK, 0 rows affected (0.01 sec)mysql> grant ALL ON *.* TO root@'%';
Query OK, 0 rows affected (0.01 sec)


7.3检测:

在MHA上进行

检测网络以及ssh免密:

masterha_check_ssh  --conf=/etc/masterha/app1.cnf
[root@MHA ~]# masterha_check_ssh  --conf=/etc/masterha/app1.cnf
Mon Aug  4 20:12:40 2025 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Aug  4 20:12:40 2025 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Mon Aug  4 20:12:40 2025 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Mon Aug  4 20:12:40 2025 - [info] Starting SSH connection tests..
Mon Aug  4 20:12:41 2025 - [debug] 
Mon Aug  4 20:12:40 2025 - [debug]  Connecting via SSH from root@172.25.254.10(172.25.254.10:22) to root@172.25.254.20(172.25.254.20:22)..
Mon Aug  4 20:12:41 2025 - [debug]   ok.
Mon Aug  4 20:12:41 2025 - [debug]  Connecting via SSH from root@172.25.254.10(172.25.254.10:22) to root@172.25.254.30(172.25.254.30:22)..
Mon Aug  4 20:12:41 2025 - [debug]   ok.
Mon Aug  4 20:12:42 2025 - [debug] 
Mon Aug  4 20:12:41 2025 - [debug]  Connecting via SSH from root@172.25.254.20(172.25.254.20:22) to root@172.25.254.10(172.25.254.10:22)..
Mon Aug  4 20:12:41 2025 - [debug]   ok.
Mon Aug  4 20:12:41 2025 - [debug]  Connecting via SSH from root@172.25.254.20(172.25.254.20:22) to root@172.25.254.30(172.25.254.30:22)..
Mon Aug  4 20:12:42 2025 - [debug]   ok.
Mon Aug  4 20:12:43 2025 - [debug] 
Mon Aug  4 20:12:41 2025 - [debug]  Connecting via SSH from root@172.25.254.30(172.25.254.30:22) to root@172.25.254.10(172.25.254.10:22)..
Mon Aug  4 20:12:42 2025 - [debug]   ok.
Mon Aug  4 20:12:42 2025 - [debug]  Connecting via SSH from root@172.25.254.30(172.25.254.30:22) to root@172.25.254.20(172.25.254.20:22)..
Mon Aug  4 20:12:42 2025 - [debug]   ok.
Mon Aug  4 20:12:43 2025 - [info] All SSH connection tests passed successfully.

检测数据主从复制情况:

masterha_check_repl --conf=/etc/masterha/app1.cnf
[root@MHA ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf
Mon Aug  4 20:14:23 2025 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Aug  4 20:14:23 2025 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Mon Aug  4 20:14:23 2025 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Mon Aug  4 20:14:23 2025 - [info] MHA::MasterMonitor version 0.58.
Mon Aug  4 20:14:24 2025 - [info] GTID failover mode = 1
Mon Aug  4 20:14:24 2025 - [info] Dead Servers:
Mon Aug  4 20:14:24 2025 - [info] Alive Servers:
Mon Aug  4 20:14:24 2025 - [info]   172.25.254.10(172.25.254.10:3306)
Mon Aug  4 20:14:24 2025 - [info]   172.25.254.20(172.25.254.20:3306)
Mon Aug  4 20:14:24 2025 - [info]   172.25.254.30(172.25.254.30:3306)
Mon Aug  4 20:14:24 2025 - [info] Alive Slaves:
Mon Aug  4 20:14:24 2025 - [info]   172.25.254.20(172.25.254.20:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 20:14:24 2025 - [info]     GTID ON
Mon Aug  4 20:14:24 2025 - [info]     Replicating from 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 20:14:24 2025 - [info]     Primary candidate for the new Master (candidate_master is set)
Mon Aug  4 20:14:24 2025 - [info]   172.25.254.30(172.25.254.30:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 20:14:24 2025 - [info]     GTID ON
Mon Aug  4 20:14:24 2025 - [info]     Replicating from 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 20:14:24 2025 - [info]     Not candidate for the new Master (no_master is set)
Mon Aug  4 20:14:24 2025 - [info] Current Alive Master: 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 20:14:24 2025 - [info] Checking slave configurations..
Mon Aug  4 20:14:24 2025 - [info]  read_only=1 is not set on slave 172.25.254.20(172.25.254.20:3306).
Mon Aug  4 20:14:24 2025 - [info]  read_only=1 is not set on slave 172.25.254.30(172.25.254.30:3306).
Mon Aug  4 20:14:24 2025 - [info] Checking replication filtering settings..
Mon Aug  4 20:14:24 2025 - [info]  binlog_do_db= , binlog_ignore_db= 
Mon Aug  4 20:14:24 2025 - [info]  Replication filtering check ok.
Mon Aug  4 20:14:24 2025 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Mon Aug  4 20:14:24 2025 - [info] Checking SSH publickey authentication settings on the current master..
Mon Aug  4 20:14:25 2025 - [info] HealthCheck: SSH to 172.25.254.10 is reachable.
Mon Aug  4 20:14:25 2025 - [info] 
172.25.254.10(172.25.254.10:3306) (current master)+--172.25.254.20(172.25.254.20:3306)+--172.25.254.30(172.25.254.30:3306)Mon Aug  4 20:14:25 2025 - [info] Checking replication health on 172.25.254.20..
Mon Aug  4 20:14:25 2025 - [info]  ok.
Mon Aug  4 20:14:25 2025 - [info] Checking replication health on 172.25.254.30..
Mon Aug  4 20:14:25 2025 - [info]  ok.
Mon Aug  4 20:14:25 2025 - [warning] master_ip_failover_script is not defined.
Mon Aug  4 20:14:25 2025 - [warning] shutdown_script is not defined.
Mon Aug  4 20:14:25 2025 - [info] Got exit code 0 (Not master dead).MySQL Replication Health is OK.

 7.3MHA的故障切换:

7.3.1未出现故障时手动切换master:

检测当前的集群状况:

 masterha_check_repl --conf=/etc/masterha/app1.cnf

可以看到,当前的集群状况,10为master,20为备选master,30不参与主库竞选,

[root@MHA ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf
Mon Aug  4 21:27:17 2025 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Aug  4 21:27:17 2025 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Mon Aug  4 21:27:17 2025 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Mon Aug  4 21:27:17 2025 - [info] MHA::MasterMonitor version 0.58.
Mon Aug  4 21:27:18 2025 - [info] GTID failover mode = 1
Mon Aug  4 21:27:18 2025 - [info] Dead Servers:
Mon Aug  4 21:27:18 2025 - [info] Alive Servers:
Mon Aug  4 21:27:18 2025 - [info]   172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:27:18 2025 - [info]   172.25.254.20(172.25.254.20:3306)
Mon Aug  4 21:27:18 2025 - [info]   172.25.254.30(172.25.254.30:3306)
Mon Aug  4 21:27:18 2025 - [info] Alive Slaves:
Mon Aug  4 21:27:18 2025 - [info]   172.25.254.20(172.25.254.20:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 21:27:18 2025 - [info]     GTID ON
Mon Aug  4 21:27:18 2025 - [info]     Replicating from 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:27:18 2025 - [info]     Primary candidate for the new Master (candidate_master is set)
Mon Aug  4 21:27:18 2025 - [info]   172.25.254.30(172.25.254.30:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 21:27:18 2025 - [info]     GTID ON
Mon Aug  4 21:27:18 2025 - [info]     Replicating from 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:27:18 2025 - [info]     Not candidate for the new Master (no_master is set)
Mon Aug  4 21:27:18 2025 - [info] Current Alive Master: 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:27:18 2025 - [info] Checking slave configurations..
Mon Aug  4 21:27:18 2025 - [info]  read_only=1 is not set on slave 172.25.254.20(172.25.254.20:3306).
Mon Aug  4 21:27:18 2025 - [info]  read_only=1 is not set on slave 172.25.254.30(172.25.254.30:3306).
Mon Aug  4 21:27:18 2025 - [info] Checking replication filtering settings..
Mon Aug  4 21:27:18 2025 - [info]  binlog_do_db= , binlog_ignore_db= 
Mon Aug  4 21:27:18 2025 - [info]  Replication filtering check ok.
Mon Aug  4 21:27:18 2025 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Mon Aug  4 21:27:18 2025 - [info] Checking SSH publickey authentication settings on the current master..
Mon Aug  4 21:27:18 2025 - [info] HealthCheck: SSH to 172.25.254.10 is reachable.
Mon Aug  4 21:27:18 2025 - [info] 
172.25.254.10(172.25.254.10:3306) (current master)+--172.25.254.20(172.25.254.20:3306)+--172.25.254.30(172.25.254.30:3306)Mon Aug  4 21:27:18 2025 - [info] Checking replication health on 172.25.254.20..
Mon Aug  4 21:27:18 2025 - [info]  ok.
Mon Aug  4 21:27:18 2025 - [info] Checking replication health on 172.25.254.30..
Mon Aug  4 21:27:18 2025 - [info]  ok.
Mon Aug  4 21:27:18 2025 - [warning] master_ip_failover_script is not defined.
Mon Aug  4 21:27:18 2025 - [warning] shutdown_script is not defined.
Mon Aug  4 21:27:18 2025 - [info] Got exit code 0 (Not master dead).MySQL Replication Health is OK.

手动切换master:

masterha_master_switch 
--conf=/etc/masterha/app1.cnf 
--master_state=alive 
--new_master_host=172.25.254.20 
--new_master_port=3306 
--orig_master_is_new_slave 
--running_updates_limit=10000

切换过程如下:
三次询问均为yes:

[root@MHA ~]# masterha_master_switch --conf=/etc/masterha/app1.cnf --master_state=alive --new_master_host=172.25.254.20 --new_master_port=3306 --orig_master_is_new_slave --running_updates_limit=10000
Mon Aug  4 21:34:39 2025 - [info] MHA::MasterRotate version 0.58.
Mon Aug  4 21:34:39 2025 - [info] Starting online master switch..
Mon Aug  4 21:34:39 2025 - [info] 
Mon Aug  4 21:34:39 2025 - [info] * Phase 1: Configuration Check Phase..
Mon Aug  4 21:34:39 2025 - [info] 
Mon Aug  4 21:34:39 2025 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Aug  4 21:34:39 2025 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Mon Aug  4 21:34:39 2025 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Mon Aug  4 21:34:40 2025 - [info] GTID failover mode = 1
Mon Aug  4 21:34:40 2025 - [info] Current Alive Master: 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:34:40 2025 - [info] Alive Slaves:
Mon Aug  4 21:34:40 2025 - [info]   172.25.254.20(172.25.254.20:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 21:34:40 2025 - [info]     GTID ON
Mon Aug  4 21:34:40 2025 - [info]     Replicating from 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:34:40 2025 - [info]     Primary candidate for the new Master (candidate_master is set)
Mon Aug  4 21:34:40 2025 - [info]   172.25.254.30(172.25.254.30:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 21:34:40 2025 - [info]     GTID ON
Mon Aug  4 21:34:40 2025 - [info]     Replicating from 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:34:40 2025 - [info]     Not candidate for the new Master (no_master is set)It is better to execute FLUSH NO_WRITE_TO_BINLOG TABLES on the master before switching. Is it ok to execute on 172.25.254.10(172.25.254.10:3306)? (YES/no): yes
Mon Aug  4 21:34:42 2025 - [info] Executing FLUSH NO_WRITE_TO_BINLOG TABLES. This may take long time..
Mon Aug  4 21:34:42 2025 - [info]  ok.
Mon Aug  4 21:34:42 2025 - [info] Checking MHA is not monitoring or doing failover..
Mon Aug  4 21:34:42 2025 - [info] Checking replication health on 172.25.254.20..
Mon Aug  4 21:34:42 2025 - [info]  ok.
Mon Aug  4 21:34:42 2025 - [info] Checking replication health on 172.25.254.30..
Mon Aug  4 21:34:42 2025 - [info]  ok.
Mon Aug  4 21:34:42 2025 - [info] 172.25.254.20 can be new master.
Mon Aug  4 21:34:42 2025 - [info] 
From:
172.25.254.10(172.25.254.10:3306) (current master)+--172.25.254.20(172.25.254.20:3306)+--172.25.254.30(172.25.254.30:3306)To:
172.25.254.20(172.25.254.20:3306) (new master)+--172.25.254.30(172.25.254.30:3306)+--172.25.254.10(172.25.254.10:3306)Starting master switch from 172.25.254.10(172.25.254.10:3306) to 172.25.254.20(172.25.254.20:3306)? (yes/NO): yes
Mon Aug  4 21:34:44 2025 - [info] Checking whether 172.25.254.20(172.25.254.20:3306) is ok for the new master..
Mon Aug  4 21:34:44 2025 - [info]  ok.
Mon Aug  4 21:34:44 2025 - [info] 172.25.254.10(172.25.254.10:3306): SHOW SLAVE STATUS returned empty result. To check replication filtering rules, temporarily executing CHANGE MASTER to a dummy host.
Mon Aug  4 21:34:44 2025 - [info] 172.25.254.10(172.25.254.10:3306): Resetting slave pointing to the dummy host.
Mon Aug  4 21:34:44 2025 - [info] ** Phase 1: Configuration Check Phase completed.
Mon Aug  4 21:34:44 2025 - [info] 
Mon Aug  4 21:34:44 2025 - [info] * Phase 2: Rejecting updates Phase..
Mon Aug  4 21:34:44 2025 - [info] 
master_ip_online_change_script is not defined. If you do not disable writes on the current master manually, applications keep writing on the current master. Is it ok to proceed? (yes/NO): yes
Mon Aug  4 21:34:58 2025 - [info] Locking all tables on the orig master to reject updates from everybody (including root):
Mon Aug  4 21:34:58 2025 - [info] Executing FLUSH TABLES WITH READ LOCK..
Mon Aug  4 21:34:58 2025 - [info]  ok.
Mon Aug  4 21:34:58 2025 - [info] Orig master binlog:pos is binlog.000002:2168.
Mon Aug  4 21:34:58 2025 - [info]  Waiting to execute all relay logs on 172.25.254.20(172.25.254.20:3306)..
Mon Aug  4 21:34:58 2025 - [info]  master_pos_wait(binlog.000002:2168) completed on 172.25.254.20(172.25.254.20:3306). Executed 0 events.
Mon Aug  4 21:34:58 2025 - [info]   done.
Mon Aug  4 21:34:58 2025 - [info] Getting new master's binlog name and position..
Mon Aug  4 21:34:58 2025 - [info]  binlog.000002:2514
Mon Aug  4 21:34:58 2025 - [info]  All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='172.25.254.20', MASTER_PORT=3306, MASTER_AUTO_POSITION=1, MASTER_USER='repl_rin', MASTER_PASSWORD='xxx';
Mon Aug  4 21:34:58 2025 - [info] 
Mon Aug  4 21:34:58 2025 - [info] * Switching slaves in parallel..
Mon Aug  4 21:34:58 2025 - [info] 
Mon Aug  4 21:34:58 2025 - [info] -- Slave switch on host 172.25.254.30(172.25.254.30:3306) started, pid: 4410
Mon Aug  4 21:34:58 2025 - [info] 
Mon Aug  4 21:34:59 2025 - [info] Log messages from 172.25.254.30 ...
Mon Aug  4 21:34:59 2025 - [info] 
Mon Aug  4 21:34:58 2025 - [info]  Waiting to execute all relay logs on 172.25.254.30(172.25.254.30:3306)..
Mon Aug  4 21:34:58 2025 - [info]  master_pos_wait(binlog.000002:2168) completed on 172.25.254.30(172.25.254.30:3306). Executed 0 events.
Mon Aug  4 21:34:58 2025 - [info]   done.
Mon Aug  4 21:34:58 2025 - [info]  Resetting slave 172.25.254.30(172.25.254.30:3306) and starting replication from the new master 172.25.254.20(172.25.254.20:3306)..
Mon Aug  4 21:34:58 2025 - [info]  Executed CHANGE MASTER.
Mon Aug  4 21:34:58 2025 - [info]  Slave started.
Mon Aug  4 21:34:59 2025 - [info] End of log messages from 172.25.254.30 ...
Mon Aug  4 21:34:59 2025 - [info] 
Mon Aug  4 21:34:59 2025 - [info] -- Slave switch on host 172.25.254.30(172.25.254.30:3306) succeeded.
Mon Aug  4 21:34:59 2025 - [info] Unlocking all tables on the orig master:
Mon Aug  4 21:34:59 2025 - [info] Executing UNLOCK TABLES..
Mon Aug  4 21:34:59 2025 - [info]  ok.
Mon Aug  4 21:34:59 2025 - [info] Starting orig master as a new slave..
Mon Aug  4 21:34:59 2025 - [info]  Resetting slave 172.25.254.10(172.25.254.10:3306) and starting replication from the new master 172.25.254.20(172.25.254.20:3306)..
Mon Aug  4 21:34:59 2025 - [info]  Executed CHANGE MASTER.
Mon Aug  4 21:34:59 2025 - [info]  Slave started.
Mon Aug  4 21:34:59 2025 - [info] All new slave servers switched successfully.
Mon Aug  4 21:34:59 2025 - [info] 
Mon Aug  4 21:34:59 2025 - [info] * Phase 5: New master cleanup phase..
Mon Aug  4 21:34:59 2025 - [info] 
Mon Aug  4 21:34:59 2025 - [info]  172.25.254.20: Resetting slave info succeeded.
Mon Aug  4 21:34:59 2025 - [info] Switching master to 172.25.254.20(172.25.254.20:3306) completed successfully.

再次进行集群状况检测:

masterha_check_repl --conf=/etc/masterha/app1.cnf

 集群以及将20变更为master,10变为master备选,

[root@MHA ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf
Mon Aug  4 21:35:05 2025 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Aug  4 21:35:05 2025 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Mon Aug  4 21:35:05 2025 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Mon Aug  4 21:35:05 2025 - [info] MHA::MasterMonitor version 0.58.
Mon Aug  4 21:35:10 2025 - [info] GTID failover mode = 1
Mon Aug  4 21:35:10 2025 - [info] Dead Servers:
Mon Aug  4 21:35:10 2025 - [info] Alive Servers:
Mon Aug  4 21:35:10 2025 - [info]   172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:35:10 2025 - [info]   172.25.254.20(172.25.254.20:3306)
Mon Aug  4 21:35:10 2025 - [info]   172.25.254.30(172.25.254.30:3306)
Mon Aug  4 21:35:10 2025 - [info] Alive Slaves:
Mon Aug  4 21:35:10 2025 - [info]   172.25.254.10(172.25.254.10:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 21:35:10 2025 - [info]     GTID ON
Mon Aug  4 21:35:10 2025 - [info]     Replicating from 172.25.254.20(172.25.254.20:3306)
Mon Aug  4 21:35:10 2025 - [info]     Primary candidate for the new Master (candidate_master is set)
Mon Aug  4 21:35:10 2025 - [info]   172.25.254.30(172.25.254.30:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 21:35:10 2025 - [info]     GTID ON
Mon Aug  4 21:35:10 2025 - [info]     Replicating from 172.25.254.20(172.25.254.20:3306)
Mon Aug  4 21:35:10 2025 - [info]     Not candidate for the new Master (no_master is set)
Mon Aug  4 21:35:10 2025 - [info] Current Alive Master: 172.25.254.20(172.25.254.20:3306)
Mon Aug  4 21:35:10 2025 - [info] Checking slave configurations..
Mon Aug  4 21:35:10 2025 - [info]  read_only=1 is not set on slave 172.25.254.30(172.25.254.30:3306).
Mon Aug  4 21:35:10 2025 - [info] Checking replication filtering settings..
Mon Aug  4 21:35:10 2025 - [info]  binlog_do_db= , binlog_ignore_db= 
Mon Aug  4 21:35:10 2025 - [info]  Replication filtering check ok.
Mon Aug  4 21:35:10 2025 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Mon Aug  4 21:35:10 2025 - [info] Checking SSH publickey authentication settings on the current master..
Mon Aug  4 21:35:10 2025 - [info] HealthCheck: SSH to 172.25.254.20 is reachable.
Mon Aug  4 21:35:10 2025 - [info] 
172.25.254.20(172.25.254.20:3306) (current master)+--172.25.254.10(172.25.254.10:3306)+--172.25.254.30(172.25.254.30:3306)Mon Aug  4 21:35:10 2025 - [info] Checking replication health on 172.25.254.10..
Mon Aug  4 21:35:10 2025 - [info]  ok.
Mon Aug  4 21:35:10 2025 - [info] Checking replication health on 172.25.254.30..
Mon Aug  4 21:35:10 2025 - [info]  ok.
Mon Aug  4 21:35:10 2025 - [warning] master_ip_failover_script is not defined.
Mon Aug  4 21:35:10 2025 - [warning] shutdown_script is not defined.
Mon Aug  4 21:35:10 2025 - [info] Got exit code 0 (Not master dead).MySQL Replication Health is OK.

7.3.2出现故障时手动切换master:

 检测当前的集群状况:

 masterha_check_repl --conf=/etc/masterha/app1.cnf

可以看到,当前的集群状况,10为master,20为备选master,30不参与主库竞选,

[root@MHA ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf
Mon Aug  4 21:42:20 2025 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Aug  4 21:42:20 2025 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Mon Aug  4 21:42:20 2025 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Mon Aug  4 21:42:21 2025 - [info] MHA::MasterMonitor version 0.58.
Mon Aug  4 21:42:22 2025 - [info] GTID failover mode = 1
Mon Aug  4 21:42:22 2025 - [info] Dead Servers:
Mon Aug  4 21:42:22 2025 - [info] Alive Servers:
Mon Aug  4 21:42:22 2025 - [info]   172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:42:22 2025 - [info]   172.25.254.20(172.25.254.20:3306)
Mon Aug  4 21:42:22 2025 - [info]   172.25.254.30(172.25.254.30:3306)
Mon Aug  4 21:42:22 2025 - [info] Alive Slaves:
Mon Aug  4 21:42:22 2025 - [info]   172.25.254.20(172.25.254.20:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 21:42:22 2025 - [info]     GTID ON
Mon Aug  4 21:42:22 2025 - [info]     Replicating from 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:42:22 2025 - [info]     Primary candidate for the new Master (candidate_master is set)
Mon Aug  4 21:42:22 2025 - [info]   172.25.254.30(172.25.254.30:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 21:42:22 2025 - [info]     GTID ON
Mon Aug  4 21:42:22 2025 - [info]     Replicating from 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:42:22 2025 - [info]     Not candidate for the new Master (no_master is set)
Mon Aug  4 21:42:22 2025 - [info] Current Alive Master: 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:42:22 2025 - [info] Checking slave configurations..
Mon Aug  4 21:42:22 2025 - [info]  read_only=1 is not set on slave 172.25.254.30(172.25.254.30:3306).
Mon Aug  4 21:42:22 2025 - [info] Checking replication filtering settings..
Mon Aug  4 21:42:22 2025 - [info]  binlog_do_db= , binlog_ignore_db= 
Mon Aug  4 21:42:22 2025 - [info]  Replication filtering check ok.
Mon Aug  4 21:42:22 2025 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Mon Aug  4 21:42:22 2025 - [info] Checking SSH publickey authentication settings on the current master..
Mon Aug  4 21:42:22 2025 - [info] HealthCheck: SSH to 172.25.254.10 is reachable.
Mon Aug  4 21:42:22 2025 - [info] 
172.25.254.10(172.25.254.10:3306) (current master)+--172.25.254.20(172.25.254.20:3306)+--172.25.254.30(172.25.254.30:3306)Mon Aug  4 21:42:22 2025 - [info] Checking replication health on 172.25.254.20..
Mon Aug  4 21:42:22 2025 - [info]  ok.
Mon Aug  4 21:42:22 2025 - [info] Checking replication health on 172.25.254.30..
Mon Aug  4 21:42:22 2025 - [info]  ok.
Mon Aug  4 21:42:22 2025 - [warning] master_ip_failover_script is not defined.
Mon Aug  4 21:42:22 2025 - [warning] shutdown_script is not defined.
Mon Aug  4 21:42:22 2025 - [info] Got exit code 0 (Not master dead).MySQL Replication Health is OK.

模拟故障情况发生:
将当前master,10节点停用:

 /etc/init.d/mysqld stop

查看集群状况:

masterha_check_repl --conf=/etc/masterha/app1.cnf
[root@MHA ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf
Mon Aug  4 21:44:47 2025 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Aug  4 21:44:47 2025 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Mon Aug  4 21:44:47 2025 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Mon Aug  4 21:44:47 2025 - [info] MHA::MasterMonitor version 0.58.
Mon Aug  4 21:44:49 2025 - [info] GTID failover mode = 1
Mon Aug  4 21:44:49 2025 - [info] Dead Servers:
Mon Aug  4 21:44:49 2025 - [info]   172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:44:49 2025 - [info] Alive Servers:
Mon Aug  4 21:44:49 2025 - [info]   172.25.254.20(172.25.254.20:3306)
Mon Aug  4 21:44:49 2025 - [info]   172.25.254.30(172.25.254.30:3306)
Mon Aug  4 21:44:49 2025 - [info] Alive Slaves:
Mon Aug  4 21:44:49 2025 - [info]   172.25.254.20(172.25.254.20:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 21:44:49 2025 - [info]     GTID ON
Mon Aug  4 21:44:49 2025 - [info]     Replicating from 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:44:49 2025 - [info]     Primary candidate for the new Master (candidate_master is set)
Mon Aug  4 21:44:49 2025 - [info]   172.25.254.30(172.25.254.30:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 21:44:49 2025 - [info]     GTID ON
Mon Aug  4 21:44:49 2025 - [info]     Replicating from 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:44:49 2025 - [info]     Not candidate for the new Master (no_master is set)
Mon Aug  4 21:44:49 2025 - [warning] MySQL master is not currently alive!
Mon Aug  4 21:44:49 2025 - [info] Checking slave configurations..
Mon Aug  4 21:44:49 2025 - [info]  read_only=1 is not set on slave 172.25.254.30(172.25.254.30:3306).
Mon Aug  4 21:44:49 2025 - [info] Checking replication filtering settings..
Mon Aug  4 21:44:49 2025 - [info]  Replication filtering check ok.
Mon Aug  4 21:44:49 2025 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Mon Aug  4 21:44:49 2025 - [info] Getting current master (maybe dead) info ..
Mon Aug  4 21:44:49 2025 - [info] Identified master is 172.25.254.10(172.25.254.10:3306).
Mon Aug  4 21:44:49 2025 - [info] Checking SSH publickey authentication settings on the current master..
Mon Aug  4 21:44:49 2025 - [info] HealthCheck: SSH to 172.25.254.10 is reachable.
Mon Aug  4 21:44:49 2025 - [info] Master MHA Node version is 0.58.
Mon Aug  4 21:44:49 2025 - [info] 
172.25.254.10(172.25.254.10:3306) (current master)+--172.25.254.20(172.25.254.20:3306)+--172.25.254.30(172.25.254.30:3306)Mon Aug  4 21:44:49 2025 - [info] Checking replication health on 172.25.254.20..
Mon Aug  4 21:44:49 2025 - [error][/usr/share/perl5/vendor_perl/MHA/Server.pm, ln490] Slave IO thread is not running on 172.25.254.20(172.25.254.20:3306)
Mon Aug  4 21:44:49 2025 - [error][/usr/share/perl5/vendor_perl/MHA/ServerManager.pm, ln1526]  failed!
Mon Aug  4 21:44:49 2025 - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln427] Error happened on checking configurations.  at /usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm line 420.
Mon Aug  4 21:44:49 2025 - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln525] Error happened on monitoring servers.
Mon Aug  4 21:44:49 2025 - [info] Got exit code 1 (Not master dead).MySQL Replication Health is NOT OK!

迁移master:

masterha_master_switch 
--master_state=dead 
--conf=/etc/masterha/app1.cnf 
--dead_master_host=172.25.254.10 
--dead_master_port=3306 
--new_master_host=172.25.254.20 
--new_master_port=3306 
--ignore_last_failover
参数作用
--master_state=dead声明原主库已宕机(核心参数,与在线切换区分)
--conf=/etc/masterha/app1.cnf指定 MHA 集群配置文件路径
--dead_master_host=172.25.254.10明确已宕机的原主库 IP
--dead_master_port=3306宕机主库的 MySQL 端口
--new_master_host=172.25.254.20指定新主库的 IP(需是集群中的候选从库)
--new_master_port=3306新主库的 MySQL 端口
--ignore_last_failover忽略上一次故障转移的记录(默认 MHA 会阻止短时间内重复故障转移,此参数用于强制绕过)

迁移过程:

[root@MHA ~]# masterha_master_switch --master_state=dead --conf=/etc/masterha/app1.cnf --dead_master_host=172.25.254.10 --dead_master_port=3306 --new_master_host=172.25.254.20 --new_master_port=3306 --ignore_last_failover
--dead_master_ip=<dead_master_ip> is not set. Using 172.25.254.10.
Mon Aug  4 21:52:25 2025 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Aug  4 21:52:25 2025 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Mon Aug  4 21:52:25 2025 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Mon Aug  4 21:52:25 2025 - [info] MHA::MasterFailover version 0.58.
Mon Aug  4 21:52:25 2025 - [info] Starting master failover.
Mon Aug  4 21:52:25 2025 - [info] 
Mon Aug  4 21:52:25 2025 - [info] * Phase 1: Configuration Check Phase..
Mon Aug  4 21:52:25 2025 - [info] 
Mon Aug  4 21:52:27 2025 - [info] GTID failover mode = 1
Mon Aug  4 21:52:27 2025 - [info] Dead Servers:
Mon Aug  4 21:52:27 2025 - [info]   172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:52:27 2025 - [info] Checking master reachability via MySQL(double check)...
Mon Aug  4 21:52:27 2025 - [info]  ok.
Mon Aug  4 21:52:27 2025 - [info] Alive Servers:
Mon Aug  4 21:52:27 2025 - [info]   172.25.254.20(172.25.254.20:3306)
Mon Aug  4 21:52:27 2025 - [info]   172.25.254.30(172.25.254.30:3306)
Mon Aug  4 21:52:27 2025 - [info] Alive Slaves:
Mon Aug  4 21:52:27 2025 - [info]   172.25.254.20(172.25.254.20:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 21:52:27 2025 - [info]     GTID ON
Mon Aug  4 21:52:27 2025 - [info]     Replicating from 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:52:27 2025 - [info]     Primary candidate for the new Master (candidate_master is set)
Mon Aug  4 21:52:27 2025 - [info]   172.25.254.30(172.25.254.30:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 21:52:27 2025 - [info]     GTID ON
Mon Aug  4 21:52:27 2025 - [info]     Replicating from 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:52:27 2025 - [info]     Not candidate for the new Master (no_master is set)
Master 172.25.254.10(172.25.254.10:3306) is dead. Proceed? (yes/NO): yes
Mon Aug  4 21:52:30 2025 - [info] Starting GTID based failover.
Mon Aug  4 21:52:30 2025 - [info] 
Mon Aug  4 21:52:30 2025 - [info] ** Phase 1: Configuration Check Phase completed.
Mon Aug  4 21:52:30 2025 - [info] 
Mon Aug  4 21:52:30 2025 - [info] * Phase 2: Dead Master Shutdown Phase..
Mon Aug  4 21:52:30 2025 - [info] 
Mon Aug  4 21:52:30 2025 - [info] HealthCheck: SSH to 172.25.254.10 is reachable.
Mon Aug  4 21:52:31 2025 - [info] Forcing shutdown so that applications never connect to the current master..
Mon Aug  4 21:52:31 2025 - [warning] master_ip_failover_script is not set. Skipping invalidating dead master IP address.
Mon Aug  4 21:52:31 2025 - [warning] shutdown_script is not set. Skipping explicit shutting down of the dead master.
Mon Aug  4 21:52:31 2025 - [info] * Phase 2: Dead Master Shutdown Phase completed.
Mon Aug  4 21:52:31 2025 - [info] 
Mon Aug  4 21:52:31 2025 - [info] * Phase 3: Master Recovery Phase..
Mon Aug  4 21:52:31 2025 - [info] 
Mon Aug  4 21:52:31 2025 - [info] * Phase 3.1: Getting Latest Slaves Phase..
Mon Aug  4 21:52:31 2025 - [info] 
Mon Aug  4 21:52:31 2025 - [info] The latest binary log file/position on all slaves is binlog.000002:2465
Mon Aug  4 21:52:31 2025 - [info] Latest slaves (Slaves that received relay log files to the latest):
Mon Aug  4 21:52:31 2025 - [info]   172.25.254.20(172.25.254.20:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 21:52:31 2025 - [info]     GTID ON
Mon Aug  4 21:52:31 2025 - [info]     Replicating from 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:52:31 2025 - [info]     Primary candidate for the new Master (candidate_master is set)
Mon Aug  4 21:52:31 2025 - [info]   172.25.254.30(172.25.254.30:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 21:52:31 2025 - [info]     GTID ON
Mon Aug  4 21:52:31 2025 - [info]     Replicating from 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:52:31 2025 - [info]     Not candidate for the new Master (no_master is set)
Mon Aug  4 21:52:31 2025 - [info] The oldest binary log file/position on all slaves is binlog.000002:2465
Mon Aug  4 21:52:31 2025 - [info] Oldest slaves:
Mon Aug  4 21:52:31 2025 - [info]   172.25.254.20(172.25.254.20:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 21:52:31 2025 - [info]     GTID ON
Mon Aug  4 21:52:31 2025 - [info]     Replicating from 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:52:31 2025 - [info]     Primary candidate for the new Master (candidate_master is set)
Mon Aug  4 21:52:31 2025 - [info]   172.25.254.30(172.25.254.30:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 21:52:31 2025 - [info]     GTID ON
Mon Aug  4 21:52:31 2025 - [info]     Replicating from 172.25.254.10(172.25.254.10:3306)
Mon Aug  4 21:52:31 2025 - [info]     Not candidate for the new Master (no_master is set)
Mon Aug  4 21:52:31 2025 - [info] 
Mon Aug  4 21:52:31 2025 - [info] * Phase 3.3: Determining New Master Phase..
Mon Aug  4 21:52:31 2025 - [info] 
Mon Aug  4 21:52:31 2025 - [info] 172.25.254.20 can be new master.
Mon Aug  4 21:52:31 2025 - [info] New master is 172.25.254.20(172.25.254.20:3306)
Mon Aug  4 21:52:31 2025 - [info] Starting master failover..
Mon Aug  4 21:52:31 2025 - [info] 
From:
172.25.254.10(172.25.254.10:3306) (current master)+--172.25.254.20(172.25.254.20:3306)+--172.25.254.30(172.25.254.30:3306)To:
172.25.254.20(172.25.254.20:3306) (new master)+--172.25.254.30(172.25.254.30:3306)Starting master switch from 172.25.254.10(172.25.254.10:3306) to 172.25.254.20(172.25.254.20:3306)? (yes/NO): yes
Mon Aug  4 21:52:33 2025 - [info] New master decided manually is 172.25.254.20(172.25.254.20:3306)
Mon Aug  4 21:52:33 2025 - [info] 
Mon Aug  4 21:52:33 2025 - [info] * Phase 3.3: New Master Recovery Phase..
Mon Aug  4 21:52:33 2025 - [info] 
Mon Aug  4 21:52:33 2025 - [info]  Waiting all logs to be applied.. 
Mon Aug  4 21:52:33 2025 - [info]   done.
Mon Aug  4 21:52:33 2025 - [info] Getting new master's binlog name and position..
Mon Aug  4 21:52:33 2025 - [info]  binlog.000002:2514
Mon Aug  4 21:52:33 2025 - [info]  All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='172.25.254.20', MASTER_PORT=3306, MASTER_AUTO_POSITION=1, MASTER_USER='repl_rin', MASTER_PASSWORD='xxx';
Mon Aug  4 21:52:33 2025 - [info] Master Recovery succeeded. File:Pos:Exec_Gtid_Set: binlog.000002, 2514, 506a67d6-7129-11f0-8460-000c29b1341f:1-8,
528ca525-7129-11f0-8ea4-000c2923893f:1
Mon Aug  4 21:52:33 2025 - [warning] master_ip_failover_script is not set. Skipping taking over new master IP address.
Mon Aug  4 21:52:33 2025 - [info] Setting read_only=0 on 172.25.254.20(172.25.254.20:3306)..
Mon Aug  4 21:52:33 2025 - [info]  ok.
Mon Aug  4 21:52:33 2025 - [info] ** Finished master recovery successfully.
Mon Aug  4 21:52:33 2025 - [info] * Phase 3: Master Recovery Phase completed.
Mon Aug  4 21:52:33 2025 - [info] 
Mon Aug  4 21:52:33 2025 - [info] * Phase 4: Slaves Recovery Phase..
Mon Aug  4 21:52:33 2025 - [info] 
Mon Aug  4 21:52:33 2025 - [info] 
Mon Aug  4 21:52:33 2025 - [info] * Phase 4.1: Starting Slaves in parallel..
Mon Aug  4 21:52:33 2025 - [info] 
Mon Aug  4 21:52:33 2025 - [info] -- Slave recovery on host 172.25.254.30(172.25.254.30:3306) started, pid: 4645. Check tmp log /var/log/masterha/app1/172.25.254.30_3306_20250804215225.log if it takes time..
Mon Aug  4 21:52:34 2025 - [info] 
Mon Aug  4 21:52:34 2025 - [info] Log messages from 172.25.254.30 ...
Mon Aug  4 21:52:35 2025 - [info] 
Mon Aug  4 21:52:33 2025 - [info]  Resetting slave 172.25.254.30(172.25.254.30:3306) and starting replication from the new master 172.25.254.20(172.25.254.20:3306)..
Mon Aug  4 21:52:34 2025 - [info]  Executed CHANGE MASTER.
Mon Aug  4 21:52:34 2025 - [info]  Slave started.
Mon Aug  4 21:52:34 2025 - [info]  gtid_wait(506a67d6-7129-11f0-8460-000c29b1341f:1-8,
528ca525-7129-11f0-8ea4-000c2923893f:1) completed on 172.25.254.30(172.25.254.30:3306). Executed 0 events.
Mon Aug  4 21:52:35 2025 - [info] End of log messages from 172.25.254.30.
Mon Aug  4 21:52:35 2025 - [info] -- Slave on host 172.25.254.30(172.25.254.30:3306) started.
Mon Aug  4 21:52:35 2025 - [info] All new slave servers recovered successfully.
Mon Aug  4 21:52:35 2025 - [info] 
Mon Aug  4 21:52:35 2025 - [info] * Phase 5: New master cleanup phase..
Mon Aug  4 21:52:35 2025 - [info] 
Mon Aug  4 21:52:35 2025 - [info] Resetting slave info on the new master..
Mon Aug  4 21:52:35 2025 - [info]  172.25.254.20: Resetting slave info succeeded.
Mon Aug  4 21:52:35 2025 - [info] Master failover to 172.25.254.20(172.25.254.20:3306) completed successfully.
Mon Aug  4 21:52:35 2025 - [info] ----- Failover Report -----app1: MySQL Master failover 172.25.254.10(172.25.254.10:3306) to 172.25.254.20(172.25.254.20:3306) succeededMaster 172.25.254.10(172.25.254.10:3306) is down!Check MHA Manager logs at MHA.rin.com for details.Started manual(interactive) failover.
Selected 172.25.254.20(172.25.254.20:3306) as a new master.
172.25.254.20(172.25.254.20:3306): OK: Applying all logs succeeded.
172.25.254.30(172.25.254.30:3306): OK: Slave started, replicating from 172.25.254.20(172.25.254.20:3306)
172.25.254.20(172.25.254.20:3306): Resetting slave info succeeded.
Master failover to 172.25.254.20(172.25.254.20:3306) completed successfully.

恢复故障:
将10节点启用:

/etc/init.d/mysqld start

将10节点启用后,当前集群内有两个主库master,所有我们对于当前重新启用的10节点,应该指定其所属的主库20,更改master信息:

CHANGE MASTER TO MASTER_HOST='172.25.254.20', MASTER_USER='repl_rin', MASTER_PASSWORD='rin', MASTER_AUTO_POSITION=1;

启用从库复制进程:

START SLAVE;

从库10从库状态:

show slave status\G;
mysql> show slave status\G;
*************************** 1. row ***************************Slave_IO_State: Waiting for source to send eventMaster_Host: 172.25.254.20Master_User: repl_rinMaster_Port: 3306Connect_Retry: 60Master_Log_File: binlog.000002Read_Master_Log_Pos: 2514Relay_Log_File: mysql-a-relay-bin.000002Relay_Log_Pos: 411Relay_Master_Log_File: binlog.000002Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 2514Relay_Log_Space: 623Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_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: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 20Master_UUID: 528ca525-7129-11f0-8ea4-000c2923893fMaster_Info_File: mysql.slave_master_infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Replica has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: 506a67d6-7129-11f0-8460-000c29b1341f:1-8,
528ca525-7129-11f0-8ea4-000c2923893f:1Auto_Position: 1Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: Master_public_key_path: Get_master_public_key: 0Network_Namespace: 
1 row in set, 1 warning (0.00 sec)ERROR: 
No query specified

在MHA上检测集群状况:

masterha_check_repl --conf=/etc/masterha/app1.cnf

 集群状况为20为主库,10、30为从库,状况良好。

[root@MHA ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf
Mon Aug  4 22:11:40 2025 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Aug  4 22:11:40 2025 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Mon Aug  4 22:11:40 2025 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Mon Aug  4 22:11:40 2025 - [info] MHA::MasterMonitor version 0.58.
Mon Aug  4 22:11:41 2025 - [info] GTID failover mode = 1
Mon Aug  4 22:11:41 2025 - [info] Dead Servers:
Mon Aug  4 22:11:41 2025 - [info] Alive Servers:
Mon Aug  4 22:11:41 2025 - [info]   172.25.254.10(172.25.254.10:3306)
Mon Aug  4 22:11:41 2025 - [info]   172.25.254.20(172.25.254.20:3306)
Mon Aug  4 22:11:41 2025 - [info]   172.25.254.30(172.25.254.30:3306)
Mon Aug  4 22:11:41 2025 - [info] Alive Slaves:
Mon Aug  4 22:11:41 2025 - [info]   172.25.254.10(172.25.254.10:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 22:11:41 2025 - [info]     GTID ON
Mon Aug  4 22:11:41 2025 - [info]     Replicating from 172.25.254.20(172.25.254.20:3306)
Mon Aug  4 22:11:41 2025 - [info]     Primary candidate for the new Master (candidate_master is set)
Mon Aug  4 22:11:41 2025 - [info]   172.25.254.30(172.25.254.30:3306)  Version=8.0.40 (oldest major version between slaves) log-bin:enabled
Mon Aug  4 22:11:41 2025 - [info]     GTID ON
Mon Aug  4 22:11:41 2025 - [info]     Replicating from 172.25.254.20(172.25.254.20:3306)
Mon Aug  4 22:11:41 2025 - [info]     Not candidate for the new Master (no_master is set)
Mon Aug  4 22:11:41 2025 - [info] Current Alive Master: 172.25.254.20(172.25.254.20:3306)
Mon Aug  4 22:11:41 2025 - [info] Checking slave configurations..
Mon Aug  4 22:11:41 2025 - [info]  read_only=1 is not set on slave 172.25.254.10(172.25.254.10:3306).
Mon Aug  4 22:11:41 2025 - [info]  read_only=1 is not set on slave 172.25.254.30(172.25.254.30:3306).
Mon Aug  4 22:11:41 2025 - [info] Checking replication filtering settings..
Mon Aug  4 22:11:41 2025 - [info]  binlog_do_db= , binlog_ignore_db= 
Mon Aug  4 22:11:41 2025 - [info]  Replication filtering check ok.
Mon Aug  4 22:11:41 2025 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Mon Aug  4 22:11:41 2025 - [info] Checking SSH publickey authentication settings on the current master..
Mon Aug  4 22:11:41 2025 - [info] HealthCheck: SSH to 172.25.254.20 is reachable.
Mon Aug  4 22:11:41 2025 - [info] 
172.25.254.20(172.25.254.20:3306) (current master)+--172.25.254.10(172.25.254.10:3306)+--172.25.254.30(172.25.254.30:3306)Mon Aug  4 22:11:41 2025 - [info] Checking replication health on 172.25.254.10..
Mon Aug  4 22:11:41 2025 - [info]  ok.
Mon Aug  4 22:11:41 2025 - [info] Checking replication health on 172.25.254.30..
Mon Aug  4 22:11:41 2025 - [info]  ok.
Mon Aug  4 22:11:41 2025 - [warning] master_ip_failover_script is not defined.
Mon Aug  4 22:11:41 2025 - [warning] shutdown_script is not defined.
Mon Aug  4 22:11:41 2025 - [info] Got exit code 0 (Not master dead).MySQL Replication Health is OK.


8.MySQL组复制:

准备工作:

停止10-30的mysql:

/etc/init.d/mysqld stop

编辑dns:

vim /etc/hosts
172.25.254.10    mysql-a.rin.com
172.25.254.20    mysql-b.rin.com
172.25.254.30    mysql-c.rin.com

rm -rf /data/mysql/*
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
server-id=10
default_authentication_plugin=mysql_native_password
disabled_storage_engines="MyISAM,BLACKHOLE,FEDERATED,ARCHIVE,MEMORY"
gtid_mode=ON
enforce_gtid_consistency=ON
binlog_checksum=NONE
log_slave_updates=ON
log_bin=binlog
binlog_format=ROW
transaction_write_set_extraction=XXHASH64

接着进行初始化:

初始化完成后再编辑文件my.cnf,添加参数:

vim /etc/my.cnf
plugin_load_add='group_replication.so'group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
group_replication_start_on_boot=off
group_replication_local_address="172.25.254.10:33061"
group_replication_group_seeds="172.25.254.10:33061,172.25.254.20:33061,172.25.254.30:33061"
group_replication_ip_whitelist="172.25.254.0/24,127.0.0.1/8"
group_replication_bootstrap_group=off
group_replication_single_primary_mode=OFF

http://www.dtcms.com/a/411195.html

相关文章:

  • 有服务器了怎么做网站三星网上商城分期
  • 交付场景下的 iOS 混淆实战,无源码部分源码如何做成品加固、供应链验证与交付治理
  • 中国菲律宾商会网站seo优化免费
  • CS课程项目设计18:基于Insightface人脸识别库的课堂签到系统
  • 收录网站的二级域名郑州又上热搜了
  • 济南企业型网站深圳定制网站制作
  • 【2025】Mixxx 2.5.1安装教程保姆级一键安装教程(附安装包)
  • 算法学习之 二分
  • Carboxyrhodamine 110 Alk,羧基罗丹明110-炔基在点击化学的应用
  • 日记 - 2025.9.26 读研日记(二)
  • 做网站数据库表设计优化大师win7官方免费下载
  • 中建建设银行网站电子邮箱
  • display ip routing-table 概念及题目
  • spring 第三级缓存singletonFactories的作用及@Async造成循环依赖报错原因分析
  • 什么是静态IP?静态IP和动态IP的对比
  • IP子网掩码的计算
  • 济南富新网站建设福州服务类网站建设
  • 网站设置快捷方式到桌面找大学生做家教的网站
  • 手机提词器APP对比测评
  • 【不背八股】18.GPT1:GPT系列的初代目
  • 体系化能力
  • 小谈:AR/VR(增强/虚拟现实)技术
  • 服务器建网站seo外链推广平台
  • Android studio图像视图和相对布局知识点
  • 网站备案主体空壳上不了国外网站 怎么做贸易
  • 适合设计制作公司的网站asp远吗宁波网站建设培训学校
  • 【AI论文】Qwen3-Omni技术报告
  • 门业网站 源码杭州亚运会闭幕式
  • 中裕隆建设有限公司网站考研资料找微信hyhyk1推广可以
  • LeetCode 3132.找出与数组相加的整数 II