1
votes

We're planning to add a second varnish server to our infraestructure.

What it's the better method to balance the traffic throw the two servers? I think we can use haproxy in front of the two servers, but how to configure it to load balance the traffic between the 2 varnish? The ideal solution is that if one varnish is down all the traffic goes to the other.

Edit: The ideal behaviour is an active/active conf, with 50% load each and if one goes down haproxy sends 100% load to the other.

2
Are you looking for a master/slave configuration for Varnish (where only one is active at all times) or where the 2 Varnish instances both serve traffic at the same time?Mojah
Edited question with active/active ideal conf.David Sedeño

2 Answers

1
votes

Another option would be to put both varnish instances in the same backend, but balance requests by uri or parameter.

This will allow you to have both active in the same backend, and still maintain a high cache-hit ratio since the same uri will be always balanced to the same varnish cache (as long as it is available). Balace uri also takes an optional parameter of length to use when hashing.

Heres a quick example:

frontend http-in acl my_acl use_backend varnish if my_acl

backend varnish1
  mode http
  balance uri
  option httpchk  GET /check.txt HTTP/1.0
  server varnish1 192.168.222.51:6081 check inter 2000
  server varnish2 192.168.222.52:6081 check inter 2000
0
votes

The idea I have come up is use two backends and have in each backed use the other server as backup so when a server is down all the request goes to the alive server.

frontend http-in
  acl my_acl <whaever acl to split the traffic>
  use_backend varnish2 if my_acl
  default_backend varnish1

backend varnish1
  mode http
  option httpchk  GET /check.txt HTTP/1.0
  server varnish1 192.168.222.51:6081 check inter 2000
  server varnish2 192.168.222.52:6081 check inter 2000 backup

backend varnish2
  mode http
  option httpchk  GET /check.txt HTTP/1.0
  server varnish2 192.168.222.51:6081 check inter 2000
  server varnish1 192.168.222.52:6081 check inter 2000 backup