对HAProxy的粘性连接和HTTPS支持

我们有2个HTTP负载平衡器HAproxy和心跳。 在这个集群中有4个apache节点。 它正在循环负载平衡。 HTTP群集工作正常。 我们的门户网站存在问题,因为它使用SSO。 我们需要在我们的HAproxy中提供粘性连接支持。 另外我们需要对HTTPSstream量进行负载平衡。 这是我们的HAproxy conf文件。

global # to have these messages end up in /var/log/haproxy.log you will # need to: # # 1) configure syslog to accept network log events. This is done # by adding the '-r' option to the SYSLOGD_OPTIONS in # /etc/sysconfig/syslog # # 2) configure local2 events to go to the /var/log/haproxy.log # file. A line like the following can be added to # /etc/sysconfig/syslog # # local2.* /var/log/haproxy.log # log 127.0.0.1 local0 log 127.0.0.1 local1 notice chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon # turn on stats unix socket stats socket /var/lib/haproxy/stats #--------------------------------------------------------------------- # common defaults that all the 'listen' and 'backend' sections will # use if not designated in their block #--------------------------------------------------------------------- defaults mode http log global option httplog option dontlognull option http-server-close option forwardfor except 127.0.0.0/8 option redispatch retries 3 timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s maxconn 3000 #--------------------------------------------------------------------- # main frontend which proxys to the backends #--------------------------------------------------------------------- frontend main *:5000 acl url_static path_beg -i /static /images /javascript /stylesheets acl url_static path_end -i .jpg .gif .png .css .js use_backend static if url_static default_backend app #--------------------------------------------------------------------- # static backend for serving up images, stylesheets and such #--------------------------------------------------------------------- backend static balance roundrobin server static 127.0.0.1:4331 check #--------------------------------------------------------------------- # round robin balancing between the various backends #--------------------------------------------------------------------- backend app listen ha-http 10.190.1.28:80 mode http stats enable stats auth admin:xxxxxx balance roundrobin cookie JSESSIONID prefix option httpclose option forwardfor option httpchk HEAD /haproxy.txt HTTP/1.0 server apache1 portal-04:80 cookie A check server apache2 im-01:80 cookie B check server apache3 im-02:80 cookie B check server apache4 im-03:80 cookie B check 

请指教。 感谢您的帮助提前。

你的configuration已经设置了一个持久性cookie,但是我相信你需要为每个后端服务器定义一个不同的cookie来始终将访问者发送到相同的后端。

你的SSO有它自己的cookie吗? 还是你高兴坚持与任何箱子haproxyselect发送stream量? 如果你有一个应用程序设置的cookie,有一个configuration选项可以告诉haproxy根据预先存在的cookie来进行负载均衡,而不是设置一个本身。 (选中“ appsession ”选项)。

关于SSL,这里有大量的文档描述了HAProxy为什么不处理SSL本身。 相反,如果你想做SSL +第7层(cookies等)负载平衡,你必须终止负载平衡器上的HTTPS连接(即有SSL的SSL驻留在LB而不是后端服务器)。 我之前通过在同一个盒子上运行nginx来完成这个工作,并且工作得很好。

但是,如果您对第4层负载均衡(无cookie等)感到满意,HAProxy可以将encryption的stream量路由而不用在旁边看内容。

如果您使用spnego / kerberos进行用户身份validation,则需要保持客户端和后端之间的连接处于活动状态。 这是一个SPNEGO协议“function”,它希望通过同一个连接来解决挑战。

请记住,保持连接活着可能会导致连接持久性问题,因为haproxy只检查第一个http动词的头。

对于ssl,我也会selectNginx,其他选项是带有X-FORWARDED-FOR支持的stunnel