# mgr-agent **Repository Path**: leocd/mgr-agent ## Basic Information - **Project Name**: mgr-agent - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-04-11 - **Last Updated**: 2024-04-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README mysql 8.0 MGR(GroupReplication) vip 切换工具 ### 配置说明 ```bash [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 #ordinal是MGR节点序号 ordinal = 0 ``` - cluster_vip 集群的VIP(三个节点可以不配置一致); - polling_interval_Seconds: 检测节点角色的时间频率,单位为秒(S); - nic 网卡名,当MGR接到变为Primary时会把ClusterVip绑定在此网卡上; - peer_ips MGR三节点的IP地址。其中之一的地址需要在本机上; - ordinal MGR节点序号,建议依次使用0/1/2 admin_user,admin_password,admin_address,admin_port-agent程序用来连接MySQL检测主从角色的用户; ### 运行条件 1. MySQL 8.0版本以上 2. MGR单主模式(Single-Primary-Mode) 3. 原生用户认证模式(mysql_native_password) 在create_user.sql里面有创建用户的语句。 ```bash create user if not exists admin_op@'%' identified WITH mysql_native_password By 'admin_op'; grant select on performance_schema.* to admin_op@'%'; ``` ### 运行方式 帮助:目前只简单提供了两个子命令,启动和关闭。 ```bash # ./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. ``` - 可将应用托管至systemd,根据实际情况修改mgr-agent.service后使用 - 前台启动 ```bash # ./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 ``` - 后台启动 ```bash # ./bin/mgr-agent start -d 2020/09/23 15:02:13 ./bin/mgr-agent start, [PID] %d running... 28420 ``` - 关闭 ```$xslt ./bin/mgr-agent stop 2020-09-23 15:01:20 [INFO] [mgr-agent/main.go:94] mgr-agent stopped ``` ### 原理 agent判断逻辑: - 每次检查如果本机是Primary,且查询另外两个节点都不是Primary(包括是Secondary,offline,....或者连不上或者没有数据返回等情况),则绑定vip,否则保持不动。 - 每次检查如果本机不是Primary(包括是Secondary,offline,....或者连不上或者没有数据返回等情况),连另外两个节点,如果任意一个等于Primary, 则卸载vip,否则保持不动。 > 注意事项: 1. 默认情况下,节点退出MGR集群,会变为超级只读(super_read_only=1),从退出集群到vip正式被卸载存在检测时间,为防止数据混乱,业务用户切不可有super权限。 2. MGR的部署请自行遵循最佳实践。