快速业务通道

Varnish安装部署文档

作者 佚名技术 来源 Linux系统 浏览 发布时间 2012-03-29

简述:Varnish是一款高性能的开源HTTP加速器,挪威最大的在线报纸 Verdens Gang 使用3台Varnish代替了原来的12台Squid,性能比以前更好.

系统环境:
CentOS release 5.5 (Final) 64-bit

所需软件:
varnish-2.1.4.tar.gz

Varnish官方网站:

http://www.varnish-cache.org/

安装前准备:

创建www用户和组,以及Varnish缓存文件存放目录(/elain/data/vcache):
/usr/sbin/groupadd www -g 600
/usr/sbin/useradd -u 600 -g www www
mkdir -p /elain/data/vcache
chmod w /elain/data/vcache
chown -R www:www /elain/data/vcache

创建Varnish日志目录(/elain/logs/varnish):
mkdir -p /elain/logs/varnish
chmod w /elain/logs/varnish
chown -R www:www /elain/logs/varnish

安装:
wget http://cdnetworks-kr-1.dl.sourceforge.net/project/pcre/pcre/8.12/pcre-8.12.tar.gz
tar zxvf pcre-8.12.tar.gz
cd pcre-8.12/
./configure --prefix=/elain/apps/pcre
make && make install
cd ../

wget http://repo.varnish-cache.org/source/varnish-2.1.5.tar.gz
tar zxvf varnish-2.1.5.tar.gz
cd varnish-2.1.5
export PKG_CONFIG_PATH=/elain/apps/pcre/lib/pkgconfig
./configure -prefix=/elain/apps/varnish
make
make install
cd ..

配置:
默认配置文件样板:
/elain/apps/varnish/etc/varnish/default.vcl

cd /elain/apps/varnish/etc/varnish/
cp default.vcl elain_vcl.conf
vi elain_vcl.conf
#############################
backend www {
.host = "www.elain.org";
.port = "80";
}

acl purge {
"localhost";
"127.0.0.1";
"172.16.2.0"/24;
}

sub vcl_recv {
if (req.restarts == 0) {
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For ", " client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
if (req.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
req.request != "POST" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE") {
/* Non-RFC2616 or CONNECT which is weird. */
return (pipe);
}
if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
if (req.http.Authorization || req.http.Cookie) {
/* Not cacheable by default */
return (pass);
}

else {
lookup;
}
return (lookup);
}

sub vcl_pipe {
return (pipe);
}

sub vcl_pass {
return (pass);
}

sub vcl_hash {
set req.hash = req.url;
if (req.http.host) {
set req.hash = req.http.host;
} else {
set req.hash = server.ip;
}
return (hash);
}

sub vcl_hit {
if (!obj.cacheable) {
return (pass);
}
return (deliver);
}

sub vcl_miss {
return (fetch);
}

sub vcl_fetch {
if (!beresp.cacheable) {
return (pass);
}
if (beresp.http.Set-Cookie) {
return (pass);
}
return (deliver);
}

sub vcl_deliver {
return (deliver);
}

sub vcl_error {
set obj.http.Content-Type = "text/html; charset=utf-8";
synthetic {"
<?xml version="1.0" e

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号