mysql主主高可用方案

Posted 正经追梦

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql主主高可用方案相关的知识,希望对你有一定的参考价值。

masterA配置:

yum -y install keepalived

vim /etc/keepalived/keepalived.conf

router_id LVS_MASTER-A

 

 

 interface ens33

nopreempt

 

 

 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

 

 

  tail -f /var/log/messages

 

 

 masterB配置:

yum -y install keepalived

vim /etc/keepalived/keepalived.conf 

 

 

  router_id LVS_MASTER-B

 

 

 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

 

 

 

测试VIP转移

masterA配置

systemctl stop mariadb

ip a | grep ens33

 

  ps aux | grep mysql

 

 masterB 配置

ip a | grep ens32

 

 tail -f /var/log/messages

 

 在远程客户端测试

所有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主主高可用方案的主要内容,如果未能解决你的问题,请参考以下文章

keepalived+MySQL主主高可用

MySQL主主高可用(keepalive)

配置MySQL实现主主互备模式并利用keepalived实现双主高可用

MYSQL双主高可用方案部署实例

基于keepalived搭建mysql双主高可用

MySQL集群之keepalived实现mysql双主高可用