与stunnel和haproxy一起使用虚拟IP

我们有一个负载平衡器的设置,其中一个HTTPS请求stream经以下步骤:

Client -> DNS -> stunnel on Load-Balancer -> HAProxy on LB -> Web-Server 

当stunnel正在监听负载均衡器的本地IP时,此设置完美工作。

然而,在我们的设置中,我们有2个负载均衡器,我们希望能够监听一个虚拟IP,这个虚拟IP一次只能在一个LB上存在(keepalived将IP翻转到第二个LB,如果第一个丢弃的话)。

HAProxy在这样做没有问题(我可以ping所分配的虚拟IP在我正在testing的负载平衡器上),但似乎stunnel恨这个概念。

有没有人以前做过这个(下面是我的stunnelconfiguration – 正如你可以看到我实际上听所有443stream量): –

 cert= /etc/ssl/certs/mycert.crt key = /etc/ssl/certs/mykey.key ;setuid = nobody ;setgid = nogroup pid = /etc/stunnel/stunnel.pid debug = 3 output = /etc/stunnel/stunnel.log socket=l:TCP_NODELAY=1 socket=r:TCP_NODELAY=1 [https] accept=443 connect=127.0.0.1:8443 TIMEOUTclose=0 xforwardedfor=yes 

对于冗长的问题抱歉!

关键是允许程序(如stunnel,HA-proxy)绑定不存在的接口。 因此,当keepalived将虚拟IP翻转到该框时,程序已经在监听并等待该接口上的stream量。

这可以通过修改你的/etc/sysctl.conf来完成,包括下面的键/值对:

 net.ipv4.ip_nonlocal_bind=1 

更多信息: http : //nbevans.wordpress.com/2011/03/01/safely-pairing-haproxy-with-virtual-network-interface-providers-like-keepalived-or-heartbeat/

然后,您最好修改您的stunnel和HA-proxyconfiguration,将绑定硬编码到特定的虚拟接口IP。 而不是让它“开放”。