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.
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.
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?
Did you try to remove every option involved in cookie-based persistence? What happens?
Try to change WEB_1 into WEB1:
Try to remove
insert
statement fromcookie
.Following to documentation for [
insert
]: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 serverstatement
.