docker下用keepalived+Haproxy实现高可用负载均衡集群

启动keepalived后宿主机无法ping通用keepalived,报错:

[root@localhost ~]# ping 172.18.0.15
PING 172.18.0.15 (172.18.0.15) () bytes of data.
From 172.18.0.1 icmp_seq= Destination Host Unreachable
From 172.18.0.1 icmp_seq= Destination Host Unreachable
From 172.18.0.1 icmp_seq= Destination Host Unreachable
From 172.18.0.1 icmp_seq= Destination Host Unreachable
From 172.18.0.1 icmp_seq= Destination Host Unreachable
From 172.18.0.1 icmp_seq= Destination Host Unreachable

解决方案:

大多数都是我把配置文件没写对,重写配置文件,重启服务;

这里检查能否ping通,需要看服务内你的配置文件写入的ip有没有出现在docker的网卡上,具体方法是:

进入到docker服务内,不是在宿主机上哦,查看配置文件
root@8351443065ea:/etc/keepalived# cat keepalived.conf
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id
priority
advert_int
authentication {
auth_type PASS
auth_pass
}
virtual_ipaddress {
172.18.0.201
}
}
如果配置文件信息都是正确的,通过ip a命令会显示如当前docker服务有的网卡
root@ec688a676a07:/# ip a
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN group default qlen
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
valid_lft forever preferred_lft forever
inet6 ::/ scope host
valid_lft forever preferred_lft forever
: eth0@if18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc noqueue state UP group default ; 很明显没有我配置文件中的172.18.0.201ip地址,代表配置文件未生效,大多数配置文件错误 停掉keepalived服务重新修改编辑后重启
root@ec688a676a07:/# service keepalived stop
[....] Stopping keepalived: keepalived. ok
重启服务
root@ec688a676a07:/# service keepalived start
[....] Starting keepalived: keepalived. ok 再次查看docker服务的ip
root@ec688a676a07:/# ip a
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN group default qlen
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
valid_lft forever preferred_lft forever
inet6 ::/ scope host
valid_lft forever preferred_lft forever
: eth0@if18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc noqueue state UP group default
link/ether ::ac::: brd ff:ff:ff:ff:ff:ff link-netnsid
inet 172.18.0.7/ scope global eth0
valid_lft forever preferred_lft forever
这里出现了我的配置文件ip地址
inet 172.18.0.201/ scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80:::acff:fe12:/ scope link
valid_lft forever preferred_lft forever 在服务内直接ping这个ip,发现能ping通,切换宿主机,也能ping通,解决问题
[root@localhost ~]# ping 172.18.0.201
PING 172.18.0.201 (172.18.0.201) () bytes of data.
bytes from 172.18.0.201: icmp_seq= ttl= time=0.077 ms
bytes from 172.18.0.201: icmp_seq= ttl= time=0.064 ms
上一篇:LVS+Keepalived+Nginx+Tomcat高可用负载均衡集群配置(DR模式,一个VIP,多个端口)


下一篇:SharePoint 2013 Pop-Up Dialogs