标签:清除缓存 erro reads 访问 mod root turn tor IV
系统环境:rhel6.5 server8.9安装http服务###查看缓存命中情况
[root@server7 ~]# vim /etc/varnish/default.vcl
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT from westos cache";
}
else {
set resp.http.X-Cache = "MISS from westos cache";
}
return (deliver);
}
[root@server7 ~]# /etc/init.d/varnish reload
###测试缓存命中###第一次为MISS,第二次以后为HIT
[root@localhost ~]# curl -I www.redhat.org
HTTP/1.1 200 OK
Server: Apache/2.2.15 (Red Hat)
Last-Modified: Thu, 28 Jun 2018 07:01:14 GMT
ETag: "3fe8f-10-56fae4c10bfcc"
Content-Type: text/html; charset=UTF-8
Content-Length: 16
Accept-Ranges: bytes
Date: Thu, 28 Jun 2018 07:43:48 GMT
X-Varnish: 657573205
Age: 0
Via: 1.1 varnish
Connection: keep-alive
X-Cache: MISS from westos cache
[root@localhost ~]# curl -I www.redhat.org
HTTP/1.1 200 OK
Server: Apache/2.2.15 (Red Hat)
Last-Modified: Thu, 28 Jun 2018 07:01:14 GMT
ETag: "3fe8f-10-56fae4c10bfcc"
Content-Type: text/html; charset=UTF-8
Content-Length: 16
Accept-Ranges: bytes
Date: Thu, 28 Jun 2018 07:45:02 GMT
X-Varnish: 657573206 657573205
Age: 73
Via: 1.1 varnish
Connection: keep-alive
X-Cache: HIT from westos cache
通过 varnishadm 手动清除缓存
varnishadm ban.url .*$ #清除所有#
varnishadm ban.url /index.html #清除 index.html 页面缓存#
varnishadm ban.url /admin/$ #清除 admin 目录缓存
定义多个不同域名站点的后端服务器
[root@server7 ~]# vim /etc/varnish/default.vcl
sub vcl_recv { if (req.http.host ~ "^(www.)?redhat.org") { set req.http.host = "www.redhat.org"; set req.backend = web1; } elsif (req.http.host ~ "^bbs.redhat.org") { set req.backend = web2; } else {error 404 "redhat cache"; }}
#当访问 www.westos.org 域名时从 web1 上取数据,访问 bbs.westos.org 域名时到 web2 取数据,访问其他页面报错。
[root@server7 ~]# /etc/init.d/varnish reload
Loading vcl from /etc/varnish/default.vcl
Current running config name is reload_2018-06-28T15:43:07
Using new config name reload_2018-06-28T16:13:06
VCL compiled.
available 0 boot
available 2 reload_2018-06-28T15:43:07
active 0 reload_2018-06-28T16:13:06
物理机测试:
[root@localhost ~]# curl bbs.redhat.org
server9
[root@localhost ~]# curl www.redhat.org
<h1>server8<h1>
浏览器访问:
定义负载均衡
#定义健康检查 ##可不配置
probe healthcheck { .url = "/index.html"; # 哪个 url 需要 varnish 请求 .interval = 5s; #检查的间隔时间
.timeout = 1s; #等待多长时间探针超时
.window = 5; #维持 5 个 sliding window 的结果
.threshold = 3; #至少有三次 window 是成功的,就宣告 bachend 健康 }
[root@server7 ~]# vim /etc/varnish/default.vcl
director lb round-robin { #把多个后端聚合为一个组,并检测后端健康状况 { .backend = web1; }
{ .backend = web2; }
}
sub vcl_recv {
if (req.http.host ~ "^(www.)?redhat.org") {
set req.http.host = "www.redhat.org";
set req.backend = lb ;
return (pass); #为了测试方便,不进行缓存。
} elsif (req.http.host ~ "^bbs.redhat.org") {
set req.backend = web2;
} else {error 404 "redhat cache";
}
}
物理机测试;
[root@localhost ~]# for i in {1..10}; do curl www.redhat.org;done
<h1>server8<h1>
<h1>server 9 </h1>
<h1>server8<h1>
<h1>server 9 </h1>
<h1>server8<h1>
<h1>server 9 </h1>
<h1>server8<h1>
<h1>server 9 </h1>
<h1>server8<h1>
<h1>server 9 </h1>
标签:清除缓存 erro reads 访问 mod root turn tor IV
原文地址:http://blog.51cto.com/13810716/2133834