【问题标题】:How to check if backend is healthy in vcl_recv如何在 vcl_recv 中检查后端是否健康
【发布时间】:2012-09-07 03:22:04
【问题描述】:

我有相当复杂的清漆配置。我不能真正使用导向器并手动执行路线。

//webservice1 and webservice2 has probes working there

set req.backend = webservice1;
if (req.backend.healthy)
{ 
     #redirect there 
}

set req.backend = webservice2;
if(req.backend.healthy)
{ 
     #change parameters with regex and redirect
}

这行得通。但是看起来真的很蹩脚。

是否有任何“合法”的方式来确定后端是否健康?像这样:

if(webservice2.healthy)
{ 
     #change parameters with regex and redirect
}

这显然是行不通的。

【问题讨论】:

    标签: proxy varnish varnish-vcl


    【解决方案1】:

    在谷歌大量搜索后,我找到了这个link,他们正在谈论迁移到 V4。

    代码:

    if(!req.backend.healthy) {
      #your logic
    }
    

    对 Varnish 3 有效,对 varnish 4 无效。

    对于清漆 4:

    看这里: https://www.varnish-cache.org/docs/4.0/users-guide/vcl-grace.html#users-guide-handling-misbehaving-servers

    所以解决办法是:

    import std;
    set req.backend_hint = webservice1;
    if (!std.healthy(req.backend_hint)) {
        set req.backend_hint = webservice2;
    }
    

    希望对你有帮助:)

    【讨论】:

    • 他没有要求 Varnish 4 解决方案,但有两个版本很好。
    • 有趣的是,3 年后我从 varnish 3 升级到 4 并且遇到了同样的问题。我用谷歌搜索并遇到了你的答案。目前很好。我决定投赞成票,登录后我发现我正在查看我的旧问题。
    【解决方案2】:

    我已经对此进行了大量研究,这是完成它的唯一方法(除非你想编写一个 vmod)。

    假设您总是想用 webservice1 来响应,除非它生病了,我可能会建议进行一些重构:

    set req.backend = webservice1;
    if(!req.backend.healthy) {
         set req.backend = webservice2;
         #change parameters with regex
    }
    # redirect here
    

    【讨论】:

    • 如果你不确定/有建议,你应该把它写成评论而不是答案。
    • 感谢您的建议,但由于我的声誉较低,我无法制作 cmet。另外,这个问题的答案不是没有答案吗? :)
    • 我有同样的问题,这在 Varnish 4 中不起作用
    • 所以你只是因为它不适合你而对我投了反对票?
    • 天哪,3 年来我一直使用您的答案作为我最重要的关于清漆的数据之一,但从未将其作为解决方案。谢谢,伙计!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-17
    • 2020-05-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多