2025年nagtive for mysql 打开远程链接_keepalived vrrp script-interface weight when positive,nagtive,zero & vrrp's...

nagtive for mysql 打开远程链接_keepalived vrrp script-interface weight when positive,nagtive,zero & vrrp's...同时虚拟 IP 切换到了本节点 Aug 20 16 38 30 192 168 173 203 Keepalived vrrp 23110 VRRP Instance vi 1 forcing a new MASTER election Aug 20 16 38 30 192 168 173 203 Keepalived vrrp 23110

大家好,我是讯享网,很高兴认识大家。

同时虚拟IP切换到了本节点

Aug 20 16:38:30 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) forcing a new MASTER election

Aug 20 16:38:30 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) forcing a new MASTER election

Aug 20 16:38:31 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) Transition to MASTER STATE

Aug 20 16:38:32 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) Entering MASTER STATE

Aug 20 16:38:32 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) setting protocol VIPs.

Aug 20 16:38:32 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100

Aug 20 16:38:32 192_168_173_203 Keepalived_healthcheckers[23109]: Netlink reflector reports IP 172.16.173.100 added

Aug 20 16:38:37 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100

查看192.168.173.204节点的日志, 选举为BACKUP后, 移除了虚拟IP.Aug 20 16:38:08 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Transition to MASTER STATE

Aug 20 16:38:09 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Entering MASTER STATE

Aug 20 16:38:09 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) setting protocol VIPs.

Aug 20 16:38:09 192_168_173_204 Keepalived_healthcheckers[5922]: Netlink reflector reports IP 172.16.173.100 added

Aug 20 16:38:09 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100

Aug 20 16:38:14 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100

Aug 20 16:38:29 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Received lower prio advert, forcing new election

Aug 20 16:38:29 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100

Aug 20 16:38:29 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Received lower prio advert, forcing new election

Aug 20 16:38:29 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100

Aug 20 16:38:30 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Received higher prio advert

Aug 20 16:38:30 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Entering BACKUP STATE

Aug 20 16:38:30 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) removing protocol VIPs.

Aug 20 16:38:30 192_168_173_204 Keepalived_healthcheckers[5922]: Netlink reflector reports IP 172.16.173.100 removed

现在我们把192.168.173.203的pos.var改成1, 那么将降回初始优先级100. 比192.168.173.204的优先级102要低.[root@192_168_173_203 ~]# echo 1 > /root/pos.var

我们在192.168.173.204节点可以看到它重新选举变成了MASTERAug 20 16:44:43 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) forcing a new MASTER election

Aug 20 16:44:43 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) forcing a new MASTER election

Aug 20 16:44:44 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Transition to MASTER STATE

Aug 20 16:44:45 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Entering MASTER STATE

Aug 20 16:44:45 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) setting protocol VIPs.

Aug 20 16:44:45 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100

Aug 20 16:44:45 192_168_173_204 Keepalived_healthcheckers[5922]: Netlink reflector reports IP 172.16.173.100 added

Aug 20 16:44:50 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100

接下来在192.168.173.204测试一下nag.sh脚本, 把nag.var改成1. 那么nag.sh将返回1, 也就是失败. 优先级需要减5. 变成102-5=97, vrrp重新选举的话, 变成BACKUP.[root@192_168_173_204 ~]# echo 1 > /root/nag.var

我们在192.168.173.203上可以看到它选举变成了master.Aug 20 16:48:04 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) forcing a new MASTER election

Aug 20 16:48:04 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) forcing a new MASTER election

Aug 20 16:48:05 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) Transition to MASTER STATE

Aug 20 16:48:06 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) Entering MASTER STATE

Aug 20 16:48:06 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) setting protocol VIPs.

Aug 20 16:48:06 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100

Aug 20 16:48:06 192_168_173_203 Keepalived_healthcheckers[23109]: Netlink reflector reports IP 172.16.173.100 added

Aug 20 16:48:11 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100

现在的优先级构成如下 :192.168.173.203 MASTER

base=100

pos.sh failed +0

zero.sh success

nag.sh success -0


讯享网

最终优先级: 100

192.168.173.204 BACKUP

base=99

pos.sh success + 3

zero.sh success

nag.sh failed -5

最终优先级: 97

接下来把192.168.173.203的nag.sh弄成failed, 那么将再次减5, 变成95. 选举将变成BACKUP.[root@192_168_173_203 ~]# echo 1 > /root/nag.var

可以看到192.168.173.204变成MASTER了.Aug 20 16:52:29 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) forcing a new MASTER election

Aug 20 16:52:29 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) forcing a new MASTER election

Aug 20 16:52:30 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Transition to MASTER STATE

Aug 20 16:52:31 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Entering MASTER STATE

Aug 20 16:52:31 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) setting protocol VIPs.

Aug 20 16:52:31 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100

Aug 20 16:52:31 192_168_173_204 Keepalived_healthcheckers[5922]: Netlink reflector reports IP 172.16.173.100 added

最后测试一下zero脚本对状态的影响, 前面我们看到的nag.sh和pos.sh都只改变优先级, 不会直接对状态造成影响, 而是在选举的过程中简介的对状态造成的影响.

zero脚本的weight=0, 所以脚本调用的成功与否直接影响vrrp instance的状态

测试 :

把192.168.173.204的zero.var改成1,

[root@192_168_173_204 ~]# echo 1 >/root/zero.var

查看日志 :Aug 20 16:54:49 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Script(zero) failed

Aug 20 16:54:50 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Entering FAULT STATE

Aug 20 16:54:50 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) removing protocol VIPs.

Aug 20 16:54:50 192_168_173_204 Keepalived_healthcheckers[5922]: Netlink reflector reports IP 172.16.173.100 removed

Aug 20 16:54:50 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Now in FAULT state

192.168.173.203变成了唯一的状态正常的主机, 所以理所当然就是MASTER了.Aug 20 16:54:50 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) Transition to MASTER STATE

Aug 20 16:54:51 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) Entering MASTER STATE

Aug 20 16:54:51 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) setting protocol VIPs.

Aug 20 16:54:51 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100

Aug 20 16:54:51 192_168_173_203 Keepalived_healthcheckers[23109]: Netlink reflector reports IP 172.16.173.100 added

Aug 20 16:54:56 192_168_173_203 Keepalived_vrrp[23110]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100

最后, 把zero.var改回0, 观察状态回到配置的初始状态. 并重新选举.

[root@192_168_173_204 ~]# echo 0 >/root/zero.var

重新选举的过程中依然是先使用初始优先级进行选举, 状态定了以后, 再检查脚本, 动态的改变优先级.

本例192.168.173.204的初始优先级是99, 大于当前192.168.173.203的优先级95, 所以初始优先级就可以当选MASTER.

等检测开始后, 优先级变成99+3-5=97, 依然大于当前192.168.173.203的优先级95, 所以继续MASTER.Aug 20 17:02:05 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Script(zero) succeeded

Aug 20 17:02:06 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) prio is higher than received advert

Aug 20 17:02:06 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Transition to MASTER STATE

Aug 20 17:02:06 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Received lower prio advert, forcing new election

Aug 20 17:02:07 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Entering MASTER STATE

Aug 20 17:02:07 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) setting protocol VIPs.

Aug 20 17:02:07 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100

Aug 20 17:02:07 192_168_173_204 Keepalived_healthcheckers[5922]: Netlink reflector reports IP 172.16.173.100 added

Aug 20 17:02:12 192_168_173_204 Keepalived_vrrp[5923]: VRRP_Instance(vi_1) Sending gratuitous ARPs on eth0 for 172.16.173.100

[参考]

小讯
上一篇 2025-02-21 13:31
下一篇 2025-01-26 20:51

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/72263.html