首先,我对HAProxy堆栈的使用经历只有一天的时间,所以我希望我的问题是有道理的。
我有2个HAProxy虚拟机和2个Apache虚拟机(stream浪机)如下。
192.168.50.11 HAPROXY VM1 192.168.50.12 HAPROXY VM2 192.168.50.21 APACHE VM1 192.168.50.22 APACHE VM2 192.168.50.10 FLOATING IP - set in keepalived of both HAProxy servers above
如果我把一个Apache服务器closures,并且调用http://192.168.50.10系统仍然可以正常工作。 但是,如果我将其中一个HAProxy服务器closures,则整个服务都将中断。 根据我的configuration,你能告诉我我在这里错过了什么吗?
在这两个服务器上的快乐设置
在/ etc /默认/ HAProxy的
ENABLED=1
/etc/haproxy/haproxy.cfg
global log /dev/log local0 log 127.0.0.1 local1 notice user haproxy group haproxy maxconn 2000 daemon defaults log global mode http option httplog option dontlognull retries 3 option redispatch timeout connect 5000 timeout client 50000 timeout server 50000 listen webservers 192.168.50.10:80 balance roundrobin stats enable stats auth admin:admin stats uri /haproxy?stats option httpchk option forwardfor option http-server-close server webserver1 192.168.50.21:80 check server webserver2 192.168.50.22:80 check
在两个服务器上保持相同的设置
/etc/sysctl.conf中
net.ipv4.ip_nonlocal_bind=1
等/ KEEPALIVED / keepalived.conf
vrrp_script chk_haproxy { script "killall -0 haproxy" #Ping every 2 seconds interval 2 weight 2 } vrrp_instance VI_1 { interface eth0 state MASTER virtual_router_id 51 priority 11 virtual_ipaddress { 192.168.50.10 } track_script { chk_haproxy } }
注意:只有priority依赖于虚拟机,所以对于192.168.50.11 HAPROXY VM1机器, priority 12为priority 11 ,对于192.168.50.12 HAPROXY VM2机器, priority 12 。
我在阅读下面的博客文章后创build了这个例子。
正如我所想的,keepalivedconfiguration文件存在一些小错误。
state MASTER为192.168.50.11 # This is the master HAProxy
state BACKUP为192.168.50.12 # This is the failover HAProxy
和
priority 12为192.168.50.11 # the higher priority goes with the master HAProxy
priority 11为192.168.50.12