搭建keepalived遇到的问题
主机192.168.100.10
备机192.168.100.20
VIP192.168.100.30
一.防火墙开启后双机都是master。
在搭建之后开启防火墙发现双机日志都是MASTER
Aug :: localhost Keepalived_vrrp[]: VRRP_Instance(VI_1) Transition to MASTER STATE
Aug :: localhost Keepalived_vrrp[]: VRRP_Instance(VI_1) Entering MASTER STATE
Aug :: localhost Keepalived_vrrp[]: VRRP_Instance(VI_1) setting protocol VIPs.
Aug :: localhost Keepalived_vrrp[]: VRRP_Instance(VI_1) Sending gratuitous ARPs on em1 for 192.168.100.30
Aug :: localhost Keepalived_healthcheckers[]: Netlink reflector reports IP 192.168.100.30 added
Aug :: localhost Keepalived_vrrp[]: VRRP_Instance(VI_1) Sending gratuitous ARPs on em1 for 192.168.100.30
通过查看VRRP通信原理发现VRRP基于报文实现的。master设置一定时间发送一个报文给backup如果backup没有收到就自己成为master。可推出导致问题的原因是因为backup没有收到文
所以自己成为了master。
VRRP控制报文只有一种:VRRP通告(advertisement)。它使用IP多播数据包进行封装,组地址为224.0.0.18,发布范围只限于同一局域网内。这保证了VRID在不同网络中可以重复使用。为了减少网络带宽消耗只有主控路由器才可以周期性的发送VRRP通告报文。备份路由器在连续三个通告间隔内收不到VRRP或收到优先级为0的通告后启动新的一轮VRRP选举。
vrrp_instance VI_1 {
state BACKUP
interface em1
virtual_router_id
priority
advert_int 1 #VRRP报文的发送间隔
authentication {
auth_type PASS
auth_pass admin
}
virtual_ipaddress {
192.168.100.30 dev em1
}
在iptables上设置。
vim /etc/sysconfig/iptables
添加-A INPUT -p vrrp -j ACCEPT