Rocky之Mysql-MHA高可用
9、半同步复制
安装插件三种方法:
第一种:
mysql>INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so' 安装
在写入配置文件开启:
[root@master ~]#vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
rpl_semi_sync_master_enabled=ON
rpl_semi_sync_master_timeout=3000
第二种方法:
[root@master ~]#vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
loose-rpl_semi_sync_master_enabled=ON ## 仅报警
loose_rpl_semi_sync_master_timeout=3000
mysql>INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so' 安装
第三种:
[root@master ~]#vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
plugin-load-add = "semisync_salve.so" 开启服务自动加载插件
rpl_semi_sync_master_enabled=ON
# master:
[root@master ~]# mysql
mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';
[root@master ~]# vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
server-id=8
log-bin
rpl_semi_sync_master_enabled=ON
rpl_semi_sync_master_timeout=3000
[root@master ~]# systemctl restart mysqld.service
[root@master ~]# mysqldump -A -F --single-transaction --master-data=1 > /data/all.sql
[root@master ~]# scp /data/all.sql root@10.0.0.18:
[root@rocky8 ~]# scp /data/all.sql root@10.0.0.28:
[root@master ~]# mysql
mysql> show master logs;
+-------------------+-----------+-----------+
| Log_name | File_size | Encrypted |
+-------------------+-----------+-----------+
| rocky8-bin.000001 | 179 | No |
| rocky8-bin.000002 | 179 | No |
| rocky8-bin.000003 | 204 | No |
| rocky8-bin.000004 | 156 | No
mysql> create user repluser@'10.0.0.%' identified by '123456';
mysql> grant replication slave on *.* to repluser@'10.0.0.%';
mysql> show global variables like '%semi%';
# slave
[root@slave ~]# mysql
mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
CHANGE MASTER TO
MASTER_HOST='10.0.0.8',
MASTER_USER='repluser',
MASTER_PASSWORD='123456',
MASTER_PORT=3306,
MASTER_LOG_FILE='rocky8-bin.000004',
MASTER_LOG_POS=156,
MASTER_CONNECT_RETRY=10;
[root@slave ~]# vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
server-id=18
rpl_semi_sync_slave_enabled=ON
[root@slave ~]# systemctl restart mysqld.service
[root@slave ~]# mysql
mysql> show global variables like '%semi%';
mysql> show slave status\G #如果slave错误或者启动失败跳过错误或者重新写change master to
# slave2
[root@slave2 ~]# mysql
mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
[root@slave2 ~]# vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
server-id=18
rpl_semi_sync_slave_enabled=ON
[root@slave2 ~]# systemctl restart mysqld.service
[root@slave2 ~]# mysql
mysql> source /root/all.sql
mysql> show slave status\G
# 测试:
master 可以查看到2个客户端
mysql> show global status like '%semi%';
+--------------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients | 2
两个从服务器都停止后,主服务器更改内容后,等待3秒,自动提交成功。
10、复制过滤器
两种方法实现过滤:
第一种:master服务器选项写黑名单或者白名单:
[mysqld]
server-id=8
log-bin
rpl_semi_sync_master_enabled=ON
rpl_semi_sync_master_timeout=3000
binlog-ignore-db=db1 #黑名单:不同步db1库
重启服务即可
11、GTID复制
# master:#从库如果数据不一致,需要提前完全备份
[root@master ~]# vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
server-id=8
gtid_mode=ON
enforce_gtid_consistency
log-bin=/data/mysql/mysql-bin
[root@master ~]# mkdir /data/mysql
[root@master ~]# chown -R mysql.mysql /data/mysql
[root@master ~]# systemctl start mysqld.service
# slave:
[mysqld]
server-id=18
gtid_mode=ON
enforce_gtid_consistency
[root@slave ~]# systemctl start mysqld.service
CHANGE MASTER TO
MASTER_HOST='10.0.0.8',
MASTER_USER='repluser',
MASTER_PASSWORD='123456',
MASTER_PORT=3306,
MASTER_AUTO_POSITION=1;
mysql> start slave;
mysql> show slave status\G
12、利用 Mycat 实现 MySQL 的读写分离
所有主机的系统环境:
Mycat: 10.0.0.38 #内存建议2G以上(java需要大内存)
master: 10.0.0.8 MySQL 8.0
slave: 10.0.0.18 MySQL 8.0
关闭SELinux和防火墙、时间同步
主从和上边配置一样(从自动同步):
master:
mysql> create user wang@'10.0.0.%' identified by '123456';
mysql> grant all on *.* to wang@'10.0.0.%';
Mycat:
[root@mycat ~]# yum install -y java
[root@mycat ~]#mkdir /apps
[root@mycat ~]#tar xf Mycat-server-1.6.7.6-release-20220524173810-linux.tar.gz -C /apps/
[root@mycat ~]#cd /apps/
[root@mycat apps]#echo 'PATH=/apps/mycat/bin:$PATH' > /etc/profile.d/mycat.sh
[root@mycat apps]#. /etc/profile.d/mycat.sh
[root@mycat apps]#mycat start
Starting Mycat-server...
[root@mycat apps]#ss -ntl
现在可以测试连接:
客户机(要有mysql客户端):
[root@rocky8 ~]# mysql -uroot -p123456 -h10.0.0.38 -P8066
mysql> show databases;
+----------+
| DATABASE |
+----------+
| TESTDB |
+----------+
[root@mycat mycat]#vim conf/server.xml
<property name="serverPort">3306</property> #修改8066端口为3066,此行(45行)默认是注释的,可以复制到53行左右为注释的地方
用户名密码在最后方,有两块有用户名密码,一个库级别的一个表级别的。
[root@mycat mycat]#vim conf/schema.xml #仅对hellodb库进行了读写分离
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1">
</schema>
<dataNode name="dn1" dataHost="localhost1" database="hellodb" />
<dataHost name="localhost1" maxCon="1000" minCon="10" balance="1"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="host1" url="10.0.0.8:3306" user="wang" password="123456">
<readHost host="host2" url="10.0.0.18:3306" user="wang" password="123456" />
<readHost host="host3" url="10.0.0.28:3306" user="wang" password="123456" />
</writeHost>
</dataHost>
</mycat:schema>
# 客户机连接测试
[root@rocky8 ~]# mysql -uroot -p123456 -h10.0.0.38
mysql> select @@server_id; #可以看到server-id是28
+-------------+
| @@server_id |
+-------------+
| 28 |
+-------------+
1 row in set (0.11 sec)
mysql> select @@server_id; #可以看到server-id是18
+-------------+
| @@server_id |
+-------------+
| 18 |
+-------------+
## 上述已经测试好了读在18和28直接跳跃
## 下面测试写:
客户机连接mycat执行:
mysql> USE TESTDB;
mysql> insert students (name,age)values('wangwangwang',30);
在主服务可以看到
26 | wangwangwang | 30 | F | NULL | NULL |
[root@master ~]# systemctl stop mysqld.service #停止主的服务
# mycat插入数据报错:
mysql> insert students(name,age)values('zhangzhangzhang',20);
ERROR 1184 (HY000): java.net.ConnectException: Connection refused
[root@master ~]# systemctl start mysqld.service #开启主服务 mycat再次可以插入
mysql> insert students(name,age)values('zhangzhangzhang',20);
Query OK, 1 row affected (0.01 sec)
13、综合实验1
#环境:
master: 10.0.0.8 rocky8.6
slave: 10.0.0.18 rocky8.6
slave1: 10.0.0.28 rocky8.6
Mycat: 10.0.0.38 rocky8.6
MHA manager: 10.0.0.188 centos7
#流程:
1、先实现半同步主从
2、加入Gtid复制
3、增加Mycat读写分离
4、建立MHA高可用
# 需提前准备
Mycat安装包: Mycat-server-1.6.7.6-release-20220524173810-linux.tar.gz
MHA管理安装包和节点安装包:
- mha4mysql-manager-0.58-0.el7.centos.noarch.rpm
- mha4mysql-node-0.58-0.el7.centos.noarch.rpm
VIP自动飘逸脚本: master_ip_failover
邮件自动发送脚本: sendmail.sh
打通所有节点ssh脚本: ssh_key_for_linux.sh
Mycat设置模板:
- server.xml
- schema.xml
MHA设置模板: app1.cnf
----------------------------半同步复制 ------------------------
#master:
[root@master ~]# vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
server-id=8
log-bin=/data/mysql/mysql-bin
[root@master ~]# systemctl restart mysqld.service
[root@master ~]# mysql
mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';
[root@master ~]# vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
server-id=8
log-bin=/data/mysql/mysql-bin
rpl_semi_sync_master_enabled=ON
rpl_semi_sync_master_timeout=3000
[root@master ~]# mkdir /data/mysql
[root@master ~]# chown -R mysql.mysql /data/mysql
[root@master ~]# mysqldump -A -F --single-transaction --master-data=1 > all.sql
[root@master ~]# scp all.sql root@10.0.0.18:
[root@master ~]# scp all.sql root@10.0.0.28:
[root@master ~]# systemctl restart mysqld.service
[root@master ~]# mysql
mysql> show master logs;
+------------------+-----------+-----------+
| Log_name | File_size | Encrypted |
+------------------+-----------+-----------+
| mysql-bin.000001 | 156 | No |
+------------------+-----------+-----------+
1 row in set (0.00 sec)
mysql> create user repluser@'10.0.0.%' identified by '123456';
Query OK, 0 rows affected (3.01 sec)
mysql> grant replication slave on *.* to repluser@'10.0.0.%';
Query OK, 0 rows affected (0.00 sec)
#slave
[root@slave ~]# vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
server-id=18
log-bin=/data/mysql/mysql-bin
[root@slave ~]# mkdir /data/mysql
[root@slave ~]# chown -R mysql.mysql /data/mysql
[root@slave ~]# systemctl restart mysqld.service
[root@slave ~]# mysql
mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
mysql> set sql_log_bin=0;
mysql> source /root/all.sql
mysql> set sql_log_bin=1;
CHANGE MASTER TO
MASTER_HOST='10.0.0.8',
MASTER_USER='repluser',
MASTER_PASSWORD='123456',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=156,
MASTER_CONNECT_RETRY=10;
[root@slave ~]# vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
server-id=18
log-bin=/data/mysql/mysql-bin
rpl_semi_sync_slave_enabled=ON
[root@slave ~]# systemctl restart mysqld.service
[root@slave ~]# mysql
mysql> start slave;
mysql> show slave status\G
# slave1的操作步骤同slave
========================GTID============================
在上边半同步的基础上增加:
# master:
[root@master ~]# vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
server-id=8
log-bin=/data/mysql/mysql-bin
rpl_semi_sync_master_enabled=ON
rpl_semi_sync_master_timeout=3000
gtid_mode=ON #开启gtid
enforce_gtid_consistency #保证GTID安全参数
[root@master ~]# systemctl restart mysqld.service
# slave和slave1同样在配置文件增加gtid的两行,重启服务即可
进入mysql master可以通过mysql> show master status;查看gtid 信息,一般需要同步过一次后才会显示。
slave可以通过mysql> show slave status\G 查看Gtid信息。
=================Mycat===============
# mycat:
[root@mycat ~]#yum install -y java
[root@mycat ~]#java -version
openjdk version "1.8.0_332"
[root@mycat ~]#mkdir /apps
[root@mycat ~]#tar xf Mycat-server-1.6.7.6-release-20220524173810-linux.tar.gz -C /apps/
[root@mycat ~]#echo 'PATH=/apps/mycat/bin:$PATH' > /etc/profile.d/mycat.sh
[root@mycat ~]#. /etc/profile.d/mycat.sh
[root@mycat mycat]#vim conf/server.xml
<property name="serverPort">3306</property> #修改8066端口为3066,此行(45行)默认是注释的,可以复制到53行左右为注释的地方
[root@mycat mycat]#vim conf/schema.xml
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1">
</schema>
<dataNode name="dn1" dataHost="localhost1" database="hellodb" />
<dataHost name="localhost1" maxCon="1000" minCon="10" balance="1"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="host1" url="10.0.0.8:3306" user="li" password="123456">
<readHost host="host2" url="10.0.0.18:3306" user="li" password="123456" />
<readHost host="host3" url="10.0.0.28:3306" user="li" password="123456" />
</writeHost>
</dataHost>
</mycat:schema>
# master
mysql> create user li@'10.0.0.%' identified by '123456';
mysql> grant all on *.* to li@'10.0.0.%';
# client测试:
[root@rocky8 ~]# mysql -uroot -p123456 -h10.0.0.38
mysql> show databases;
mysql> use TESTDB;
mysql> select @@server_id;
+-------------+
| @@server_id |
+-------------+
| 28 |
+-------------+
1 row in set (0.01 sec)
mysql> select @@server_id;
+-------------+
| @@server_id |
+-------------+
| 18 |
+-------------+
1 row in set (0.00 sec)
# MHA(centos7):
=======================在所有节点实现相互之间 ssh key 验证========================
# 修改下边脚本的密码变量PASS和网卡接口:
[root@MHA ~]# vim ssh_key_for_linux.sh
PASS=redhat # 密码为redhat
END=254
IP=`ip a s ens33 | awk -F'[ /]+' 'NR==3{print $3}'` #网卡名称为ens33
NET=${IP%.*}.
. /etc/os-release
rm -f /root/.ssh/id_rsa
[ -e ./SCANIP.log ] && rm -f SCANIP.log
for((i=3;i<="$END";i++));do
ping -c 1 -w 1 ${NET}$i &> /dev/null && echo "${NET}$i" >> SCANIP.log &
done
wait
ssh-keygen -P "" -f /root/.ssh/id_rsa
if [ $ID = "centos" -o $ID = "rocky" ];then
rpm -q sshpass || yum -y install sshpass
else
dpkg -i sshpass &> /dev/null ||{ apt update; apt -y install sshpass; }
fi
sshpass -p $PASS ssh-copy-id -o StrictHostKeyChecking=no $IP
AliveIP=(`cat SCANIP.log`)
for n in ${AliveIP[*]};do
sshpass -p $PASS scp -o StrictHostKeyChecking=no -r /root/.ssh root@${n}:
done
#把.ssh/known_hosts拷贝到所有主机,使它们第一次互相访问时不需要输入回车
for n in ${AliveIP[*]};do
scp /root/.ssh/known_hosts ${n}:.ssh/
done
[root@MHA ~]# chmod +x ssh_key_for_linux.sh
[root@MHA ~]# ./ssh_key_for_linux.sh
===========================安装相关包=======================================
# MHA服务器安装mha4mysql-manager和node (建议先安装manager后安装node)
[root@MHA ~]# yum install -y epel-release mha4mysql-manager-0.58-0.el7.centos.noarch.rpm mha4mysql-node-0.58-0.el7.centos.noarch.rpm ## (没有epel源的话安装manager会报错)
# 所有mysql主从服务器安装mha4mysql-node
[root@master ~]# yum install -y mha4mysql-node-0.58-0.el7.centos.noarch.rpm
[root@slave ~]# yum install -y mha4mysql-node-0.58-0.el7.centos.noarch.rpm
[root@slave1 ~]# yum install -y mha4mysql-node-0.58-0.el7.centos.noarch.rpm
# 准备相关脚本和配置mha4mysql-manager配置
# MHA:
=======================master_ip_failover脚本=====================
[root@MHA ~]# cat /usr/local/bin/master_ip_failover
#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
use Getopt::Long;
use MHA::DBHelper;
my (
$command, $ssh_user, $orig_master_host,
$orig_master_ip, $orig_master_port, $new_master_host,
$new_master_ip, $new_master_port, $new_master_user,
$new_master_password
);
#执行时必须删除下面三行注释
my $vip = '10.0.0.188/24'; # 修改这里的ip, 找个空闲的ip, 不能是在用的
my $key = "1";
my $ssh_start_vip = "/sbin/ifconfig eth0:$key $vip"; # 这里和下一行需要注意下网卡信息,我是用的虚拟机网卡是eth0, 需修改成机器的网卡信息
my $ssh_stop_vip = "/sbin/ifconfig eth0:$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,
'new_master_user=s' => \$new_master_user,
'new_master_password=s' => \$new_master_password,
);
exit &main();
sub main {
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 {
# updating global catalog, etc
$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();
&stop_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;
}
}
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";
}
[root@MHA ~]# chmod +x /usr/local/bin/master_ip_failover
=======================sendmail.sh脚本============================================
vim /usr/local/bin/sendmail.sh
#!/bin/bash
echo "MHA is failover!" | mail -s "MHA Warning" 965507991@qq.com
[root@MHA ~]# chmod +x /usr/local/bin/sendmail.sh
[root@MHA ~]# yum install -y mailx
[root@MHA ~]# vim /etc/mail.rc #在最后添加以下自己的邮箱信息
set from=96550@qq.com #自己的邮箱
set smtp=smtp.qq.com #邮箱的smtp服务器
set smtp-auth-user=96550@qq.com #邮箱用户名
set smtp-auth-password=arxbgiznng #邮箱smtp授权码
[root@MHA ~]# bash /usr/local/bin/sendmail.sh #测试邮箱是否能收到邮件
=================================建立配置文件==================================
[root@MHA ~]# mkdir /etc/mastermha
[root@MHA ~]# vim /etc/mastermha/app1.cnf
[server default]
check_repl_delay=0
manager_log=/data/mastermha/app1/manager.log
manager_workdir=/data/mastermha/app1/
remote_workdir=/data/mastermha/app1/
master_binlog_dir=/data/mysql/
master_ip_failover_script=/usr/local/bin/master_ip_failover
ping_interval=1
repl_user=repluser
repl_password=123456
report_script=/usr/local/bin/sendmail.sh
ssh_user=root
user=mhauser
password=123456
[server1]
hostname=10.0.0.8
candidate_master=1
[server2]
hostname=10.0.0.18
[server3]
candidate_master=1
hostname=10.0.0.28
# master:
[root@master ~]# vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
server-id=8
log-bin=/data/mysql/mysql-bin
rpl_semi_sync_master_enabled=ON
rpl_semi_sync_master_timeout=3000
gtid_mode=ON
enforce_gtid_consistency
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid
skip_name_resolve=1 #增加(可选) 禁止反向解析
general_log #方便观察的设置 (开启通用日志)
[root@master ~]# systemctl restart mysqld.service
[root@master ~]# ifconfig eth0:1 10.0.0.188/24
[root@master ~]# mysql
mysql> create user mhauser@'10.0.0.%' identified by '123456';
mysql> grant all on *.* to mhauser@'10.0.0.%';
# slave:
[root@slave ~]# vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
server-id=18
log-bin=/data/mysql/mysql-bin
rpl_semi_sync_slave_enabled=ON
gtid_mode=ON
enforce_gtid_consistency
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid
read_only #只读
relay_log_purge=0 #禁止自动删除不再使用的relay log
skip_name_resolve=1 #禁止反向解析,此项可选
general_log
[root@slave ~]# systemctl restart mysqld.service
# slave2 配置同slave
=========================================
# MHA:
[root@MHA ~]# masterha_check_ssh --conf=/etc/mastermha/app1.cnf #检查环境
[root@MHA ~]# masterha_check_repl --conf=/etc/mastermha/app1.cnf #如果出错,检查配置和脚本
[root@MHA ~]# masterha_check_status --conf=/etc/mastermha/app1.cnf #查看状态,现在是no running
[root@MHA ~]# masterha_manager --conf=/etc/mastermha/app1.cnf --remove_dead_master_conf --ignore_laste_failover #启动MHA ,生产环境一般后台运行,需要在头前加nohup 尾部加&> /dev/null
再开个窗口查看状态:
[root@MHA ~]# masterha_check_status --conf=/etc/mastermha/app1.cnf #查看状态
app1 (pid:15957) is running(0:PING_OK), master:10.0.0.8
# 模拟故障:
[root@master ~]# systemctl stop mysqld.service #10.0.0.8主服务器停止服务
MHA查看日志:
[root@MHA ~]# tail /data/mastermha/app1/manager.log -f
......
Master 10.0.0.8(10.0.0.8:3306) is down!
Started automated(non-interactive) failover.
Invalidated master IP address on 10.0.0.8(10.0.0.8:3306)
The latest slave 10.0.0.18(10.0.0.18:3306) has all relay logs for recovery.
Selected 10.0.0.28(10.0.0.28:3306) as a new master.
10.0.0.28(10.0.0.28:3306): OK: Applying all logs succeeded.
10.0.0.28(10.0.0.28:3306): OK: Activated master IP address.
10.0.0.18(10.0.0.18:3306): This host has the latest relay log events.
Generating relay diff files from the latest slave succeeded.
10.0.0.18(10.0.0.18:3306): OK: Applying all logs succeeded. Slave started, replicating from 10.0.0.28(10.0.0.28:3306)
10.0.0.28(10.0.0.28:3306): Resetting slave info succeeded.
Master failover to 10.0.0.28(10.0.0.28:3306) completed successfully.
Sat Sep 3 15:51:06 2022 - [info] Sending mail..
[root@MHA ~]# cat /etc/mastermha/app1.cnf #查看配置文件,原主服务器8的地址已经被删除
[server2]
hostname=10.0.0.18
[server3]
candidate_master=1
hostname=10.0.0.28
# 邮箱也收到了邮件。
# slave 18主机查看状态:
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for source to send event
Master_Host: 10.0.0.28
Master_User: repluser
# 原slave1 28主机已成为新的主服务器,验证VIP飘逸:
[root@slave1 ~]# ip a
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:5d:78:d1 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.28/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet 10.0.0.188/24 brd 10.0.0.255 scope global secondary eth0:1
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe5d:78d1/64 scope link
valid_lft forever preferred_lft forever
# 再次运行MHA,需要删除下面文件:
# MHA删除:[root@MHA ~]# rm -rf /data/mastermha/app1/
# 所有节点删除:
[root@master ~]# rm -rf /data/mastermha/app1/
[root@slave ~]# rm -rf /data/mastermha/app1/
[root@slave1 ~]# rm -rf /data/mastermha/app1/
# 原来的10.0.0.8变为从服务器
mysql> CHANGE MASTER TO
-> MASTER_HOST='10.0.0.28',
-> MASTER_USER='repluser',
-> MASTER_PASSWORD='123456',
-> MASTER_PORT=3306,
-> MASTER_AUTO_POSITION=1;
Query OK, 0 rows affected, 8 warnings (0.06 sec)
mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for source to send event
Master_Host: 10.0.0.28
# MHA配置新加入一个IP服务器在开启masterha即可
Rocky之Mysql-MHA高可用的更多相关文章
- 搭建MySQL MHA高可用
本文内容参考:http://www.ttlsa.com/mysql/step-one-by-one-deploy-mysql-mha-cluster/ MySQL MHA 高可用集群 环境: Linu ...
- MySQL MHA 高可用集群部署及故障切换
MySQL MHA 高可用集群部署及故障切换 1.概念 2.搭建MySQL + MHA 1.概念: a)MHA概念 : MHA(MasterHigh Availability)是一套优秀的MySQL高 ...
- Mysql MHA高可用集群架构
** 记得之前发过一篇文章,名字叫<浅析MySQL高可用架构>,之后一直有很多小伙伴在公众号后台或其它渠道问我,何时有相关的深入配置管理文章出来,因此,民工哥,也将对前面的各类架构逐一进行 ...
- MySQL mha 高可用集群搭建
[mha] MHA作为MySQL故障切换和主从提升的高可用软件,在故障切换过程中,MHA能做到在0~30秒之内自动完成数据库的故障切换操作,并且在进行故障切换的过程中,MHA能在最大程度上保证数据的一 ...
- mysql mha高可用架构的安装
MMM无法全然地保证数据的一致性,所以MMM适用于对数据的一致性要求不是非常高.可是又想最大程度的保证业务可用性的场景对于那些对数据一致性要求非常高的业务,非常不建议採用MMM的这样的高可用性架构.那 ...
- mysql+MHA高可用
MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司)开发,是一套优秀 ...
- MySQL MHA高可用集群部署及故障切换
一.MHA概念MHA(MasterHigh Availability)是一套优秀的MySQL高可用环境下故障切换和主从复制的软件.MHA 的出现就是解决MySQL 单点的问题.MySQL故障切换过程中 ...
- mysql MHA高可用测试
[环境介绍] 系统环境:Red Hat Enterprise Linux 7 + 5.7.18 + MHA version 0.57 [测试步骤:自动切换] 当前数据库状态: 系统 IP 主机名 备注 ...
- centos7 mysql+MHA高可用安装
https://dzone.com/articles/consul-proxysql-and-mysql-ha?utm_medium=feed&utm_source=feedpress.me& ...
- mysql+MHA高可用 (一主双从)
1.准备三台服务器 10.0.0.12 10.0.0.13 10.0.0.14 2.在三台服务器上执行操作 时间同步 [root@ c7m01 ~]# echo "*/5* * * * /u ...
随机推荐
- mybatis 13: 一对多关联查询
业务背景 根据客户id查询客户基本信息,以及客户存在的订单信息 两张数据表 客户表 订单表 实体类 客户实体类:Customer private Integer id; private String ...
- 树莓派4B无屏幕连接Wi-Fi/启用ssh/创建用户
前边总得说点什么 最近每次在Win10上写代码需要启动Redis,残血Redis For Windows有卡死系统的bug.由于主机内存不大够用(已经扩到顶了),开虚拟机运行Redis更别提了..想起 ...
- 零基础学Java(14)对象构造
对象构造 之前学习了编写简单的构造器,可以定义对象的初始状态.但是,由于对象构造非常重要,所以Java提供了多种编写构造器的机制. 重载 有些类有多个构造器.例如,可以如下构造一个空的StringBu ...
- 通过cpu热插拔解决rcu stall的问题
在linux 3.10环境一次故障处理中,发现有类似如下打印: NFO: rcu_sched_state detected stalls on CPUs/tasks: {15 } (detected ...
- day24--Java集合07
Java集合07 14.HashMap底层机制 (k,v)是一个Node,实现了Map.Entry<K,V>,查看HashMap的源码可以看到 jdk7.0 的HashMap底层实现[数组 ...
- Find-Vulnerability 自动化探测扫描工具简介
Fvuln 简介 F-vuln(全称:Find-Vulnerability)是一款自动化探测扫描工具,主要适用于日常安全服务.渗透测试人员和RedTeam红队人员使用 它集合的功能包括: 存活IP探测 ...
- 【C标准库】详解feof函数与EOF
创作不易,多多支持! 再说此函数之前,先来说一下EOF是什么 EOF,为End Of File的缩写,通常在文本的最后存在此字符表示资料结束. 在C语言中,或更精确地说成C标准函式库中表示文件结束符. ...
- Typora多线程批量上传图片,永久免费25G图床
为了满足日常需求,就写了一个自动上传图片到图床的脚本 运行该程序可以做到自动完成图片上传,并自动替换为网络链接,支持多图同时上传,采用了多线程,上传速度提升很明显. 以Window系统为例,操作步骤: ...
- mysql选择列建立索引选择
1. 选择Where子句中筛选性好的列,即列中数据大量不重复 2. 索引名最好 idx_ 开头 3. 包含在 Order by ; Group By; Distinct 中的字段可以添加索引,可以提高 ...
- Redis6.0.6的三大内存过期策略和八大淘汰策略
一.前言 Redis在我们日常开发中是经常用到的,Redis也是功能非常强大,可以进行缓存,还会有一些排行榜.点赞.消息队列.购物车等等:当然还有分布式锁Redisson,我们使用肯定少不了集群!小编 ...