1, Varnish采用了Squid具有优势,它避免了 Varnish已经有一个月,没有发生过故障,而Squid服务器就倒过几次。Varnish管理端口,可以使用正则表达式快速、批量地清除部分缓存,这一点是<span style="font-family: "Tahoma','sans-serif'; FONT-SIZE: 9pt" lang=EN-US>Squid
不能具备的。
说明:
web server 前端:192.168.10.127
Varnish 缓存服务:192.168.10.41
web server 后端:192.168.10.30
web server 后端:192.168.10.43
-----------------------------------------------------
tar zxvf varnish-2.1.3.tar.gz -C /usr/src/
cd /usr/src/varnish-2.1.3/
./configure --prefix=/usr/local/varnish
make && make install
cd /usr/local/varnish/etc/varnish/
cp default.vcl mos.conf
------------------------------------------------------------------------------------------------------------ # This is a basic VCL configuration file for varnish.See the vcl(7) # man page for details on VCL syntax and semantics. # Default backend definition.Set this to point to your content # Below is a commented-out copy of the default VCL logic.If you # redefine any of these subroutines, the built-in logic will be if (req.http.x-forwarded-for) { set req.http.X-Forwarded-For = req.http.X-Forwarded-For ", " 192.168.10.30; set req.http.X-Forwarded-For = 192.168.10.43; if (req.request != "GET" && req.request != "TRACE" && req.request != "OPTIONS" && req.request != "DELETE") { /* Non-RFC2616 or CONNECT which is weird. */ if (req.request != "GET" && req.request != "HEAD") { #/* We only deal with GET and HEAD by default */ if (req.http.Authorization || req.http.Cookie) { #/* Not cacheable by default */ ## Note that only the first request to the backend will have ## X-Forwarded-For set.If you use X-Forwarded-For and want to ## have it set for all requests, make sure to have: ## set req.http.connection = "close"; ## here.It is not set by default as it might break some broken web ## applications, like IIS with NTLM authentication. set req.hash += req.http.host; set req.hash += server.ip; if (beresp.http.Set-Cookie) { if (beresp.http.Pragma ~ "no-cache" || beresp.http.Cache-Control ~ "no-cache" || beresp.http.Cache-Control ~ "private") { if (req.request == "GET" && req.url ~ "\.(txt|js|css|shtml|html|htm)$") { set resp.http.x-hits = obj.hits ; set resp.http.X-Cache = "HIT cqtel-bbs"; set resp.http.X-Cache = "MISS cqtel-bbs"; :wq!
mkdir -p /data/varnish/{cache,logs}
chmod +w /data/varnish/{cache,logs}
groupadd www
useradd www -g www -s /sbin/nologin
chown -R www:www /data/varnish/{cache,logs}
/usr/local/varnish/sbin/varnishd -u www -g www -f /usr/local/varnish/etc/varnish/mos.conf -a 192.168.10.41:80 -s file,/data/varnish/cache/varnish_cache.data,256MB -w 256,2560,10 -t 3600 -T 192.168.10.41:3000