keepalived Transition & Entering {MASTER|BACKUP|FAULT} STATE & first priority affect by track interface|script

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介:
本例主要说明1个问题, 当使用脚本或接口的动态优先级调整时, 什么时候优先级会生效.

路由器进入状态后, 动态优先级才会被调整, 没有进入状态前的track都不会影响优先级.
用两个例子来说明问题.
并且初始状态为MASTER和BACKUP, track的先后是有差别的.
如果初始状态时MASTER, 那么是先执行track(此时的脚本调用结果不影响路由器优先级), 然后Transition to MASTER STATE. 
如果初始状态是BACKUP, 那么是先Entering to BACKUP STATE, 然后执行脚本 (此时的脚本调用结果会影响路由器优先级) .

例子1 :
route A : BACKUP, priority=99, track_script+3 weight, !nopreempt
route B : MASTER, priority=100, track_script+3 weight, !nopreempt

先启动A, 
keepalived -f /opt/keepalived/etc/keepalived/keepalived.conf -D
日志 :
Aug 25 15:21:35 192_168_173_203 Keepalived[25763]: Starting Keepalived v1.2.13 (08/19,2014)
Aug 25 15:21:35 192_168_173_203 Keepalived[25764]: Starting Healthcheck child process, pid=25765
Aug 25 15:21:35 192_168_173_203 Keepalived[25764]: Starting VRRP child process, pid=25766
Aug 25 15:21:35 192_168_173_203 Keepalived_vrrp[25766]: Netlink reflector reports IP 192.168.173.203 added
Aug 25 15:21:35 192_168_173_203 Keepalived_vrrp[25766]: Netlink reflector reports IP 192.168.173.156 added
Aug 25 15:21:35 192_168_173_203 Keepalived_vrrp[25766]: Netlink reflector reports IP fe80::f6ce:46ff:fe86:4234 added
Aug 25 15:21:35 192_168_173_203 Keepalived_vrrp[25766]: Registering Kernel netlink reflector
Aug 25 15:21:35 192_168_173_203 Keepalived_healthcheckers[25765]: Netlink reflector reports IP 192.168.173.203 added
Aug 25 15:21:35 192_168_173_203 Keepalived_healthcheckers[25765]: Netlink reflector reports IP 192.168.173.156 added
Aug 25 15:21:35 192_168_173_203 Keepalived_vrrp[25766]: Registering Kernel netlink command channel
Aug 25 15:21:35 192_168_173_203 Keepalived_healthcheckers[25765]: Netlink reflector reports IP fe80::f6ce:46ff:fe86:4234 added
Aug 25 15:21:35 192_168_173_203 Keepalived_vrrp[25766]: Registering gratuitous ARP shared channel
Aug 25 15:21:35 192_168_173_203 Keepalived_healthcheckers[25765]: Registering Kernel netlink reflector
Aug 25 15:21:35 192_168_173_203 Keepalived_healthcheckers[25765]: Registering Kernel netlink command channel
Aug 25 15:21:35 192_168_173_203 Keepalived_healthcheckers[25765]: Opening file '/opt/keepalived/etc/keepalived/keepalived.conf'.
Aug 25 15:21:35 192_168_173_203 Keepalived_vrrp[25766]: Opening file '/opt/keepalived/etc/keepalived/keepalived.conf'.
Aug 25 15:21:35 192_168_173_203 Keepalived_healthcheckers[25765]: Configuration is using : 7942 Bytes
Aug 25 15:21:35 192_168_173_203 Keepalived_vrrp[25766]: Configuration is using : 69324 Bytes
Aug 25 15:21:35 192_168_173_203 Keepalived_vrrp[25766]: Using LinkWatch kernel netlink reflector...
注意用词Entering, 是进入BACKUP状态, 而不是向BACKUP状态转变.
Aug 25 15:21:35 192_168_173_203 Keepalived_vrrp[25766]: VRRP_Instance(vi_1) Entering BACKUP STATE
Aug 25 15:21:35 192_168_173_203 Keepalived_vrrp[25766]: VRRP sockpool: [ifindex(2), proto(112), unicast(1), fd(10,11)]
Aug 25 15:21:35 192_168_173_203 Keepalived_healthcheckers[25765]: Using LinkWatch kernel netlink reflector...
Aug 25 15:21:35 192_168_173_203 Keepalived_vrrp[25766]: VRRP_Script(nag) succeeded
Aug 25 15:21:35 192_168_173_203 Keepalived_vrrp[25766]: VRRP_Script(zero) succeeded
Aug 25 15:21:35 192_168_173_203 Keepalived_vrrp[25766]: VRRP_Script(pos) succeeded
优先级99+3=102
Aug 25 15:21:39 192_168_173_203 Keepalived_vrrp[25766]: VRRP_Instance(vi_1) Transition to MASTER STATE
Aug 25 15:21:40 192_168_173_203 Keepalived_vrrp[25766]: VRRP_Instance(vi_1) Entering MASTER STATE
Aug 25 15:21:40 192_168_173_203 Keepalived_vrrp[25766]: VRRP_Instance(vi_1) setting protocol VIPs.
Aug 25 15:21:40 192_168_173_203 Keepalived_vrrp[25766]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100
Aug 25 15:21:40 192_168_173_203 Keepalived_healthcheckers[25765]: Netlink reflector reports IP 172.16.173.100 added

再启动B, 
keepalived -f /opt/keepalived/etc/keepalived/keepalived.conf -D
日志 :
Aug 25 15:26:27 192_168_173_204 Keepalived[8192]: Starting Keepalived v1.2.13 (08/19,2014)
Aug 25 15:26:27 192_168_173_204 Keepalived[8193]: Starting Healthcheck child process, pid=8194
Aug 25 15:26:27 192_168_173_204 Keepalived[8193]: Starting VRRP child process, pid=8196
Aug 25 15:26:27 192_168_173_204 Keepalived_vrrp[8196]: Netlink reflector reports IP 192.168.173.204 added
Aug 25 15:26:27 192_168_173_204 Keepalived_vrrp[8196]: Netlink reflector reports IP fe80::f6ce:46ff:fe85:15fc added
Aug 25 15:26:27 192_168_173_204 Keepalived_vrrp[8196]: Registering Kernel netlink reflector
Aug 25 15:26:27 192_168_173_204 Keepalived_healthcheckers[8194]: Netlink reflector reports IP 192.168.173.204 added
Aug 25 15:26:27 192_168_173_204 Keepalived_healthcheckers[8194]: Netlink reflector reports IP fe80::f6ce:46ff:fe85:15fc added
Aug 25 15:26:27 192_168_173_204 Keepalived_vrrp[8196]: Registering Kernel netlink command channel
Aug 25 15:26:27 192_168_173_204 Keepalived_vrrp[8196]: Registering gratuitous ARP shared channel
Aug 25 15:26:27 192_168_173_204 Keepalived_healthcheckers[8194]: Registering Kernel netlink reflector
Aug 25 15:26:27 192_168_173_204 Keepalived_healthcheckers[8194]: Registering Kernel netlink command channel
Aug 25 15:26:27 192_168_173_204 Keepalived_healthcheckers[8194]: Opening file '/opt/keepalived/etc/keepalived/keepalived.conf'.
Aug 25 15:26:27 192_168_173_204 Keepalived_vrrp[8196]: Opening file '/opt/keepalived/etc/keepalived/keepalived.conf'.
Aug 25 15:26:27 192_168_173_204 Keepalived_healthcheckers[8194]: Configuration is using : 7944 Bytes
Aug 25 15:26:27 192_168_173_204 Keepalived_vrrp[8196]: Configuration is using : 69326 Bytes
Aug 25 15:26:27 192_168_173_204 Keepalived_vrrp[8196]: Using LinkWatch kernel netlink reflector...
Aug 25 15:26:27 192_168_173_204 Keepalived_vrrp[8196]: VRRP sockpool: [ifindex(2), proto(112), unicast(1), fd(10,11)]
Aug 25 15:26:27 192_168_173_204 Keepalived_healthcheckers[8194]: Using LinkWatch kernel netlink reflector...
Aug 25 15:26:27 192_168_173_204 Keepalived_vrrp[8196]: VRRP_Script(pos) succeeded
Aug 25 15:26:27 192_168_173_204 Keepalived_vrrp[8196]: VRRP_Script(zero) succeeded
Aug 25 15:26:27 192_168_173_204 Keepalived_vrrp[8196]: VRRP_Script(nag) succeeded
注意用词Transition, 表示现在还不是master, 像master角色转换而已. 转换过程要干些什么, 参考rfc2338.
Aug 25 15:26:28 192_168_173_204 Keepalived_vrrp[8196]: VRRP_Instance(vi_1) Transition to MASTER STATE
Aug 25 15:26:28 192_168_173_204 Keepalived_vrrp[8196]: VRRP_Instance(vi_1) Received higher prio advert
第一次竞选MASTER失败, 说明现在track script虽然执行成功了, 但是没有动态变更优先级, 目前优先级还是100
Aug 25 15:26:28 192_168_173_204 Keepalived_vrrp[8196]: VRRP_Instance(vi_1) Entering BACKUP STATE
第二次竞选成功, 说明已动态变更优先级. 目前优先级100+3=103
Aug 25 15:26:29 192_168_173_204 Keepalived_vrrp[8196]: VRRP_Instance(vi_1) forcing a new MASTER election
Aug 25 15:26:29 192_168_173_204 Keepalived_vrrp[8196]: VRRP_Instance(vi_1) forcing a new MASTER election
Aug 25 15:26:30 192_168_173_204 Keepalived_vrrp[8196]: VRRP_Instance(vi_1) Transition to MASTER STATE
Aug 25 15:26:31 192_168_173_204 Keepalived_vrrp[8196]: VRRP_Instance(vi_1) Entering MASTER STATE
Aug 25 15:26:31 192_168_173_204 Keepalived_vrrp[8196]: VRRP_Instance(vi_1) setting protocol VIPs.
Aug 25 15:26:31 192_168_173_204 Keepalived_vrrp[8196]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100
Aug 25 15:26:31 192_168_173_204 Keepalived_healthcheckers[8194]: Netlink reflector reports IP 172.16.173.100 added


例子2 : 
route A : BACKUP, priority=100, track_script+3 weight, !nopreempt
route B : MASTER, priority=99, track_script+3 weight, !nopreempt

先启动B, 
keepalived -f /opt/keepalived/etc/keepalived/keepalived.conf -D
日志如下 :
Aug 25 15:31:12 192_168_173_204 Keepalived[10659]: Starting Keepalived v1.2.13 (08/19,2014)
Aug 25 15:31:12 192_168_173_204 Keepalived[10660]: Starting Healthcheck child process, pid=10661
Aug 25 15:31:12 192_168_173_204 Keepalived[10660]: Starting VRRP child process, pid=10663
Aug 25 15:31:12 192_168_173_204 Keepalived_vrrp[10663]: Netlink reflector reports IP 192.168.173.204 added
Aug 25 15:31:12 192_168_173_204 Keepalived_vrrp[10663]: Netlink reflector reports IP fe80::f6ce:46ff:fe85:15fc added
Aug 25 15:31:12 192_168_173_204 Keepalived_vrrp[10663]: Registering Kernel netlink reflector
Aug 25 15:31:12 192_168_173_204 Keepalived_healthcheckers[10661]: Netlink reflector reports IP 192.168.173.204 added
Aug 25 15:31:12 192_168_173_204 Keepalived_vrrp[10663]: Registering Kernel netlink command channel
Aug 25 15:31:12 192_168_173_204 Keepalived_healthcheckers[10661]: Netlink reflector reports IP fe80::f6ce:46ff:fe85:15fc added
Aug 25 15:31:12 192_168_173_204 Keepalived_vrrp[10663]: Registering gratuitous ARP shared channel
Aug 25 15:31:12 192_168_173_204 Keepalived_healthcheckers[10661]: Registering Kernel netlink reflector
Aug 25 15:31:12 192_168_173_204 Keepalived_healthcheckers[10661]: Registering Kernel netlink command channel
Aug 25 15:31:12 192_168_173_204 Keepalived_healthcheckers[10661]: Opening file '/opt/keepalived/etc/keepalived/keepalived.conf'.
Aug 25 15:31:12 192_168_173_204 Keepalived_vrrp[10663]: Opening file '/opt/keepalived/etc/keepalived/keepalived.conf'.
Aug 25 15:31:12 192_168_173_204 Keepalived_healthcheckers[10661]: Configuration is using : 7942 Bytes
Aug 25 15:31:12 192_168_173_204 Keepalived_vrrp[10663]: Configuration is using : 69324 Bytes
Aug 25 15:31:12 192_168_173_204 Keepalived_vrrp[10663]: Using LinkWatch kernel netlink reflector...
Aug 25 15:31:12 192_168_173_204 Keepalived_vrrp[10663]: VRRP sockpool: [ifindex(2), proto(112), unicast(1), fd(10,11)]
Aug 25 15:31:12 192_168_173_204 Keepalived_healthcheckers[10661]: Using LinkWatch kernel netlink reflector...
Aug 25 15:31:12 192_168_173_204 Keepalived_vrrp[10663]: VRRP_Script(pos) succeeded
Aug 25 15:31:12 192_168_173_204 Keepalived_vrrp[10663]: VRRP_Script(nag) succeeded
Aug 25 15:31:12 192_168_173_204 Keepalived_vrrp[10663]: VRRP_Script(zero) succeeded
现在的优先级是99
Aug 25 15:31:13 192_168_173_204 Keepalived_vrrp[10663]: VRRP_Instance(vi_1) Transition to MASTER STATE
Aug 25 15:31:14 192_168_173_204 Keepalived_vrrp[10663]: VRRP_Instance(vi_1) Entering MASTER STATE
现在的优先级是99+3=102
Aug 25 15:31:14 192_168_173_204 Keepalived_vrrp[10663]: VRRP_Instance(vi_1) setting protocol VIPs.
Aug 25 15:31:14 192_168_173_204 Keepalived_vrrp[10663]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100
Aug 25 15:31:14 192_168_173_204 Keepalived_healthcheckers[10661]: Netlink reflector reports IP 172.16.173.100 added


然后启动A, 
keepalived -f /opt/keepalived/etc/keepalived/keepalived.conf -D
日志如下 :
Aug 25 15:32:11 192_168_173_203 Keepalived[8306]: Starting Keepalived v1.2.13 (08/19,2014)
Aug 25 15:32:11 192_168_173_203 Keepalived[8307]: Starting Healthcheck child process, pid=8308
Aug 25 15:32:11 192_168_173_203 Keepalived[8307]: Starting VRRP child process, pid=8309
Aug 25 15:32:11 192_168_173_203 Keepalived_vrrp[8309]: Netlink reflector reports IP 192.168.173.203 added
Aug 25 15:32:11 192_168_173_203 Keepalived_vrrp[8309]: Netlink reflector reports IP 192.168.173.156 added
Aug 25 15:32:11 192_168_173_203 Keepalived_vrrp[8309]: Netlink reflector reports IP fe80::f6ce:46ff:fe86:4234 added
Aug 25 15:32:11 192_168_173_203 Keepalived_vrrp[8309]: Registering Kernel netlink reflector
Aug 25 15:32:11 192_168_173_203 Keepalived_healthcheckers[8308]: Netlink reflector reports IP 192.168.173.203 added
Aug 25 15:32:11 192_168_173_203 Keepalived_vrrp[8309]: Registering Kernel netlink command channel
Aug 25 15:32:11 192_168_173_203 Keepalived_healthcheckers[8308]: Netlink reflector reports IP 192.168.173.156 added
Aug 25 15:32:11 192_168_173_203 Keepalived_vrrp[8309]: Registering gratuitous ARP shared channel
Aug 25 15:32:11 192_168_173_203 Keepalived_healthcheckers[8308]: Netlink reflector reports IP fe80::f6ce:46ff:fe86:4234 added
Aug 25 15:32:11 192_168_173_203 Keepalived_healthcheckers[8308]: Registering Kernel netlink reflector
Aug 25 15:32:11 192_168_173_203 Keepalived_healthcheckers[8308]: Registering Kernel netlink command channel
Aug 25 15:32:11 192_168_173_203 Keepalived_healthcheckers[8308]: Opening file '/opt/keepalived/etc/keepalived/keepalived.conf'.
Aug 25 15:32:11 192_168_173_203 Keepalived_vrrp[8309]: Opening file '/opt/keepalived/etc/keepalived/keepalived.conf'.
Aug 25 15:32:11 192_168_173_203 Keepalived_healthcheckers[8308]: Configuration is using : 7944 Bytes
Aug 25 15:32:11 192_168_173_203 Keepalived_vrrp[8309]: Configuration is using : 69326 Bytes
Aug 25 15:32:11 192_168_173_203 Keepalived_vrrp[8309]: Using LinkWatch kernel netlink reflector...
Aug 25 15:32:11 192_168_173_203 Keepalived_vrrp[8309]: VRRP_Instance(vi_1) Entering BACKUP STATE
注意现在的状态是进入BACKUP STATE, 
Aug 25 15:32:11 192_168_173_203 Keepalived_vrrp[8309]: VRRP sockpool: [ifindex(2), proto(112), unicast(1), fd(10,11)]
Aug 25 15:32:11 192_168_173_203 Keepalived_healthcheckers[8308]: Using LinkWatch kernel netlink reflector...
Aug 25 15:32:11 192_168_173_203 Keepalived_vrrp[8309]: VRRP_Script(pos) succeeded
Aug 25 15:32:11 192_168_173_203 Keepalived_vrrp[8309]: VRRP_Script(nag) succeeded
Aug 25 15:32:11 192_168_173_203 Keepalived_vrrp[8309]: VRRP_Script(zero) succeeded
第一次竞选MASTER成功, 说明Entering后, 脚本执行完后, 动态调整了priority. 现在的优先级是100+3=103
Aug 25 15:32:12 192_168_173_203 Keepalived_vrrp[8309]: VRRP_Instance(vi_1) forcing a new MASTER election
Aug 25 15:32:12 192_168_173_203 Keepalived_vrrp[8309]: VRRP_Instance(vi_1) forcing a new MASTER election
Aug 25 15:32:13 192_168_173_203 Keepalived_vrrp[8309]: VRRP_Instance(vi_1) Transition to MASTER STATE
Aug 25 15:32:14 192_168_173_203 Keepalived_vrrp[8309]: VRRP_Instance(vi_1) Entering MASTER STATE
Aug 25 15:32:14 192_168_173_203 Keepalived_vrrp[8309]: VRRP_Instance(vi_1) setting protocol VIPs.
Aug 25 15:32:14 192_168_173_203 Keepalived_healthcheckers[8308]: Netlink reflector reports IP 172.16.173.100 added
Aug 25 15:32:14 192_168_173_203 Keepalived_vrrp[8309]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100


路由器进入状态后, 动态优先级才会被调整. 没有进入状态前的track都不会影响优先级.

[参考]
1. keepalived src
相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
目录
相关文章
|
6月前
Failed to start LVS and VRRP High Availability Monitor.
Failed to start LVS and VRRP High Availability Monitor.
140 1
|
6月前
|
JavaScript
【报错】onMounted is called when there is no active component instance too be associated with.
【报错】onMounted is called when there is no active component instance too be associated with.
411 4
|
C语言
解决Dev-C++ [Error] ‘for‘ loop initial declarations are only allowed in C99 or C11 mode
Dev-C++ [Error] ‘for‘ loop initial declarations are only allowed in C99 or C11 mode
767 0
解决Dev-C++ [Error] ‘for‘ loop initial declarations are only allowed in C99 or C11 mode
‘Client‘ is not allowed to run in parallel.Would you like to stop the running one?
‘Client‘ is not allowed to run in parallel.Would you like to stop the running one?
567 0
‘Client‘ is not allowed to run in parallel.Would you like to stop the running one?
|
网络安全 数据安全/隐私保护 数据格式