Varnish状态监测机制
可以使用backend probe进行定义
我们在backend
每个后端服务器当前探测的健康状态探测方法通过.probe进行设定,其结果可由req.backend.healthy变量获取,也可通过varnishlog中的Backend_health查看或varnishadm的debug.health查看。
例:
backend web1 {
.host = "www.magedu.com";
.probe = {
.url="/.healthtest.html"; #探测请求哪个文件做监测
.interval = 1s; #指定超时时间
.window = 5; #采样几次
.threshold = 2; #预值,至少重复采样几次认为正常
}
}
定义检测机制
probe healtchk {
.url ="/";
.interval = 1s;
.timeout = 0.1s;
.expected_response= 200;
}
backendimageserver1 {
.host ="10.0.10.63";
.port ="8080";
.probe = healtchk;
}
backendappserver1 {
.host ="10.0.10.62";
.port ="8080";
.probe = healtchk;
}
subvcl_recv {
setreq.http.X-Forward-For = client.ip;
if(req.url ~"index.html$") {
return(pass);
}
if(req.url ~"\.php$") {
set req.backend =appserver1;
} else {
set req.backend =imageserver1;
}
}
sub vcl_deliver {
if(obj.hits > 0){
setresp.http.X-Cache = "HIT from"+""+ server.ip;
} else {
setresp.http.XCahche= "MISS";
}
}
varnish>vcl.loadtest7 ./test.vcl
200
VCL compiled.