基础信息
ProxySQL
版本:1.4.8-32-g669c149
ProxySQL 1:proxysql1 192.168.1.15 监听端口6032
ProxySQL 2:proxysql2 192.168.1.16 监听端口6032
Keepalived
版本:keepalived-1.4.4
同时在ProxySQL 1和ProxySQL 2上面安装
VIP
192.168.1.88
机器信息
1 | # cat /etc/redhat-release |
安装Keepalived
1 | # 依赖安装 |
配置
两个keepalived配置
1 | ProxySQL 1: state MASTER;priority 100 |
1 | vim /etc/keepalived/keepalived.conf |
配置iptables防火墙规则
1 | vim /etc/sysconfig/iptables |
重启防火墙
1 | systemctl restart iptables |
测试
启动keepalived
1 | systemctl start keepalived |
查看vip切换情况
1 | ip addr |
通过VIP连接
1 | mysql -u proxysql -p -h vip -P6033 |
停止proxysql1的proxysql进程
1 | # 停止proxysql |
1 | # 查看两台机器keepalived的日志 |
1 | # 查看两台机器的vip绑定情况 |
可见已经实现vip的漂移,通过命令行连接
1 | mysql -u proxysql -p -h vip -P6033 |
问题排查
keepalived主备同时都有VIP
原因:主备vvrp直接无法通信
解决:检查防火墙,开启组播
主备切换后,新主再故障,主备无法再次切换
原因:主开启了nopreempt,不抢占
解决:去除主的该配置即可,可参考Keepalived中Master和Backup角色选举策略
参考
1. Mysql+Keepalived双主热备高可用操作记录
2. 解决ProxySQL的单点问题
3. Keepalived中Master和Backup角色选举策略