mysql主主高可用_mysql主主高可用方案

masterA配置:

yum -y install keepalived

vim /etc/keepalived/keepalived.conf

5f619213d97cf26903acc6b35f9c5962.png

router_id LVS_MASTER-A

95d4e1564f1d02b725a36252e2876f93.png

interface ens33

nopreempt

4199e79d14263d3109772006a294c440.png

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

9c3957f4b8d711fe25f936941e026dea.png

tail -f /var/log/messages

7b4cfb163650150f257dfefd3a0e46f3.png

masterB配置:

yum -y install keepalived

vim /etc/keepalived/keepalived.conf

66dd2aba3c772c14bc698f6a8b4d11f1.png

router_id LVS_MASTER-B

553a75b8e09cbfd282d9b0a40a29e6e1.png

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

0b382a77b7cc796da8433a595ff5533f.png

测试VIP转移

masterA配置

systemctl stop mariadb

ip a | grep ens33

fa0c33668f975144d63910adb2db0e97.png

ps aux | grep mysql

751bec8d4598063c9b1c7fd20ad86a68.png

masterB 配置

ip a | grep ens32

35d7a67b8f4fe2e19d46e8a2b7766f57.png

tail -f /var/log/messages

29ae27748a32c14963ac7a317113bee5.png

在远程客户端测试

所有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

25a8be8cca03c64dafa6fb1b5678b801.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值