扩展功能
Arksentinel 支持节点按照距离远近来调整切换优先级,哨兵切换节点时首先对比数据同步情况(主从架构,Galera,MGR默认一致),然后根据节点间距离进行优先排序(两个节点配置的address_num绝对值),距离越近优先级越高.
此外,用户可以在切换时配置调用脚本,进行proxy,vip或者域名等操作(当前提供两种切换方式:基于vip和基于Arkproxy,如果用户想要基于其他方式或者无法通过ifconfig进行vip绑定解绑则需要自己编写)
目前拓展功能只支持手动配置对应架构的数据库表.
基于VIP切换测试
初始化测试环境
- 搭建主从架构集群如下
- 配置切换脚本路径
// 登录哨兵配置库,设置切换脚本,在执行故障切换时会调用failover,手动维护操作时调用switchover
// 用户可以根据下面的接口定义编写符合自己场景的切换脚本
update sentinel_config set switchover_script='./switchover',failover_script='./failover';
// 哨兵故障切换时调用接口如下
-namespace string
cluster namespace: a name to mysql cluster (default "namespace")
-newip string
instance ip which replace old one (default "10.0.0.90")
-newport int
instance port which replace old one (default 3306)
-oldip string
instance ip which can`t work well (default "10.0.0.89")
-oldport int
instance port which can`t work well (default 3306)
-role string
instance role: master standby statistic (default "standby")
-type string
sentinel type:Base, MasterSlave, GaleraCluster, Arkgate, ETL (default "Base")
// 哨兵手动运维切换时调用接口如下
-namespace string
cluster namespace: a name to mysql cluster (default "namespace")
-op string
operation type:MarkNormal, MarkMaintain, AddNode, DelNode, Promotion, ForceMaintain (default "MarkNormal")
-opip string
operation instance ip (default "10.0.0.89")
-opport int
operation instance port (default 3306)
-replaceip string
old master ip when Promotion operation (default "10.0.0.90")
-replaceport int
old master port when Promotion operation (default 3306)
-role string
instance role: master standby statistic (default "standby")
-type string
sentinel type:Base, MasterSlave, GaleraCluster, Arkgate, ETL (default "Base")
- 设置切换配置
// 在ark_sentinel中添加 switch_config表
CREATE TABLE `switch_config` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`namespace` varchar(100) NOT NULL COMMENT '集群标志名称',
`switch_type` enum('vip','arkproxy','domain') NOT NULL DEFAULT 'arkproxy' COMMENT '切换方式,分别为虚拟ip,arkproxy,域名',
`config` json DEFAULT NULL COMMENT '不同切换方式对应不同的配置参数',
`update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_namespace` (`namespace`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4
// failover脚本使用ssh登录旧节点 执行 ifconfig down(失败的话则忽略,避免机器down掉影响流程)
// 然后登录新节点执行ifconfig up, 最后在新节点执行arping更新
// 因此需要配置ssh,网卡等信息
insert switch_config values(null,'ms_demo1','vip','{"ssh_config": {"nic": "enp0s3