同步多个Varnish Cache服务器

时间:2011-08-17 15:13:03

标签: synchronization varnish

我们有两个服务器,web1和web2,每个都运行Apache和Varnish。它们是负载平衡的,持续30分钟。

在我们的测试中,我们发现一些案例是页面缓存在一个Varnish实例(比如web1)上,而不是在web2上的Varnish上。

有没有办法让它们保持同步?因此,当web1中的页面被缓存(或清除)时,它也会被加载到web2中(或从中清除),反之亦然?

1 个答案:

答案 0 :(得分:1)

您可以使用一种清漆作为另一种清漆的后端。

您可以执行以下操作:

// use random director so you can fall back to web
director varnish random {
    {
        .backend = varnish2;
        .weight  = 100000000;
    }
    {
        .backend = web;
        .weight = 1;
    }
}

acl othervarnish {
        "{hostname}";
}

sub vcl_recv {
  set req.backend = web;

  // switch backend to varnish only if you haven't come from there
  if (!client.ip ~ othervarnish) {
     set req.backend = varnish;
  }
}

但请注意,这似乎是doesn't work with ESIs