0

I have configured a Software Load balancer with HAProxy.

  • Here are the details :
    1. Load Balancer 1 (Master) - 10.0.0.2
    2. Load Balancer 2 (Slave) - 10.0.0.3
    3. Virtual IP that load balancer shared is - 10.0.0.1
    4. Web Server 1 with Apache : 10.0.0.4
    5. Web Server 2 with Apache : 10.0.0.5
    6. Web Server 3 with Apache : 10.0.0.6

I am able to access the website hosted on all Webservers through Virtual IP configured i.e 10.0.0.1

But, when i refresh the browser, the servers are getting switched from one to another. Also, getting error "503 Service Unavailable", that too when refreshed, goes to another server.

Here is the HAProxy.conf file content [Master Load Balancer]:

global
        log 127.0.0.1 local0  err
        ulimit-n 50000
        maxconn 24000
        nbproc 1
        stats socket /tmp/haproxysock
        user haproxy
        group haproxy
        daemon

defaults
        log global
        mode    http
        option  httplog
        maxconn 5000
        contimeout 5000
        clitimeout 50000
        srvtimeout 50000

frontend UNBoxFrontEnd
        bind 10.0.0.1:80
        option http-server-close
        default_backend UNBoxBackEnd

backend UNBoxBackEnd
        option httpchk HEAD / HTTP/1.1\r\nHost:localhost
        hash-type consistent
        cookie JSESSIONID prefix
        server WebServer1 10.0.0.4:80 cookie Web1 check
        server WebServer2 10.0.0.5:80 cookie Web2 check
        server WebServer3 10.0.0.6:80 cookie Web3 check

listen web-cluster         10.0.0.1:80
        bind *:1936
        balance roundrobin
        stats enable
        stats scope UNBoxFrontEnd
        stats scope UNBoxBackEnd
        stats scope wordpress-backend
        stats uri /haproxy?stats
        stats realm Haproxy\ Statistics
        stats auth test:test
        stats admin if TRUE
        errorfile    400    /etc/haproxy/errors/400.http
        errorfile    403    /etc/haproxy/errors/403.http
        errorfile    408    /etc/haproxy/errors/408.http
        errorfile    500    /etc/haproxy/errors/500.http
        errorfile    502    /etc/haproxy/errors/502.http
        errorfile    503    /etc/haproxy/errors/503.http
        errorfile    504    /etc/haproxy/errors/504.http

Can you please help me out to make client always redirected to a single Webserver unless that goes down.

Thanks in advance!

  • The 503 error sounds like you have a problem with one of your servers. I've posted an answer to the load balancer issue. – shearn89 Feb 3 '15 at 10:23
0

Your problem is the balance roundrobin line in HAProxy.cfg. This tells HAProxy to round-robin between all available nodes. Change it to something else (as detailed in the haproxy documentation) and you should get the behaviour you want.

For posterity, the (IMO) most popular options to the 'balance' directive are:

  • roundrobin - classic round-robin balancing.
  • static-rr - a variant which allows for more servers by disabling some functionality.
  • leastconn - balance to the server with least connections first.
  • source - hash the source IP address and balance based on that.
  • uri - hash some or all of the URI and balance based on that.
  • Thanks for your feedback shearn89! I tried with different balance algorithms still getting the similar response. – Tejas Somaiya Feb 3 '15 at 11:49
  • The blurb for the source algorithm would imply that it's a best attempt at sticky sessions. If your problem is the 503 error still then I'm not sure that's a load balancing issue, but a problem with the Apache config on that node. Does it happen on all nodes or just one? Do all the nodes work when you navigate to them directly? – shearn89 Feb 3 '15 at 11:59
  • Thanks again for your valuable feedback! I think 503 error resolved on deleting listener server on "listen web-cluster" Yes, it works correctly when i directly access nodes. Only thing is, when i access 10.0.0.1, lets say i got navigated to 10.0.0.4 and when i refresh it goes to 10.0.0.5 or 10.0.0.6 and vice-a-versa. how can i make it consistent – Tejas Somaiya Feb 3 '15 at 13:30
  • I'm not sure - I'd expect balance source to do that, as it should hash your source IP and then effectively stick you to one server. Does this help? blog.haproxy.com/2012/03/29/… – shearn89 Feb 3 '15 at 13:37
  • 1
    Thanks a lot bro! it worked.. many thanks.. :) you saved my day! – Tejas Somaiya Feb 3 '15 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.