简体   繁体   中英

Load balancing between servers using Apache and JBoss

I am facing the following scenario: I have three servers, each with an instance of my application deployed in a standalone JBoss, I am trying to use a machine that will do the load balancing service between these three servers, for this I am using the module mod_proxy_balancer from Apache (or at least trying), and it was even easy to do the balancing, it worked correctly, however I am having problems in keeping users session and cookies, because whenever a new request is made, the balancer sends it to another server, causing that the user loses his session, I would like that when a user already had a session in one of the servers the same one was sent to him, or something of the type. Is it possible to achieve the desired result using such resources? If so, how should I make such a setup? If not, what other tool or feature should I use?

Here's the virtual host configuration:

<VirtualHost *:80>
    ServerName server.int
    ProxyPass / balancer://balance/ stickysession=JSESSIONID|jsessionid scolonpathdelim=On
    ProxyPass /balancer-manager !
    ProxyPassReverse / balancer://balance/ stickysession=JSESSIONID|jsessionid scolonpathdelim=On
    ProxyPassReverseCookiePath / /
    <Proxy balancer://balance/>
        BalancerMember "http://server1.int" loadfactor=50
        BalancerMember "http://server2.int" loadfactor=25
        BalancerMember "http://server3.int" loadfactor=25
        ProxySet lbmethod=byrequests
    </Proxy>
    <Location /balancer-manager>
        SetHandler balancer-manager
    </Location>
</VirtualHost>

Although no one has answered, I will leave here the solution to my problem if this helps anyone in the future. I ended up using HAProxy that can do exactly what I needed in a very simple way.

frontend app
    bind *:80
    bind *:443 ssl crt /etc/haproxy/certs/cert.pem
    redirect scheme https if !{ ssl_fc }
    mode http
    default_backend app

backend app
    balance leastconn
    mode http
    option httpchk HEAD / HTTP/1.0
    cookie SERVERID insert indirect nocache
    server server1 server1.test.com:80 check weight 50 fall 3 rise 2 cookie server1
    server server2 server2.test.com:80 check weight 50 fall 3 rise 2 cookie server2
    server server3 server3.test.com:80 check weight 50 fall 3 rise 2 cookie server3

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