Varnish 忽略后端

Varnish 忽略后端

我已经安装了 2 个带有循环调度器的后端服务器的 Varnish。

这两个后端在 varnishstat 和 varnishadm 中显示为健康。

varnishadm 输出:

Backend name                   Admin      Probe
boot.app1                      probe      Healthy 5/5
boot.app2                      probe      Healthy 5/5

VCL配置:

probe ping {
  .interval = 5s;
  .timeout = 1s;
  .threshold = 3;
  .window = 5;
  .url = "/ping";
}
backend app1 {
  .host = "app-1.example.com";
  .port = "80";
  .probe = ping;
}

backend app2 {
  .host = "app-2.example.com";
  .port = "80";
  .probe = ping;
}

new application_servers = directors.round_robin();
application_servers.add_backend(app1);
application_servers.add_backend(app2);

set req.backend_hint = application_servers;

varnishstat 输出:

VBE.boot.app1.happy                                                                                                                        ffffffffff     VVVVVVVVVVVVVVVVVVVVVVVV
VBE.boot.app1.bereq_hdrbytes                                                                                                                    66.17K         0.00         91.00          0.00          0.00          0.00
VBE.boot.app1.beresp_hdrbytes                                                                                                                   76.72K         0.00        106.00          0.00          0.00          0.00
VBE.boot.app1.beresp_bodybytes                                                                                                                  11.91M         0.00         16.50K         0.00          0.00          0.00
VBE.boot.app1.conn                                                                                                                                251          0.00           .          251.00        251.00        251.00
VBE.boot.app1.req                                                                                                                                 251          0.00           .            0.00          0.00          0.00
VBE.boot.app2.happy                                                                                                                        ffffffffff     VVVVVVVVVVVVVVVVVVVVVVVV

您可以从 varnishstat 命令中看到,流量似乎仅发送到循环配置中的第一个服务器。除了 .happy 之外,app2 服务器没有其他行

有什么想法可以解释为什么主管每次都选择第一台服务器?

答案1

您需要将 VCL 文件更改为类似以下内容

probe ping {
   .interval = 5s;
   .timeout = 1s;
   .threshold = 3;
   .window = 5;
   .url = "/ping";
}
backend app1 {
   .host = "app-1.example.com";
   .port = "80";
   .probe = ping;
}

backend app2 {
   .host = "app-2.example.com";
   .port = "80";
   .probe = ping;
}

sub vcl_init {
    new application_servers = directors.round_robin();
    application_servers.add_backend(app1);
    application_servers.add_backend(app2);
}

sub vcl_recv{
    set req.backend_hint = application_servers;
}

相关内容