1

I've finally got HA Proxy set up and running in a way I think I want. However, it is not load balancing the web requests it receives. All requests are currently being forwarded to the first server in the cluster. I'm going to paste my configuration below - if anyone can see where I may have gone wrong, I'd appreciate it.

This is my first stab at configuring web servers in a *nix environment.

First up, I have HA Proxy running on the same host as the first server in the apache cluster. We are moving these servers to virtual later on, and they will have different virtual hosts, but I wanted to get this running now.

Both web servers are receiving their health checks, and are reporting back correctly. The haproxy?stats page correctly reports servers that are up and down. I've tested this by altering the name of the file that is checked. I haven't put any load onto these servers yet. I've just opened up the URLs on several tabs (private browsing), and had several co-workers hit the URL too. All of the traffic goes to WEB1. Am I balancing incorrectly?

global
      maxconn 10000
      nbproc 8
      pidfile /var/run/haproxy.pid
      log 127.0.0.1 local0 debug
      daemon

defaults
      log global
      mode http
      retries 3
      option redispatch
      maxconn 5000
      contimeout 5000
      clitimeout 50000
      srvtimeout 50000

listen WEBHAEXT :80,:8443
      mode http
      cookie sessionbalance insert indirect nocache
      balance roundrobin
      option httpclose
      option forwardfor except 127.0.0.1
      option httpchk HEAD /health_check.txt
      stats enable
      stats auth rah:rah
      server WEB1 10.90.2.131:81 cookie WEB_1 check
      server WEB2 10.90.2.130:80 cookie WEB_2 check

Edit:

I successfully ran tests using ab (apache benchmarking) and load was split evenly across both nodes. I'm not sure what I was doing wrong before, but the above configuration works.

2
  • What does a stats page show? Is one of the backend servers in down state?
    – Alex
    Feb 4, 2011 at 8:09
  • No, both servers are up when I'm testing this. Feb 5, 2011 at 1:40

4 Answers 4

3

How are you checking that all requests go to a single server? As you've configured HAProxy, you're using sticky sessions where HAProxy sets a cookie on each client that directs it to the same backend node for every request. If you simply kept reloading in a single browser, you'd see every request go to the same backend.

3
  • I was opening new incognito windows and checking the cookie that was set, and viewing load on the stats page. Like I said, I also had several co-workers on different machines hit the proxy and everyone was sent to WEB1. Feb 5, 2011 at 1:42
  • +1, it may not be the problem in this case, (if it's not cookies and both servers are up - i don't know!) but cookies are something really easy to forget about. I opt for doing "curl -I <url>" when testing the setup so I can see the headers returned each time. (curl doesn't honour cookies by default).
    – Coops
    Feb 7, 2011 at 23:09
  • First to answer correctly (before I posted the bounty), so you get the win. I don't know why it wasn't appearing to balance before, but it is now. Feb 9, 2011 at 10:22
1
+50

I've just tried the exact config you provided. Firstly the health check didn't work for me, I had to add a "/" infront of "health_check.txt" (haproxy-1.4.10).

However the load balancing worked fine. Each time I closed and re-opened my browser I'd be pinged across to the other server.

Do you have a live application you're testing (with it's own cookies), or is it just a test page?

3
  • You're right about the health check, but I removed the /path/to/health_check.txt and forgot to leave the /. You're right about the load balancing, it does work fine. Feb 9, 2011 at 10:22
  • Bounty given (but not right answer) because of the effort to test the config. Thank you muchly! Feb 9, 2011 at 10:28
  • @John pleasure :)
    – Coops
    Feb 9, 2011 at 10:31
0

Try to remove insert statement from cookie.

Following to documentation for [insert]:

If the client has all the required information to connect to the same server next time, no further cookie will be inserted.

So, it's possible that all requests get their WEB1 assigment via this cookie and then follow this direction on each request.

PS: And you must set same names for cookie parameter in server statement.

server WEB1 10.90.2.131:81 cookie WEB_LB check
server WEB2 10.90.2.130:80 cookie WEB_LB check
1
  • @Molokov I don't believe your comment regarding cookies to be accurate. In the server statement, you assign the value of the cookie, where the name of the cookie is defined in the listen/backend section. Feb 9, 2011 at 10:26
0

Did you try to remove every option involved in cookie-based persistence? What happens?

Try to change WEB_1 into WEB1:

server WEB1 10.90.2.131:81 cookie WEB1 check
server WEB2 10.90.2.130:80 cookie WEB2 check
1
  • The underscores in the cookie values work correctly. Feb 9, 2011 at 10:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .