mysql主主高可用方案

时间:2021-12-25 04:49:29

masterA配置:

yum -y install keepalived

vim /etc/keepalived/keepalived.conf

mysql主主高可用方案

router_id LVS_MASTER-A

mysql主主高可用方案

 

 

 interface ens33

nopreempt

mysql主主高可用方案

 

 

 track_script {

mysql
}

 

vim /opt/mysql.sh     //编写脚本

脚本内容:

#!/bin/bash
counter=$(netstat -na|grep "LISTEN"|grep "3306"|wc -l)
if [ "${counter}" -eq 0 ]; then
systemctl stop keepalived
fi

chmod x /opt/mysql.sh 

 systemctl start keepalived    //重启keepalived

 ip a | grep ens33

mysql主主高可用方案

 

 

  tail -f /var/log/messages

mysql主主高可用方案

 

 

 masterB配置:

yum -y install keepalived

vim /etc/keepalived/keepalived.conf 

mysql主主高可用方案

 

 

  router_id LVS_MASTER-B

mysql主主高可用方案

 

 

 interface ens32

priority 99

track_script {
mysql
}

 

vim /opt/mysql.sh

脚本内容:

#!/bin/bash
counter=$(netstat -na|grep "LISTEN"|grep "3306"|wc -l)
if [ "${counter}" -eq 0 ]; then
systemctl stop keepalived
fi

 

chmod x /opt/mysql.sh

systemctl start keepalived

 tail -f /var/log/messages

mysql主主高可用方案

 

 

 

测试VIP转移

masterA配置

systemctl stop mariadb

ip a | grep ens33

mysql主主高可用方案

 

  ps aux | grep mysql

mysql主主高可用方案

 

 masterB 配置

ip a | grep ens32

mysql主主高可用方案

 

 tail -f /var/log/messages

mysql主主高可用方案

 

 在远程客户端测试

所有mysql服务器授权

mysql -uroot -p000000

 grant all on *.* to ‘root‘@‘192.168.96.%‘ identified by ‘123456‘;

flush privileges;

通过VIP登录测试:

mysql -uroot -p123456 -h 192.168.96.16

mysql主主高可用方案