MySQL MGR(组复制)高可用VIP切换工具

MySQL 8.0 MGR高可用vip切换工具

介绍:

MySQL Group Replication(MGR)组复制是MySQL官方在5.7.17版本引进的一个数据库高可用与高扩展的解决方案,以插件形式提供,实现了分布式下数据的最终一致性。但是官方没有给出vip的漂移方案,官方的推荐是使用MySQL Router,但是经过这一层代理后会有性能的损耗。于是用了Go简单写了这个工具。

之所以选择Go的原因是Go语言不用像Python之类的脚本语言需要关注一大堆依赖,部署非常不难受,而Go只需要一个二进制文件即可。

配置说明

[system]
cluster_vip              =  192.168.43.38
nic                      =  en0
polling_interval_Seconds =  5
admin_user      =  admin_op
admin_password  =  admin_op
admin_address   =  172.16.200.12
#尽量填写MySQL 8.0管理端口, 管理端口不受max_connections的限制。
admin_port      =  5000
peer_ips        =  172.16.200.12,172.16.200.13,172.16.200.14
  • cluster_vip 集群的VIP(三个节点可以不配置一致)。

  • polling_interval_Seconds: 检测节点角色的时间频率,单位为秒(S)

  • nic 网卡名,当MGR接到变为Primary时会把ClusterVip绑定在此网卡上。

admin_user,admin_password,admin_address,admin_port是mgr-agent程序用来连接MySQL检测主从角色的用户。

运行条件

  1. MySQL 8.0版本以上
  2. MGR单主模式(Single-Primary-Mode)
  3. 原生用户认证模式(mysql_native_password)
    在create_user.sql里面有创建用户的语句。
create user if not exists  admin_op@'%' identified WITH mysql_native_password By 'admin_op';
grant select  on performance_schema.* to admin_op@'%';

运行方式说明

安装

下载链接mgr-agent
解压在合适的位置即可。

帮助

目前只简单提供了两个子命令,启动和关闭。

# ./bin/mgr-agent -h
mgr-agent 

A Virtual IP failover agent tool for MySQL Group Replication(Single Primary Mode):

Usage:
  mgr-agent [flags]
  mgr-agent [command]

Available Commands:
  help        Help about any command
  start       start mgr-agent
  stop        Stop mgr-agent

Flags:
  -c, --config string   configuration file to use (default "conf/agent.system")
  -h, --help            help for mgr-agent
  -v, --version         version for mgr-agent

Use "mgr-agent [command] --help" for more information about a command.
  • 前台启动
# ./bin/mgr-agent start
2020/09/23 15:01:47 mgr-agent start
2020-09-23 15:01:47 [INFO] [mgr-agent/app/config.go:15] load config success
  • 后台启动
# ./bin/mgr-agent start -d
2020/09/23 15:02:13 ./bin/mgr-agent start, [PID] %d running...
 28420
  • 关闭
./bin/mgr-agent stop
2020-09-23 15:01:20 [INFO] [mgr-agent/main.go:94] mgr-agent stopped

原理

agent判断逻辑:

  • (1)每次检查如果本机是Primary,且查询另外两个节点都不是Primary(包括是Secondary,offline,…或者连不上或者没有数据返回等情况),则绑定vip,否则保持不动。
  • (2)每次检查如果本机不是Primary(包括是Secondary,offline,…或者连不上或者没有数据返回等情况),连另外两个节点,如果任意一个等于Primary, 则卸载vip,否则保持不动。

注意事项:

  1. 默认情况下,节点退出MGR集群,会变为超级只读(super_read_only=1),从退出集群到vip正式被卸载存在检测时间,为防止数据混乱,业务用户切不可有super权限;
  2. 实际上,MySQL 5.7版本也可使用此工具,但是考虑到5.7 MGR的不稳定性,推荐使用8.0版本;
  3. 切换工具的需要自定义开机启动;
    4.MGR的部署请自行遵循最佳实践,切换工具mgr-agent不管这些。

工具链接地址:
https://github.com/yuzhaoge/mgr-agent

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值