HAProxy supports URL hash based load balancing. This is usefull if you want to create a Squid caching cluster and ensure each object is cached only once, thus increasing the cache hit ratio and the number of objects stored in the cluster. To enable the URL hash based load balancing choose HAProxy's 'balance uri' algorith.
By default HAProxy hashes the left part of the URI (the part before the question mark). If you want to hash the whole URI you need to add the 'whole' keyword.
The 'whole' keywork was introduced in HAProxy 1.5, but 1.4.21 can be pached to get this feature.
UPDATE 1.4.22 backported the 'whole' keyword and EPEL updated HAProxy to 1.4.22, so there is no need to patch HAProxy anymore. Happy days...
UPDATE Redhat included keepalived and haproxy in RHEL6.4, there is no need to install it from EPEL anymore. Hurray!!!
Here is how to do it.
- First install HAProxy
- Then download the 1.4.21 source code, patch it, compile it, and replace the EPEL binary
yum install gcc patch wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.21.tar.gz tar xzvf haproxy-1.4.21.tar.gz cd haproxy-1.4.21 zcat /tmp/balance-uri-whole.patch.gz |patch -p 1 make TARGET=linux26 cp haproxy /usr/sbin/haproxy # this replaces the binary from EPEL package
- Now you can add the "whole" parameter after "balance uri"
backend cache balance uri whole server cache01 192.168.40.91:3128 check server cache02 192.168.40.92:3128 check server cache03 192.168.40.93:3128 check server cache04 192.168.40.94:3128 check server cache05 192.168.40.95:3128 check server cache06 192.168.40.96:3128 check
- The patch is available here.