【Keepalived 】keepalived check and notify scripts

大家知道keepalived会有四种状态的变化,每种状态变化时,都可以调用一个脚本

当进入Master状态时会呼叫notify_master

当进入Backup状态时会呼叫notify_backup

当发现异常情况时进入Fault状态呼叫notify_fault

当Keepalived程序终止时则呼叫notify_stop

进入Master和Backup这两种状态很容易理解了,就是分别变为主和从

进入Fault,简单的说就是keepalived发现自己有问题了,不能能再去参与Master竞选了,你得修好他才行。

进入这种状态一般是keepalived自身出问题了,或者keepalived检测的网卡出问题不通了,再或者就是我们自己写的检测业务的脚本返回错误

进入Stop 这个就容易理解了,执行service keepalived stop 或者 systemctl stop keepalived  就会进入这个状态。

设置selinux为宽松模式

# setenforce 0

# sed -i ‘s/^SELINUX=.*/SELINUX=permissive/g’   /etc/selinux/config

CentOS防火墙默认是不允许keepalived使用 vrrp的组播。

如果不开启组播ip,keepalived双机不能实现热备的效果,只能实现负载的效果,即虚拟ip不能实现漂移 。

Check that the multicast IP and protocol for VRRP are allowed in the firewall on both servers. 

For firewalld:

添加规则

# firewall-cmd –direct –permanent–add-rule ipv4 filterINPUT     0     –in-interface eth0   –destination 224.0.0.18 –protocol vrrp -j ACCEPT

# firewall-cmd –direct –permanent–add-ruleipv4 filterOUTPUT 0    –out-interface eth0  –destination 224.0.0.18 –protocol vrrp -j ACCEPT

# firewall-cmd –reload

删除规则

# firewall-cmd –direct –permanent–remove-ruleipv4 filterINPUT     0     –in-interface eth0   –destination 224.0.0.18 –protocol vrrp -j ACCEPT

# firewall-cmd –direct –permanent–remove-rule ipv4 filterOUTPUT 0    –out-interface eth0  –destination 224.0.0.18 –protocol vrrp -j ACCEPT

# firewall-cmd –reload

For iptables:

添加规则

# iptables -A INPUT -p vrrp -j ACCEPT

# iptables -A OUTPUT -p vrrp -j ACCEPT

# service iptables save

删除规则

# iptables  -D  INPUT -p vrrp -j ACCEPT

# iptables  -D OUTPUT -p vrrp -j ACCEPT

# service iptables save

keepalived基本应用解析

http://blog.51cto.com/pangge/1301878

keepalived官方文档

http://www.keepalived.org/doc/introduction.html

使用keepalived实现redis的故障切换

http://peiqiang.net/2014/11/21/keepalived-and-redis.html

Kamailio High Availability Done Right with Keepalived

http://blog.unicsolution.com/2015/01/kamailio-high-availability-with.html

Keepalived Check and Notify Scripts

https://tobrunet.ch/keepalived-check-and-notify-scripts

    原文作者:MissHandsome
    原文地址: https://www.jianshu.com/p/751497652110
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞