1:安装
http://repo.varnish-cache.org/redhat/varnish-3.0/el6/x86_64/ # yum localinstall varnish-3.0.5-1.el6.x86_64.rpm varnish-libs-3.0.5-1.el6.x86_64.rpm
2:配置:
将其监听端口修改为80端口以响应apache
# vim /etc/sysconfig/varnish
# # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
# VARNISH_LISTEN_ADDRESS=
VARNISH_LISTEN_PORT=80
##查看缓存命中情况
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT from data cache";
}
else {
set resp.http.X-Cache = "MISS from dat cache";
}
return (deliver);
}
# service varnish reload
[root@server1 ~]# curl -I 192.168.122.10
HTTP/1.1 200 OK
Server: Apache/2.2.15 (Red Hat)
Last-Modified: Mon, 29 Jun 2015 12:41:02 GMT
ETag: "10c5-14-519a76705da97"
Content-Type: text/html; charset=UTF-8
Content-Length: 20
Accept-Ranges: bytes
Date: Mon, 29 Jun 2015 12:52:41 GMT
X-Varnish: 933387577
Age: 0
Via: 1.1 varnish
Connection: keep-alive
X-Cache: MISS from data cache #未命中
[root@server1 ~]# curl -I 192.168.122.10
HTTP/1.1 200 OK
Server: Apache/2.2.15 (Red Hat)
Last-Modified: Mon, 29 Jun 2015 12:41:02 GMT
ETag: "10c5-14-519a76705da97"
Content-Type: text/html; charset=UTF-8
Content-Length: 20
Accept-Ranges: bytes
Date: Mon, 29 Jun 2015 12:53:09 GMT
X-Varnish: 933387578 933387577
Age: 28
Via: 1.1 varnish
Connection: keep-alive
X-Cache: HIT from data cache #命中