keepalived instance priority don't impact by track script|interface weight when 255

简介:
前面我在写keepalived优先级动态调整时, 写到关于初始优先级设置为255的instance不被动态调整的内容, 原因参考本文末尾部分. 因为
if (vrrp->base_priority == VRRP_PRIO_OWNER) {
/* we will not run a PRIO_OWNER into a non-PRIO_OWNER */
vrrp->effective_priority = VRRP_PRIO_OWNER;
本文主要就是实际验证一下.
用的例子参考
把192.168.173.204的初始优先级调整为255.
把192.168.173.203的初始优先级调整为254.
keepalived启动后, 192.168.173.204是MASTER.
Aug 21 13:59:03 192_168_173_203 Keepalived[421]: Starting Keepalived v1.2.13 (08/19,2014)
Aug 21 13:59:03 192_168_173_203 Keepalived[422]: Starting Healthcheck child process, pid=423
Aug 21 13:59:03 192_168_173_203 Keepalived[422]: Starting VRRP child process, pid=424
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Netlink reflector reports IP 192.168.173.203 added
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Netlink reflector reports IP 192.168.173.156 added
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Netlink reflector reports IP fe80::f6ce:46ff:fe86:4234 added
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Registering Kernel netlink reflector
Aug 21 13:59:03 192_168_173_203 Keepalived_healthcheckers[423]: Netlink reflector reports IP 192.168.173.203 added
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Registering Kernel netlink command channel
Aug 21 13:59:03 192_168_173_203 Keepalived_healthcheckers[423]: Netlink reflector reports IP 192.168.173.156 added
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Registering gratuitous ARP shared channel
Aug 21 13:59:03 192_168_173_203 Keepalived_healthcheckers[423]: Netlink reflector reports IP fe80::f6ce:46ff:fe86:4234 added
Aug 21 13:59:03 192_168_173_203 Keepalived_healthcheckers[423]: Registering Kernel netlink reflector
Aug 21 13:59:03 192_168_173_203 Keepalived_healthcheckers[423]: Registering Kernel netlink command channel
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Opening file '/opt/keepalived/etc/keepalived/keepalived.conf'.
Aug 21 13:59:03 192_168_173_203 Keepalived_healthcheckers[423]: Opening file '/opt/keepalived/etc/keepalived/keepalived.conf'.
Aug 21 13:59:03 192_168_173_203 Keepalived_healthcheckers[423]: Configuration is using : 7937 Bytes
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Configuration is using : 69311 Bytes
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Using LinkWatch kernel netlink reflector...
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: VRRP sockpool: [ifindex(2), proto(112), unicast(1), fd(10,11)]
Aug 21 13:59:03 192_168_173_203 Keepalived_healthcheckers[423]: Using LinkWatch kernel netlink reflector...
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: VRRP_Script(nag) succeeded
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: VRRP_Script(zero) succeeded
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: VRRP_Script(pos) succeeded
Aug 21 13:59:04 192_168_173_203 Keepalived_vrrp[424]: VRRP_Instance(vi_1) Transition to MASTER STATE
Aug 21 13:59:05 192_168_173_203 Keepalived_vrrp[424]: VRRP_Instance(vi_1) Entering MASTER STATE
Aug 21 13:59:05 192_168_173_203 Keepalived_vrrp[424]: VRRP_Instance(vi_1) setting protocol VIPs.
Aug 21 13:59:05 192_168_173_203 Keepalived_vrrp[424]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100
Aug 21 13:59:05 192_168_173_203 Keepalived_healthcheckers[423]: Netlink reflector reports IP 172.16.173.100 added
Aug 21 13:59:06 192_168_173_203 rgmanager[652]: [script] Executing /usr/local/bin/pgctl.sh status
Aug 21 13:59:10 192_168_173_203 Keepalived_vrrp[424]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100
Aug 21 13:59:26 192_168_173_203 rgmanager[1041]: [script] Executing /usr/local/bin/pgctl.sh status
Aug 21 13:59:29 192_168_173_203 Keepalived_vrrp[424]: VRRP_Instance(vi_1) Received higher prio advert
Aug 21 13:59:29 192_168_173_203 Keepalived_vrrp[424]: VRRP_Instance(vi_1) Entering BACKUP STATE
Aug 21 13:59:29 192_168_173_203 Keepalived_vrrp[424]: VRRP_Instance(vi_1) removing protocol VIPs.
Aug 21 13:59:29 192_168_173_203 Keepalived_healthcheckers[423]: Netlink reflector reports IP 172.16.173.100 removed

Aug 21 13:59:03 192_168_173_203 Keepalived[421]: Starting Keepalived v1.2.13 (08/19,2014)
Aug 21 13:59:03 192_168_173_203 Keepalived[422]: Starting Healthcheck child process, pid=423
Aug 21 13:59:03 192_168_173_203 Keepalived[422]: Starting VRRP child process, pid=424
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Netlink reflector reports IP 192.168.173.203 added
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Netlink reflector reports IP 192.168.173.156 added
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Netlink reflector reports IP fe80::f6ce:46ff:fe86:4234 added
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Registering Kernel netlink reflector
Aug 21 13:59:03 192_168_173_203 Keepalived_healthcheckers[423]: Netlink reflector reports IP 192.168.173.203 added
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Registering Kernel netlink command channel
Aug 21 13:59:03 192_168_173_203 Keepalived_healthcheckers[423]: Netlink reflector reports IP 192.168.173.156 added
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Registering gratuitous ARP shared channel
Aug 21 13:59:03 192_168_173_203 Keepalived_healthcheckers[423]: Netlink reflector reports IP fe80::f6ce:46ff:fe86:4234 added
Aug 21 13:59:03 192_168_173_203 Keepalived_healthcheckers[423]: Registering Kernel netlink reflector
Aug 21 13:59:03 192_168_173_203 Keepalived_healthcheckers[423]: Registering Kernel netlink command channel
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Opening file '/opt/keepalived/etc/keepalived/keepalived.conf'.
Aug 21 13:59:03 192_168_173_203 Keepalived_healthcheckers[423]: Opening file '/opt/keepalived/etc/keepalived/keepalived.conf'.
Aug 21 13:59:03 192_168_173_203 Keepalived_healthcheckers[423]: Configuration is using : 7937 Bytes
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Configuration is using : 69311 Bytes
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: Using LinkWatch kernel netlink reflector...
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: VRRP sockpool: [ifindex(2), proto(112), unicast(1), fd(10,11)]
Aug 21 13:59:03 192_168_173_203 Keepalived_healthcheckers[423]: Using LinkWatch kernel netlink reflector...
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: VRRP_Script(nag) succeeded
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: VRRP_Script(zero) succeeded
Aug 21 13:59:03 192_168_173_203 Keepalived_vrrp[424]: VRRP_Script(pos) succeeded
Aug 21 13:59:04 192_168_173_203 Keepalived_vrrp[424]: VRRP_Instance(vi_1) Transition to MASTER STATE
Aug 21 13:59:05 192_168_173_203 Keepalived_vrrp[424]: VRRP_Instance(vi_1) Entering MASTER STATE
Aug 21 13:59:05 192_168_173_203 Keepalived_vrrp[424]: VRRP_Instance(vi_1) setting protocol VIPs.
Aug 21 13:59:05 192_168_173_203 Keepalived_vrrp[424]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100
Aug 21 13:59:05 192_168_173_203 Keepalived_healthcheckers[423]: Netlink reflector reports IP 172.16.173.100 added
Aug 21 13:59:10 192_168_173_203 Keepalived_vrrp[424]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100
Aug 21 13:59:29 192_168_173_203 Keepalived_vrrp[424]: VRRP_Instance(vi_1) Received higher prio advert
Aug 21 13:59:29 192_168_173_203 Keepalived_vrrp[424]: VRRP_Instance(vi_1) Entering BACKUP STATE
Aug 21 13:59:29 192_168_173_203 Keepalived_vrrp[424]: VRRP_Instance(vi_1) removing protocol VIPs.
Aug 21 13:59:29 192_168_173_203 Keepalived_healthcheckers[423]: Netlink reflector reports IP 172.16.173.100 removed

当我把192.168.173.204的nag.var调成1, nag.sh脚本检查失败, 日志如下
Aug 21 13:59:43 192_168_173_204 Keepalived_vrrp[13887]: VRRP_Script(nag) failed

但是不影响 192.168.173.204的优先级, 所以它还是master.
[root@192_168_173_204 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr F4:CE:46:85:15:FC  
          inet addr:192.168.173.204  Bcast:192.168.173.255  Mask:255.255.255.0
          inet6 addr: fe80::f6ce:46ff:fe85:15fc/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:10360595 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4714379 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1469576774 (1.3 GiB)  TX bytes:661681617 (631.0 MiB)

eth0:1    Link encap:Ethernet  HWaddr F4:CE:46:85:15:FC  
          inet addr:172.16.173.100  Bcast:172.16.173.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:163476 errors:0 dropped:0 overruns:0 frame:0
          TX packets:163476 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:8835522 (8.4 MiB)  TX bytes:8835522 (8.4 MiB)


[参考]
动态调整优先级的范围 : 
如果配置的instance的初始优先级是255的话, 则不受track weight的影响. 见vrrp_update_priority函数的内容.
	if (vrrp->base_priority == VRRP_PRIO_OWNER) {
		/* we will not run a PRIO_OWNER into a non-PRIO_OWNER */
		vrrp->effective_priority = VRRP_PRIO_OWNER;
	} else {
		/* WARNING! we must compute new_prio on a signed int in order
		   to detect overflows and avoid wrapping. */
		new_prio = vrrp->base_priority + prio_offset;
		if (new_prio < 1)
			new_prio = 1;
		else if (new_prio > 254)
			new_prio = 254;
		vrrp->effective_priority = new_prio;
	}

keepalived / include / vrrp.h
#define VRRP_PRIO_OWNER		255		/* priority of the ip owner -- rfc2338.5.3.4 */

换句话说, 只有初始优先级配置<255的instance, 才可以动态调整优先级. 并且动态调整后的优先级范围是1到254.
    priority <INTEGER-0..255>		# VRRP PRIO

目录
相关文章
|
Python
【Python 自动化】小说推文一键生成思路概述
【Python 自动化】小说推文一键生成思路概述
476 0
|
Kubernetes API 调度
【k8s系列5】KubernetesClientException: too old resource version 原因分析
【k8s系列5】KubernetesClientException: too old resource version 原因分析
2025 0
|
存储 固态存储 数据库
|
移动开发 JSON Kubernetes
k8s异常诊断之no space left on device.
某用户反馈,特定节点一直拉不起来pod,提示no space left on device.,手动去docker run也是相同的报错 # docker run --name aestools-perf --cap-add CAP_SYS_ADMIN --privileged -ti --rm registry-vpc.cn-beijing.aliyuncs.com/my-nettools/aestools:onlyperf docker: Error response from daemon: error creating overlay mount to /var/li
3736 135
|
存储 运维 Kubernetes
Kubernetes HPA 的三个误区与避坑指南
云计算带来的优势之一便是弹性能力,云原生场景下Kubernetes提供了水平弹性扩容能力(HPA),让应用可以随着实时指标进行扩/缩。然而HPA的实际工作情况可能和我们直观预想的情况是不一样的,这里面存在一些认知误区。本文总结了一下 EDAS 用户在使用 HPA 时常遇到的三个认知误区
3066 103
Kubernetes HPA 的三个误区与避坑指南
|
监控 前端开发 Java
6个顶级SpringCloud微服务开源项目
6个顶级SpringCloud微服务开源项目
1476 5
|
Kubernetes 监控 Shell
在K8S中,我们公司用户反应pod连接数非常多,希望看一下这些连接都是什么信息?什么状态?怎么排查?容器里面没有集成bash环境、网络工具,怎么处理?
在K8S中,我们公司用户反应pod连接数非常多,希望看一下这些连接都是什么信息?什么状态?怎么排查?容器里面没有集成bash环境、网络工具,怎么处理?
|
应用服务中间件 测试技术 Linux
|
编解码 物联网 异构计算
基于 PPDiffusers 训练DreamBooth LoRA微调生成中国山水画风格【livingbody/Chinese_ShanShui_Style】
基于 PPDiffusers 训练DreamBooth LoRA微调生成中国山水画风格【livingbody/Chinese_ShanShui_Style】
1088 0