varnish-4.x VCL之healthy check

varnish-4.x VCL之healthy check

更多帮助请man vcl

示例:
如下是本人测试的示例文件,包含healthcheck申明,director引用, purge acl

vcl 4.0;

import std;
import directors;

probe healthcheck_nginx {
    .url = "/healthy.jpg";
    .timeout = 3s;
    .interval = 5s;
    .window = 5;
    .threshold = 3;
}
probe healthcheck_apache {
    .url = "/healthy.jpg";
    .timeout = 3s;
    .interval = 5s;
    .window = 5;
    .threshold = 3;
}
backend nginx {
    .host = "192.168.192.10";
    .port = "8080";
    .connect_timeout = 3s;
    .first_byte_timeout = 5s;
    .between_bytes_timeout = 5s;
    .max_connections = 30000;
    .probe = healthcheck_nginx;
}
backend apache {
    .host = "192.168.192.10";
    .port = "8081";
    .connect_timeout = 3s;
    .first_byte_timeout = 5s;
    .between_bytes_timeout = 5s;
    .max_connections = 3000;
    .probe = healthcheck_apache;
}

sub vcl_init {
    new round_robin_director = directors.round_robin();
    round_robin_director.add_backend(apache);
    round_robin_director.add_backend(nginx);

    new random_director = directors.random();
    random_director.add_backend(nginx, 10);
    random_director.add_backend(apache, 5);

    new hash_director = directors.hash();
    hash_director.add_backend(nginx, 10);
    hash_director.add_backend(apache, 5);
}

acl purgers {
    "127.0.0.1";
    "192.168.0.0"/24;
}

sub vcl_recv {
    # allow PURGE from localhost and 192.168.0...
    if (req.restarts == 0) {
        unset req.http.X-Purger;
    }
    if (req.method == "PURGE") {
        if (!client.ip ~ purgers) {
            return (synth(405, "Purging not allowed for " + client.ip));
        }
        return (purge);
    }
    #set req.backend_hint = round_robin_director.backend();
    set req.backend_hint = hash_director.backend(req.http.cookie);
}

sub vcl_purge {
    set req.method = "GET";
    set req.http.X-Purger = "Purged";
    return (restart);
}

sub vcl_deliver {
    if (req.http.X-Purger) {
        set resp.http.X-Purger = req.http.X-Purger;
    }
}

如下这段定义healthcheck,格式
       probe name {
            .attribute = "value";
       }

probe healthcheck_nginx {
    .url = "/healthy.jpg";
    .timeout = 3s;
    .interval = 5s;
    .window = 5;
    .threshold = 3;
}
一句话,5秒监测一次,最新的5次监测中,有3次成功则判定为healthy

实时查看健康状态
watch -n.5 varnishadm backend.list
watch -n.5 varnishadm debug.health
varnishlog -g raw -i Backend_health

相关栏位解释
varnish-4.x <wbr>VCL之healthy <wbr>check
varnish-4.x <wbr>VCL之healthy <wbr>check

varnish-4.x <wbr>VCL之healthy <wbr>check

root@config-p:~#varnishlog -g raw -i Backend_health
         0 Backend_health - nginx Still healthy 4--X-RH 5 3 5 0.000235 0.000241 HTTP/1.1 200 OK
         0 Backend_health - apache Still healthy 4--X-RH 5 3 5 0.000323 0.000378 HTTP/1.1 200 OK
         0 Backend_health - nginx Still healthy 4--X-RH 5 3 5 0.000297 0.000255 HTTP/1.1 200 OK
         0 Backend_health - apache Still healthy 4--X-RH 5 3 5 0.000324 0.000365 HTTP/1.1 200 OK
         0 Backend_health - nginx Still healthy 4--X-RH 5 3 5 0.000216 0.000245 HTTP/1.1 200 OK
         0 Backend_health - apache Still healthy ------- 4 3 5 0.000000 0.000365
         0 Backend_health - nginx Still healthy 4--X-RH 5 3 5 0.000244 0.000245 HTTP/1.1 200 OK
         0 Backend_health - apache Still healthy ------- 3 3 5 0.000000 0.000365
         0 Backend_health - nginx Still healthy 4--X-RH 5 3 5 0.000226 0.000240 HTTP/1.1 200 OK
         0 Backend_health - apache Went sick ------- 2 3 5 0.000000 0.000365
         0 Backend_health - nginx Still healthy 4--X-RH 5 3 5 0.000222 0.000236 HTTP/1.1 200 OK
         0 Backend_health - apache Still sick ------- 1 3 5 0.000000 0.000365
         0 Backend_health - nginx Still healthy 4--X-RH 5 3 5 0.000274 0.000245 HTTP/1.1 200 OK
         0 Backend_health - apache Still sick ------- 0 3 5 0.000000 0.000365
         0 Backend_health - nginx Still healthy 4--X-RH 5 3 5 0.000625 0.000340 HTTP/1.1 200 OK
         0 Backend_health - apache Still sick 4--X-RH 1 3 5 0.000936 0.000507 HTTP/1.1 200 OK
         0 Backend_health - nginx Still healthy 4--X-RH 5 3 5 0.000225 0.000311 HTTP/1.1 200 OK
         0 Backend_health - apache Still sick 4--X-RH 2 3 5 0.000793 0.000579 HTTP/1.1 200 OK
         0 Backend_health - nginx Still healthy 4--X-RH 5 3 5 0.000220 0.000288 HTTP/1.1 200 OK
         0 Backend_health - apache Back healthy 4--X-RH 3 3 5 0.000959 0.000674 HTTP/1.1 200 OK


root@config-p:jlive#varnishadm debug.health
Backend nginx is Healthy
Current states  good:  5 threshold:  3 window:  5
Average responsetime of good probes: 0.000249
Oldest                                                    Newest
================================================================
4444444444444444444444444444444444444444444444444444444444444444 Good IPv4
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Good Xmit
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR Good Recv
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH Happy
Backend apache is Healthy
Current states  good:  4 threshold:  3 window:  5
Average responsetime of good probes: 0.000363
Oldest                                                    Newest
================================================================
444444444444444444444444444444444-----4444444444444444444444444- Good IPv4
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-----XXXXXXXXXXXXXXXXXXXXXXXXX- Good Xmit
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR-----RRRRRRRRRRRRRRRRRRRRRRRRR- Good Recv
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH-----HHHHHHHHHHHHHHHHHHHHHHHHH- Happy

root@config-p:~#varnishadm debug.health
Backend nginx is Healthy
Current states  good:  5 threshold:  3 window:  5
Average responsetime of good probes: 0.000243
Oldest                                                    Newest
================================================================
4444444444444444444444444444444444444444444444444444444444444444 Good IPv4
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Good Xmit
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR Good Recv
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH Happy
Backend apache is Sick
Current states  good:  2 threshold:  3 window:  5
Average responsetime of good probes: 0.000363
Oldest                                                    Newest
================================================================
4444444444444444444444444444444-----4444444444444444444444444--- Good IPv4
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-----XXXXXXXXXXXXXXXXXXXXXXXXX--- Good Xmit
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR-----RRRRRRRRRRRRRRRRRRRRRRRRR--- Good Recv
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH-----HHHHHHHHHHHHHHHHHHHHHHHHH--- Happy

posted @ 2016-03-18 11:16  李庆喜  阅读(384)  评论(0编辑  收藏  举报