Keepalived+Redis双机热备无法正确绑定VIP,Keepalived VRRP_Instance(VI_1) Now in FAULT state

wzrlover 2014-12-07 08:50:10
Ubuntu14.04 + Keepalived1.2.13

172.18.8.74 (master,vip:172.18.8.100)
172.18.8.73 (slave,vip:172.18.8.100)

通过keepalived 实现redis主从备份零切换

keepalived.conf配置文件,如下:

! Configuration File for keepalived

global_defs {
router_id ubuntu-lvs-74
}

vrrp_script chk_redis {
script "/etc/keepalived/scripts/redis_check.sh"
interval 2
}

vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 101 # 备机 优先级为100

authentication {
auth_type PASS
auth_pass redis
}

track_script {
chk_redis
}

virtual_ipaddress {
172.18.8.100/32
}

notify_master /etc/keepalived/scripts/redis_master.sh
notify_backup /etc/keepalived/scripts/redis_backup.sh
notify_fault /etc/keepalived/scripts/redis_fault.sh
notify_stop /etc/keepalived/scripts/redis_stop.sh

}

virtual_server 172.18.8.100 6379 {
delay_loop 1
lb_algo rr
lb_kind DR #NAT
#nat_mask 255.255.255.255
persistence_timeout 50
protocol TCP

real_server 172.18.8.74 6379 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 6379
}
}

real_server 172.18.8.73 6379 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 6379
}
}
}

正确的结果应该是:
当前启动主keepalived时候,虚拟主机IP应该被主机监听绑定,备机不绑定虚拟IP;当主机keepalived宕掉时,备机进行绑定VIP

1、为什么我keepalived主备都会监听虚拟IP?
#sudo ip a
都是输出:
root@ubuntu-lvs-74:/opt/lvs# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet 172.18.8.100/32 brd 172.18.8.100 scope global lo:0
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
/etc/sysctl.conf 设置了:
net.ipv4.ip_nonlocal_bind = 1

VIP设置如下,ifconfig:

root@ubuntu-lvs-74:/opt/lvs# ifconfig
eth0 Link encap:Ethernet HWaddr 52:54:00:ee:21:49
inet addr:172.18.8.74 Bcast:172.18.8.127 Mask:255.255.255.128
inet6 addr: fe80::5054:ff:feee:2149/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3038779 errors:0 dropped:1356 overruns:0 frame:0
TX packets:564682 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:155424872 (155.4 MB) TX bytes:39263783 (39.2 MB)

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:65536 Metric:1
RX packets:703904 errors:0 dropped:0 overruns:0 frame:0
TX packets:703904 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:39418624 (39.4 MB) TX bytes:39418624 (39.4 MB)

lo:0 Link encap:Local Loopback
inet addr:172.18.8.100 Mask:255.255.255.255
UP LOOPBACK RUNNING MTU:65536 Metric:1
请教,这是哪里出了问题了?

2、keepalived启动后,出现VRRP_Instance(VI_1) Now in FAULT state

Dec 6 21:01:43 ubuntu-lvs-74 Keepalived_healthcheckers[9801]: Netlink reflector reports IP fe80::5054:ff:feee:2149 added
Dec 6 21:01:43 ubuntu-lvs-74 Keepalived_healthcheckers[9801]: Registering Kernel netlink reflector
Dec 6 21:01:43 ubuntu-lvs-74 Keepalived_healthcheckers[9801]: Registering Kernel netlink command channel
Dec 6 21:01:43 ubuntu-lvs-74 Keepalived_healthcheckers[9801]: Opening file '/etc/keepalived/keepalived.conf'.
Dec 6 21:01:43 ubuntu-lvs-74 Keepalived_healthcheckers[9801]: Configuration is using : 13613 Bytes
Dec 6 21:01:43 ubuntu-lvs-74 Keepalived_healthcheckers[9801]: Using LinkWatch kernel netlink reflector...
Dec 6 21:01:43 ubuntu-lvs-74 Keepalived_healthcheckers[9801]: Activating healthchecker for service [172.18.8.74]:6379
Dec 6 21:01:43 ubuntu-lvs-74 Keepalived_healthcheckers[9801]: Activating healthchecker for service [172.18.8.73]:6379
Dec 6 21:01:44 ubuntu-lvs-74 Keepalived_vrrp[9802]: VRRP_Instance(VI_1) Now in FAULT state
Dec 6 21:01:44 ubuntu-lvs-74 Keepalived_vrrp[9802]: Opening script file /etc/keepalived/scripts/redis_fault.sh


route信息
Destination Gateway Genmask Flags Metric Ref Use Iface
default 172.18.8.1 0.0.0.0 UG 0 0 0 eth0
172.18.8.0 * 255.255.255.128 U 0 0 0 eth0
172.18.8.100 * 255.255.255.255 UH 0 0 0 lo



root@ubuntu-lvs-74:/opt/lvs# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.18.8.100:80 rr
-> 172.18.8.73:80 Route 1 0 0
-> 172.18.8.74:80 Route 1 0 0
TCP 172.18.8.100:6379 rr persistent 50
-> 172.18.8.73:6379 Route 1 0 0
-> 172.18.8.74:6379 Route 1 0 0

VIP:172.18.8.100 ,在73,74之间可以互相ping通

请教,VRRP_Instance(VI_1) Now in FAULT state 可能是哪方面原因造成的?

...全文
1999 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljc007 2014-12-08
  • 打赏
  • 举报
回复
1、router_id 别重复 2、主机 state MASTER 备机 state BACKUP 3、lo0上的那个VIP是做心跳的,eth0上的VIP才是宕机之后做切换的

23,217

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧