Rocky8+MHA搭建

1、MHA 是什么

1.1、MHA概念

  1. MHA(MasterHigh Availability)是一套比较成熟的 MySQL 高可用方案,也是一款优秀的故障切换和主从提升的高可用软件。

  2. MHA 主要是为了解决MySQL 单点的问题。

  3. MySQL故障切换过程中,MHA能做到0-30秒内自动完成故障切换操作。

  4. MHA能在故障切换的过程中最大程度上保证数据的一致性,以达到真正意义上的高可用。

  5. MHA还支持在线快速将Master切换到其他主机,通常只需0.5-2秒。

1.2、MHA 组成

  1. MHA Manager
    MHA Manager 单独部署在一台独立的机器上,管理多个 master-slave 集群,也可以部署在一台 slave 节点上。
    MHA Manager 会定时探测集群中的 master 节点。当 master 出现故障时,它可以自动将最新数据的 slave 提升为新的 master, 然后将所有其他的 slave 重新指向新的 master。整个故障转移过程对应用程序完全透明。

  2. MHA Node
    MHA Node 运行在每台 MySQL 服务器上

1.3、MHA特点

  1. 自动故障切换过程中,MHA试图从宕机的主服务器上保存二进制日志,最大程度的保证数据不丢失

  2. 使用半同步复制,可以大大降低数据丢失的风险,如果只有一个slave已经收到了最新的二进制日志,MHA可以将最新的二进制日志应用于其他所有的slave服务器上,因此可以保证所有节点的数据一致性

  3. 目前MHA支持一主多从架构,最少三台服务,即一主两从

2、MHA架构

2.1、MHA架构设计

Rocky8+MHA搭建

2.2、MHA准备工作

注意:MHA-manager 不适合centos8以上的版本,rocky8其实和centos8是同源的。

节点 主机名称 描述 系统
192.168.1.1 MHA-manager MHA管理节点 centos7
192.168.1.2 mysql8-01 master1 rocky8
192.168.1.3 mysql8-02 slave1 rocky8
192.168.1.4 mysql8-03 slave2 rocky8
192.168.1.5 mysql8-04 slave3 rocky8

2.3、服务器基础配置

2.3.1、hosts配置

$ vim /etc/hosts
192.168.1.1 mha-manager
192.168.1.2 mysql8-01
192.168.1.3 mysql8-02
192.168.1.4 mysql8-03
192.168.1.5 mysql8-04

2.3.2、修改主机名

## 192.168.1.1 执行
$ hostnamectl set-hostname mha-manager
## 192.168.1.2 执行
$ hostnamectl set-hostname mysql8-01
## 192.168.1.3 执行
$ hostnamectl set-hostname mysql8-02
## 192.168.1.4 执行
$ hostnamectl set-hostname mysql8-03
## 192.168.1.5 执行
$ hostnamectl set-hostname mysql8-04

2.3.3、配置防火墙

所有服务器 执行

$ firewall-cmd --zone=public --add-port=3306/tcp --permanent
$ firewall-cmd --reload
$ firewall-cmd --zone=public --list-ports

2.3.4、更新所有服务器

yum update -y

2.3.5、所有服务器相互授权

## 所有服务器 执行
$ ssh-keygen
## 192.168.1.1 执行
$ for i in 2 3 4 5;do ssh-copy-id root@192.168.1.$i;done
## 192.168.1.2 执行
$ for i in 1 3 4 5;do ssh-copy-id root@192.168.1.$i;done
## 192.168.1.3 执行
$ for i in 1 2 4 5;do ssh-copy-id root@192.168.1.$i;done
## 192.168.1.4 执行
$ for i in 1 2 3 5;do ssh-copy-id root@192.168.1.$i;done
## 192.168.1.5 执行
$ for i in 1 2 3 4;do ssh-copy-id root@192.168.1.$i;done

测试:

$ for i in {mha-manager,mysql8-01,mysql8-02,mysql8-03,mysql8-04}; do ping -c 1 $i; done

3、mysql8安装

3.1、卸载旧mysql

$ rpm -qa | grep mysql
mysql-common-8.0.32-1.module+el8.8.0+1283+4b88a3a8.0.1.x86_64
mysql-server-8.0.32-1.module+el8.8.0+1283+4b88a3a8.0.1.x86_64
mysql-errmsg-8.0.32-1.module+el8.8.0+1283+4b88a3a8.0.1.x86_64
mha4mysql-node-0.58-0.el7.centos.noarch
mysql-8.0.32-1.module+el8.8.0+1283+4b88a3a8.0.1.x86_64

$ yum remove XXX

## 删除查到所有的文件
$ find / -name mysql
$ rm -rf XXX

3.2、安装mysql8

$ dnf module list mysql
$ dnf module enable mysql:8.0
$ dnf install @mysql

3.3、my.cnf配置文件

3.3.1、master 节点

[mysqld]
datadir=/home/mysql/data
socket=/home/mysql/data/mysql.sock
mysqlx_socket=/home/mysql/data/mysqlx.sock
log-error=/home/mysql/logs/mysqld.log
pid-file=/run/mysqld/mysqld.pid


default_storage_engine = InnoDB
performance_schema_max_table_instances = 12500
table_open_cache = 2000
table_definition_cache = 1400



key_buffer_size = 256M
max_allowed_packet = 1G
sort_buffer_size = 1M
net_buffer_length = 16K
read_buffer_size = 1M
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 32M
thread_cache_size = 32
tmp_table_size = 64M
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO

explicit_defaults_for_timestamp = true
max_connections = 5000
max_connect_errors = 1000
open_files_limit = 65535


innodb_data_home_dir = /home/mysql/data
innodb_data_file_path = ibdata1:12M:autoextend
innodb_log_group_home_dir = /home/mysql/data
innodb_buffer_pool_size = 4G
innodb_redo_log_capacity=500M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 8
innodb_write_io_threads = 8


### 主从
log-bin=mysql-bin
binlog_format=row
server-id = 1
### 开启gtid模式
gtid_mode=on
### 强制gtid一致性,开启后对于特定create table不被支持
enforce_gtid_consistency=on
### 使从库可以变成其他从库的主库的参数
log_replica_updates=true
### 开启中继日志
relay-log=/home/mysql/data/relaylog/slave-relay-bin
### 切换后数据补齐
relay_log_purge=0
### 当slave从库宕机后,假如relay-log损坏了,导致一部分中继日志没有处理,则自动放弃所有未执行的relay-log,并且重新从master上获取日志,这样就保证了relay-log的完整性。默认情况下该功能是关闭的,将relay_log_recovery的值设置为 1(ON)时,可在slave从库上开启该功能,建议开启。
relay_log_recovery=ON
### 当设置为1时,slave的I/O线程每次接收到master发送过来的binlog日志都要写入系统缓冲区,然后刷入relay log中继日志里,这样是最安全的,因为在崩溃的时候,你最多会丢失一个事务,但会造成磁盘的大量I/O
sync_relay_log=1
### 半同步复制
plugin-load = "rpl_semi_sync_source=semisync_source.so;rpl_semi_sync_replica=semisync_replica.so"
### master
rpl_semi_sync_source_enabled=1
### slave
rpl_semi_sync_replica_enabled=1
### 0:可读可写 1:只读
read_only=0
### 日志达到500M时自动分割
max_binlog_size = 1G
### 日志保存15天
binlog_expire_logs_seconds=30


### 慢查询日志
slow_query_log=1
slow-query-log-file=/home/mysql/logs/mysql-slow.log
long_query_time=5

3.3.2、slave 节点

[mysqld]
datadir=/home/mysql/data
socket=/home/mysql/data/mysql.sock
mysqlx_socket=/home/mysql/data/mysqlx.sock
log-error=/home/mysql/logs/mysqld.log
pid-file=/run/mysqld/mysqld.pid

default_storage_engine = InnoDB
performance_schema_max_table_instances = 12500
table_open_cache = 2000
table_definition_cache = 1400

key_buffer_size = 256M
max_allowed_packet = 1G
sort_buffer_size = 1M
net_buffer_length = 16K
read_buffer_size = 1M
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 32M
thread_cache_size = 32
tmp_table_size = 64M
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO

explicit_defaults_for_timestamp = true
max_connections = 5000
max_connect_errors = 1000
open_files_limit = 65535


innodb_data_home_dir = /home/mysql/data
innodb_data_file_path = ibdata1:12M:autoextend
innodb_log_group_home_dir = /home/mysql/data
innodb_buffer_pool_size = 4G
innodb_redo_log_capacity=500M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 8
innodb_write_io_threads = 8


### 主从
log-bin=mysql-bin
binlog_format=row
### 每个节点数值不允许一样
server-id = 2
### 开启gtid模式
gtid_mode=on
### 强制gtid一致性,开启后对于特定create table不被支持
enforce_gtid_consistency=on

### 使从库可以变成其他从库的主库的参数
log_replica_updates=true
### 开启中继日志
relay-log=/home/mysql/data/relaylog/slave-relay-bin
### 切换后数据补齐
relay_log_purge=0
### 当slave从库宕机后,假如relay-log损坏了,导致一部分中继日志没有处理,则自动放弃所有未执行的relay-log,并且重新从master上获取日志,这样就保证了relay-log的完整性。默认情况下该功能是关闭的,将relay_log_recovery的值设置为 1(ON)时,可在slave从库上开启该功能,建议开启。
relay_log_recovery=ON
### 当设置为1时,slave的I/O线程每次接收到master发送过来的binlog日志都要写入系统缓冲区,然后刷入relay log中继日志里,这样是最安全的,因为在崩溃的时候,你最多会丢失一个事务,但会造成磁盘的大量I/O
sync_relay_log=1
### 半同步复制
plugin-load = "rpl_semi_sync_source=semisync_source.so;rpl_semi_sync_replica=semisync_replica.so"
### master
rpl_semi_sync_source_enabled=1
### slave
rpl_semi_sync_replica_enabled=1
### 0:可读可写 1:只读
read_only=0
### 日志达到500M时自动分割
max_binlog_size = 1G
### 日志保存15天
binlog_expire_logs_seconds=30


### 慢查询日志
slow_query_log=1
slow-query-log-file=/home/mysql/logs/mysql-slow.log
long_query_time=5

3.4、文件夹权限

chown -R mysql:mysql   /home/mysql

3.5、数据库启动

$ systemctl start mysqld.service
$ systemctl status mysqld.service
$ systemctl restart mysqld.service
$ systemctl stop mysqld.service

3.6、配置数据库账户密码

## 无密码进入
$ systemctl stop mysqld.service
$ mysqld_safe --skip-grant-tables &
$ mysql -u root
mysql> create user mha@'%' identified by '密码';
mysql> grant all on *.* to mha@'%';
mysql> create user slave@'%' identified by '密码';
mysql> grant replication on *.* to slave@'%';
mysql> alter user 'root'@'%'IDENTIFIED BY '密码';
mysql> FLUSH PRIVILEGES;

3.7、数据库主从

192.168.1.2执行

mysql> show master status;
+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------+
| mysql-bin.000006 | 197 | | | 34a0dfa7-b10b-11ee-8515-005056a70c72:1-11,
5f7b1ae2-2588-7a9c-7255-861adc42d124:2-987 |
+------------------+----------+--------------+------------------+---------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql>

192.168.1.3/5执行

mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.1.2',
-> MASTER_USER='slave',
-> MASTER_PASSWORD='密码',
-> MASTER_LOG_FILE='mysql-bin.000001',
-> MASTER_LOG_POS=324;

查看主从状态

mysql> show slave statusG
*************************** 1. row ***************************
Slave_IO_State: Waiting for source to send event
Master_Host: 192.168.1.2
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000006
Read_Master_Log_Pos: 197
Relay_Log_File: slave-relay-bin.000015
Relay_Log_Pos: 373
Relay_Master_Log_File: mysql-bin.000006
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: 197
Relay_Log_Space: 5897977124
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: 5F7B1AE2-2588-7A9C-7255-861ADC42D124
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Replica 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: 34a0dfa7-b10b-11ee-8515-005056a70c72:1-11,
5f7b1ae2-2588-7a9c-7255-861adc42d124:2-987
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.00 sec)

4、MHA 搭建

4.1、在mha-manager执行

$ 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

上传MHA 安装包

$ ll
-rw-r--r--. 1 root root 81024 113 04:48 mha4mysql-manager-0.58-0.el7.centos.noarch.rpm
-rw-r--r--. 1 root root 36328 113 04:50 mha4mysql-node-0.58-0.el7.centos.noarch.rpm

$ yum install -y mha4mysql-manager-0.58-0.el7.centos.noarch.rpm
$ yum install -y mha4mysql-node-0.58-0.el7.centos.noarch.rpm
$ scp mha4mysql-node-0.58-0.el7.centos.noarch.rpm root@192.168.1.2:/home/rpm/
$ scp mha4mysql-node-0.58-0.el7.centos.noarch.rpm root@192.168.1.3:/home/rpm/
$ scp mha4mysql-node-0.58-0.el7.centos.noarch.rpm root@192.168.1.4:/home/rpm/
$ scp mha4mysql-node-0.58-0.el7.centos.noarch.rpm root@192.168.1.5:/home/rpm/

4.2、在其他所有节点执行

$ ll
-rw-r--r--. 1 root root 81024 113 04:48 mha4mysql-manager-0.58-0.el7.centos.noarch.rpm
-rw-r--r--. 1 root root 36328 113 04:50 mha4mysql-node-0.58-0.el7.centos.noarch.rpm

$ yum install -y mha4mysql-node-0.58-0.el7.centos.noarch.rpm

4.3、在mha-manager节点配置

$ vim /home/mhamaster/app1.cnf

app1.cnf 配置文件

[server default]
user=mha
password=mha_wms@2024.com

manager_workdir=/home/mhamaster/app1/
manager_log=/home/mhamaster/app1/manager.log
remote_workdir=/home/mhamaster/app1/

ssh_user=root
repl_user=slave
repl_password=slave_wms@2024.com

ping_interval=1
master_ip_failover_script=/usr/local/bin/master_ip_failover
report_script=/usr/local/bin/sendmail.sh
# 指定用于二次检查节点状态的脚本
secondary_check_script=/usr/bin/masterha_secondary_check -s mysql8-01 -s mysql8-02 -s mysql8-03 -s mysql8-04
check_repl_delay=0
master_binlog_dir=/home/mysql/data/
[server1]
hostname=mysql8-01
candidate_master=1
[server2]
hostname=mysql8-02
candidate_master=1
[server3]
hostname=mysql8-03
[server4]
hostname=mysql8-04

4.4 VIP

/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.1.6/16';
my $gateway = '192.168.1.31';
my $interface = 'ens33';
my $key = "1";
my $ssh_start_vip = "/sbin/ifconfig $interface:$key $vip;/sbin/arping -I $interface -c 3 -s $vip $gateway >/dev/null 2>&1";
my $ssh_stop_vip = "/sbin/ifconfig $interface:$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 "nnIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===nn";
if ( $command eq "stop" || $command eq "stopssh" ) {
# $orig_master_host, $orig_master_ip, $orig_master_port are passed.
# If you manage master ip address at global catalog database,
# invalidate orig_master_ip here.
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" ) {
# all arguments are passed.
# If you manage master ip address at global catalog database,
# activate new_master_ip here.
# You can also grant write access (create user, set read_only=0, etc) here.
my $exit_code = 10;
eval {
print "Enabling the VIP - $vip on the new master - $new_master_host n";
&start_vip();
$exit_code = 0;
};
if ($@) {
warn $@;
exit $exit_code;
}
exit $exit_code;
}
elsif ( $command eq "status" ) {
print "Checking the Status of the script.. OK n";
`ssh $ssh_user@$orig_master_host " $ssh_start_vip "`;
exit 0;
}
else {
&usage();
exit 1;
}
}
# A simple system call that enable the VIP on the new master
sub start_vip() {
`ssh $ssh_user@$new_master_host " $ssh_start_vip "`;
}
# A simple system call that disable the VIP on the old_master
sub stop_vip() {
`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=portn";
}

在mysql主节点执行

ifconfig ens33:1 192.168.1.6/16

4.5、启动测试

## 查看ssh互信
$ masterha_check_ssh --conf=/home/mhamaster/app1.cnf
Mon Feb 5 11:18:05 2024 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Feb 5 11:18:05 2024 - [info] Reading application default configuration from /home/mhamaster/app1.cnf..
Mon Feb 5 11:18:05 2024 - [info] Reading server configuration from /home/mhamaster/app1.cnf..
Mon Feb 5 11:18:05 2024 - [info] Starting SSH connection tests..
Mon Feb 5 11:18:07 2024 - [debug]
Mon Feb 5 11:18:05 2024 - [debug] Connecting via SSH from root@mysql8-02(192.168.1.3:22) to root@mysql8-01(192.168.1.2:22)..
Mon Feb 5 11:18:06 2024 - [debug] ok.
Mon Feb 5 11:18:06 2024 - [debug] Connecting via SSH from root@mysql8-02(192.168.1.3:22) to root@mysql8-03(192.168.1.4:22)..
Mon Feb 5 11:18:06 2024 - [debug] ok.
Mon Feb 5 11:18:06 2024 - [debug] Connecting via SSH from root@mysql8-02(192.168.1.3:22) to root@mysql8-04(192.168.1.5:22)..
Mon Feb 5 11:18:07 2024 - [debug] ok.
Mon Feb 5 11:18:07 2024 - [debug]
Mon Feb 5 11:18:05 2024 - [debug] Connecting via SSH from root@mysql8-01(192.168.1.2:22) to root@mysql8-02(192.168.1.3:22)..
Mon Feb 5 11:18:05 2024 - [debug] ok.
Mon Feb 5 11:18:05 2024 - [debug] Connecting via SSH from root@mysql8-01(192.168.1.2:22) to root@mysql8-03(192.168.1.4:22)..
Mon Feb 5 11:18:06 2024 - [debug] ok.
Mon Feb 5 11:18:06 2024 - [debug] Connecting via SSH from root@mysql8-01(192.168.1.2:22) to root@mysql8-04(192.168.1.5:22)..
Mon Feb 5 11:18:06 2024 - [debug] ok.
Mon Feb 5 11:18:08 2024 - [debug]
Mon Feb 5 11:18:06 2024 - [debug] Connecting via SSH from root@mysql8-03(192.168.1.4:22) to root@mysql8-01(192.168.1.2:22)..
Mon Feb 5 11:18:06 2024 - [debug] ok.
Mon Feb 5 11:18:06 2024 - [debug] Connecting via SSH from root@mysql8-03(192.168.1.4:22) to root@mysql8-02(192.168.1.3:22)..
Mon Feb 5 11:18:07 2024 - [debug] ok.
Mon Feb 5 11:18:07 2024 - [debug] Connecting via SSH from root@mysql8-03(192.168.1.4:22) to root@mysql8-04(192.168.1.5:22)..
Mon Feb 5 11:18:07 2024 - [debug] ok.
Mon Feb 5 11:18:09 2024 - [debug]
Mon Feb 5 11:18:06 2024 - [debug] Connecting via SSH from root@mysql8-04(192.168.1.5:22) to root@mysql8-01(192.168.1.2:22)..
Mon Feb 5 11:18:07 2024 - [debug] ok.
Mon Feb 5 11:18:07 2024 - [debug] Connecting via SSH from root@mysql8-04(192.168.1.5:22) to root@mysql8-02(192.168.1.3:22)..
Mon Feb 5 11:18:07 2024 - [debug] ok.
Mon Feb 5 11:18:07 2024 - [debug] Connecting via SSH from root@mysql8-04(192.168.1.5:22) to root@mysql8-03(192.168.1.4:22)..
Mon Feb 5 11:18:08 2024 - [debug] ok.
Mon Feb 5 11:18:09 2024 - [info] All SSH connection tests passed successfully.

## 查看主从状态
$ masterha_check_repl --conf=/home/mhamaster/app1.cnf
Mon Feb 5 11:18:20 2024 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Feb 5 11:18:20 2024 - [info] Reading application default configuration from /home/mhamaster/app1.cnf..
Mon Feb 5 11:18:20 2024 - [info] Reading server configuration from /home/mhamaster/app1.cnf..
Mon Feb 5 11:18:20 2024 - [info] MHA::MasterMonitor version 0.58.
Mon Feb 5 11:18:21 2024 - [info] GTID failover mode = 1
Mon Feb 5 11:18:21 2024 - [info] Dead Servers:
Mon Feb 5 11:18:21 2024 - [info] Alive Servers:
Mon Feb 5 11:18:21 2024 - [info] mysql8-01(192.168.1.2:3306)
Mon Feb 5 11:18:21 2024 - [info] mysql8-02(192.168.1.3:3306)
Mon Feb 5 11:18:21 2024 - [info] mysql8-03(192.168.1.4:3306)
Mon Feb 5 11:18:21 2024 - [info] mysql8-04(192.168.1.5:3306)
Mon Feb 5 11:18:21 2024 - [info] Alive Slaves:
Mon Feb 5 11:18:21 2024 - [info] mysql8-02(192.168.1.3:3306) Version=8.0.32 (oldest major version between slaves) log-bin:enabled
Mon Feb 5 11:18:21 2024 - [info] GTID ON
Mon Feb 5 11:18:21 2024 - [info] Replicating from 192.168.1.2(192.168.1.2:3306)
Mon Feb 5 11:18:21 2024 - [info] Primary candidate for the new Master (candidate_master is set)
Mon Feb 5 11:18:21 2024 - [info] mysql8-03(192.168.1.4:3306) Version=8.0.32 (oldest major version between slaves) log-bin:enabled
Mon Feb 5 11:18:21 2024 - [info] GTID ON
Mon Feb 5 11:18:21 2024 - [info] Replicating from 192.168.1.2(192.168.1.2:3306)
Mon Feb 5 11:18:21 2024 - [info] mysql8-04(192.168.1.5:3306) Version=8.0.32 (oldest major version between slaves) log-bin:enabled
Mon Feb 5 11:18:21 2024 - [info] GTID ON
Mon Feb 5 11:18:21 2024 - [info] Replicating from 192.168.1.2(192.168.1.2:3306)
Mon Feb 5 11:18:21 2024 - [info] Current Alive Master: mysql8-01(192.168.1.2:3306)
Mon Feb 5 11:18:21 2024 - [info] Checking slave configurations..
Mon Feb 5 11:18:21 2024 - [info] read_only=1 is not set on slave mysql8-02(192.168.1.3:3306).
Mon Feb 5 11:18:21 2024 - [info] read_only=1 is not set on slave mysql8-03(192.168.1.4:3306).
Mon Feb 5 11:18:21 2024 - [info] read_only=1 is not set on slave mysql8-04(192.168.1.5:3306).
Mon Feb 5 11:18:21 2024 - [info] Checking replication filtering settings..
Mon Feb 5 11:18:21 2024 - [info] binlog_do_db= , binlog_ignore_db=
Mon Feb 5 11:18:21 2024 - [info] Replication filtering check ok.
Mon Feb 5 11:18:21 2024 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Mon Feb 5 11:18:21 2024 - [info] Checking SSH publickey authentication settings on the current master..
Mon Feb 5 11:18:21 2024 - [info] HealthCheck: SSH to mysql8-01 is reachable.
Mon Feb 5 11:18:21 2024 - [info]
mysql8-01(192.168.1.2:3306) (current master)
+--mysql8-02(192.168.1.3:3306)
+--mysql8-03(192.168.1.4:3306)
+--mysql8-04(192.168.1.5:3306)

Mon Feb 5 11:18:21 2024 - [info] Checking replication health on mysql8-02..
Mon Feb 5 11:18:21 2024 - [info] ok.
Mon Feb 5 11:18:21 2024 - [info] Checking replication health on mysql8-03..
Mon Feb 5 11:18:21 2024 - [info] ok.
Mon Feb 5 11:18:21 2024 - [info] Checking replication health on mysql8-04..
Mon Feb 5 11:18:21 2024 - [info] ok.
Mon Feb 5 11:18:21 2024 - [info] Checking master_ip_failover_script status:
Mon Feb 5 11:18:21 2024 - [info] /usr/local/bin/master_ip_failover --command=status --ssh_user=root --orig_master_host=mysql8-01 --orig_master_ip=192.168.1.2 --orig_master_port=3306


IN SCRIPT TEST====/sbin/ifconfig ens33:1 down==/sbin/ifconfig ens33:1 192.168.102.249/16;/sbin/arping -I ens33 -c 3 -s 192.168.102.249/16 192.168.102.31 >/dev/null 2>&1===

Checking the Status of the script.. OK
Mon Feb 5 11:18:21 2024 - [info] OK.
Mon Feb 5 11:18:21 2024 - [warning] shutdown_script is not defined.
Mon Feb 5 11:18:21 2024 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.


## 查看启动状态
$ masterha_check_status --conf=/home/mhamaster/app1.cnf
app1 is stopped(2:NOT_RUNNING).


## 启动
$ masterha_manager --conf=/home/mhamaster/app1.cnf &> /dev/null 2>&1 &

IN SCRIPT TEST====/sbin/ifconfig ens33:1 down==/sbin/ifconfig ens33:1 192.168.102.249/16;/sbin/arping -I ens33 -c 3 -s 192.168.102.249/16 192.168.102.31 >/dev/null 2>&1===

Checking the Status of the script.. OK
Mon Feb 5 11:14:14 2024 - [info] OK.
Mon Feb 5 11:14:14 2024 - [warning] shutdown_script is not defined.
Mon Feb 5 11:14:14 2024 - [info] Set master ping interval 1 seconds.
Mon Feb 5 11:14:14 2024 - [info] Set secondary check script: /usr/bin/masterha_secondary_check -s mysql8-01 -s mysql8-02 -s mysql8-03 -s mysql8-04
Mon Feb 5 11:14:14 2024 - [info] Starting ping health check on mysql8-01(192.168.1.2:3306)..
Mon Feb 5 11:14:14 2024 - [info] Ping(SELECT) succeeded, waiting until MySQL doesn't respond..
Mon Feb 5 11:19:09 2024 - [info] MHA::MasterMonitor version 0.58.
Mon Feb 5 11:19:10 2024 - [warning] /home/mhamaster/app1//app1.master_status.health already exists. You might have killed manager with SIGKILL(-9), may run two or more monitoring process for the same application, or use the same working directory. Check for details, and consider setting --workdir separately.
Mon Feb 5 11:19:11 2024 - [info] GTID failover mode = 1
Mon Feb 5 11:19:11 2024 - [info] Dead Servers:
Mon Feb 5 11:19:11 2024 - [info] Alive Servers:
Mon Feb 5 11:19:11 2024 - [info] mysql8-01(192.168.1.2:3306)
Mon Feb 5 11:19:11 2024 - [info] mysql8-02(192.168.1.3:3306)
Mon Feb 5 11:19:11 2024 - [info] mysql8-03(192.168.1.4:3306)
Mon Feb 5 11:19:11 2024 - [info] mysql8-04(192.168.1.5:3306)
Mon Feb 5 11:19:11 2024 - [info] Alive Slaves:
Mon Feb 5 11:19:11 2024 - [info] mysql8-02(192.168.1.3:3306) Version=8.0.32 (oldest major version between slaves) log-bin:enabled
Mon Feb 5 11:19:11 2024 - [info] GTID ON
Mon Feb 5 11:19:11 2024 - [info] Replicating from 192.168.1.2(192.168.1.2:3306)
Mon Feb 5 11:19:11 2024 - [info] Primary candidate for the new Master (candidate_master is set)
Mon Feb 5 11:19:11 2024 - [info] mysql8-03(192.168.1.4:3306) Version=8.0.32 (oldest major version between slaves) log-bin:enabled
Mon Feb 5 11:19:11 2024 - [info] GTID ON
Mon Feb 5 11:19:11 2024 - [info] Replicating from 192.168.1.2(192.168.1.2:3306)
Mon Feb 5 11:19:11 2024 - [info] mysql8-04(192.168.1.5:3306) Version=8.0.32 (oldest major version between slaves) log-bin:enabled
Mon Feb 5 11:19:11 2024 - [info] GTID ON
Mon Feb 5 11:19:11 2024 - [info] Replicating from 192.168.1.2(192.168.1.2:3306)
Mon Feb 5 11:19:11 2024 - [info] Current Alive Master: mysql8-01(192.168.1.2:3306)
Mon Feb 5 11:19:11 2024 - [info] Checking slave configurations..
Mon Feb 5 11:19:11 2024 - [info] read_only=1 is not set on slave mysql8-02(192.168.1.3:3306).
Mon Feb 5 11:19:11 2024 - [info] read_only=1 is not set on slave mysql8-03(192.168.1.4:3306).
Mon Feb 5 11:19:11 2024 - [info] read_only=1 is not set on slave mysql8-04(192.168.1.5:3306).
Mon Feb 5 11:19:11 2024 - [info] Checking replication filtering settings..
Mon Feb 5 11:19:11 2024 - [info] binlog_do_db= , binlog_ignore_db=
Mon Feb 5 11:19:11 2024 - [info] Replication filtering check ok.
Mon Feb 5 11:19:11 2024 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Mon Feb 5 11:19:11 2024 - [info] Checking SSH publickey authentication settings on the current master..
Mon Feb 5 11:19:11 2024 - [info] HealthCheck: SSH to mysql8-01 is reachable.
Mon Feb 5 11:19:11 2024 - [info]
mysql8-01(192.168.1.2:3306) (current master)
+--mysql8-02(192.168.1.3:3306)
+--mysql8-03(192.168.1.4:3306)
+--mysql8-04(192.168.1.5:3306)

Mon Feb 5 11:19:11 2024 - [info] Checking master_ip_failover_script status:
Mon Feb 5 11:19:11 2024 - [info] /usr/local/bin/master_ip_failover --command=status --ssh_user=root --orig_master_host=mysql8-01 --orig_master_ip=192.168.1.1 --orig_master_port=3306


IN SCRIPT TEST====/sbin/ifconfig ens33:1 down==/sbin/ifconfig ens33:1 192.168.1.6/16;/sbin/arping -I ens33 -c 3 -s 192.168.1.6/16 192.168.1.31 >/dev/null 2>&1===

Checking the Status of the script.. OK
Mon Feb 5 11:19:11 2024 - [info] OK.
Mon Feb 5 11:19:11 2024 - [warning] shutdown_script is not defined.
Mon Feb 5 11:19:11 2024 - [info] Set master ping interval 1 seconds.
Mon Feb 5 11:19:11 2024 - [info] Set secondary check script: /usr/bin/masterha_secondary_check -s mysql8-01 -s mysql8-02 -s mysql8-03 -s mysql8-04
Mon Feb 5 11:19:11 2024 - [info] Starting ping health check on mysql8-01(192.168.1.1:3306)..
Mon Feb 5 11:19:11 2024 - [info] Ping(SELECT) succeeded, waiting until MySQL doesn'
t respond..

## 查看启动状态
$ masterha_check_status --conf=/home/mhamaster/app1.cnf
app1 (pid:29368) is running(0:PING_OK), master:mysql8-01


原文始发于微信公众号(猿圈搬砖日常):Rocky8+MHA搭建

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/223968.html

(0)
小半的头像小半

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!