百度空间 | 百度首页 
 
查看文章
 
安装varnish2.0.2
2009-06-30 09:42
From: http://www.sysbus.com/?p=117

varnish作为后起的cache软件,据说比squid性能要好,但是也有不少反面意见,于是自己安装测试一下

下载最新的版本varnish-2.0.2.tar.gz (官方网站是 http://varnish.projects.linpro.no)

1、创建www用户和组,以及Varnish缓存文件存放目录(/var/vcache):

/usr/sbin/groupadd www -g 48
/usr/sbin/useradd -u 48 -g www www
mkdir -p /var/vcache
chmod +w /var/vcache
chown -R www:www /var/vcache

2、创建Varnish日志目录(/var/logs/):

mkdir -p /var/vlogs
chmod +w /var/vlogs
chown -R www:www /var/vlogs

3、编译安装varnish:

tar zxvf varnish-2.0.2.tar.gz
cd varnish-2.0.2
./configure --prefix=/usr/local/varnish
make && make install

4、创建Varnish配置文件:

backend myblogserver {
.host = "10.1.32.125";
.port = "80";
}

acl purge {
“localhost”;
“127.0.0.1″;
“192.168.1.0″/24;
}

sub vcl_recv {
if (req.request == “PURGE”) {
if (!client.ip ~ purge) {
error 405 “Not allowed.”;
}
lookup;
}

if (req.http.host ~ “^nginx.xxx.com”) {
set req.backend = myblogserver;
if (req.request != “GET” && req.request != “HEAD”) {
pipe;
}
else {
lookup;
}
}
else {
error 404 “the server is wrong!”;
lookup;
}
}

sub vcl_hit {
if (req.request == “PURGE”) {
set obj.ttl = 0s;
error 200 “Purged.”;
}
}

sub vcl_miss {
if (req.request == “PURGE”) {
error 404 “Not in cache.”;
}
}

sub vcl_fetch {
if (req.request == “GET” && req.url ~ “\.(txt|js)$”) {
set obj.ttl = 10s;
}
else {
set obj.ttl = 30d;
}
}

5、启动Varnish

ulimit -SHn 51200
/usr/local/varnish/sbin/varnishd -n /var/vcache -f /usr/local/varnish/vcl.conf -a 10.1.97.109:80 -s file,/var/vcache/varnish_cache.data,1G -g www -u www -w 30000,51200,10 -T 127.0.0.1:3500 -p client_http11=on

6、启动varnishncsa用来将Varnish访问日志写入日志文件:

/usr/local/varnish/bin/varnishncsa -n /var/vcache -w /var/vlogs/varnish.log&

注意:
启动的时候出错,提示
storage_file: filename: /var/vcache/varnish_cache.data size 1024 MB.
Undefined backend www, first reference:
(/usr/local/varnish/vcl.conf Line 13 Pos 25)
set req.backend=www;
————————###-

VCL compilation failed

经查资料要把set backend.host=”xxx”换成.host=”xxx”,以及set backend.prt=”xxx”换成.port=”xxx”
(http://varnish.projects.linpro.no/browser/trunk/varnish-cache/bin/varnishd/cache_backend_simple.c?rev=2356)

启动参数说明
-a address:port # varnishd httpd监听地址及其端口
-b address:port # 后台服务器地址及其端口
# -b
# -b ':
'
-d # 使用debug模式
-f file # varnishd 服务器存取规则文件
-F # Run in foreground
-h kind[,hashoptions] # Hash specification
# -h simple_list
# -h classic [default]
# -h classic,
-n dir # varnishd working directory
-P file # PID file
-p param=value # 服务器参数,用来优化性能
-s kind[,storageoptions] # 缓存内容存放方式
# -s malloc
# -s file [default: use /tmp]
# -s file,
# -s file,,
-t # Default TTL
-T address:port # telnet管理地址及其端口
-V # version
-w int[,int[,int]] # 工作线程数
# -w
# -w min,max
# -w min,max,timeout [default: -w1,1000,120]
一般使用varnishd -a address:port -b address:port 其他使用默认即可启动
注意:vcl 中指定 后台服务器的话就不用使用-b 参数了

类别:Linux | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu