简体   繁体   中英

Load Balancer with Apache HTTPD

I'm struggling to set up a an Apache httpd load balancer in front of a couple of application servers. This is my configuration:

ProxyRequests off

<Proxy balancer://mycluster>

    BalancerMember http://127.0.0.1:8080
    BalancerMember http://remote-svr:8080
    ProxySet lbmethod=bybusyness
    ProxySet stickysession=JESSIONIDSSO
</Proxy>

<Location /balancer-manager>
   SetHandler balancer-manager
</Location>

ProxyPass /balancer-manager !
ProxyPass / balancer://mycluster/
ProxyPassReverse / balancer://mycluster/
ProxyPassReverseCookieDomain http://127.0.0.1:8080 localhost
ProxyPassReverseCookieDomain http://remote-svr:8080 localhost

I'm not sure the last 2 lines do anything, although one of the many examples I've looked at online used them, so I added them to see if it fixed my problem (it didn't).

The issue is that if I comment out either of the BalancerMember lines eg:

    #BalancerMember http://127.0.0.1:8080
    BalancerMember http://remote-svr:8080

Then the behaviour from a user perspective is fine, however when both members are active, the behaviour is wrong.

The application initially displays a login screen, however when both load balancers are active, the user on submitting their username and password just get redirected back to the login screen again, maybe the session is being lost somewhere. Does anyone have any idea what the issue might be?

EDIT - NOW WORKING

for reference, this setup now seems to work:

ProxyRequests off
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED

<Proxy balancer://mycluster>

    BalancerMember http://127.0.0.1:8080 route=localServer
    BalancerMember http://remote-svr:8080 route=remoteServer
    ProxySet lbmethod=bybusyness
    ProxySet stickysession=ROUTEID
</Proxy>

<Location /balancer-manager>
   SetHandler balancer-manager
</Location>

ProxyPass /balancer-manager !
ProxyPass / balancer://mycluster/
ProxyPassReverse / balancer://mycluster/ 

Note the 'route' attribute for the individual nodes needs to be set on the nodes themselves (server.xml in this case, as the servers run JBoss). JSESSIONID worked ok as the sticky session cookie for individual applications but there is more than one application on each server, and the user needs to use the same node for all.

If I were to guess you probably loose the session due to a typo in this section:

<Proxy balancer://mycluster>
    BalancerMember http://127.0.0.1:8080
    BalancerMember http://remote-svr:8080
    ProxySet lbmethod=bybusyness
    ProxySet stickysession=JESSIONIDSSO
</Proxy>

ProxySet stickysession=JESSIONIDSSO this should probably say ProxySet stickysession=JSESSIONIDSSO ? Or maybe even JSESSIONID ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM