2014-04-17 19:46:01
来 源
IT技术网
Varnish
本文介绍varnish2.X配置,希望对于Varnish入门者给与帮助。更多Varnish资源请本站内搜索。
Varnish 2.0.3 has just been released. This release contains multiple changes, amongst them:

Support for backend timeouts

Multiple fixes in how we process ESI

restart in vcl_hit is now supported

Documentation has been updated

Expiry processing is now more scalable

The default session workspace is now 16k instead of 8k

More graceful handling of too many headers from the client or the server.

More expressive purges

之前一直使用的还是2.0的一个trunk的R2860版本,因为只有这个版本我从1.1.2升级上来以后没有慢的问题⊙﹏⊙。但是看着新版却一直不能用,实在是让人心里痒。于是抱着死磕到底的态度,在检查了n+1遍配置文件和修改启动参数重启了n+1遍Varnish以后终于找到了问题的所在,即启动参数的-w这个上面。那么这个参数是干什么用的呢?

-w int[,int[,int]]           # Number of worker threads

#   -w <fixed_count>

#   -w min,max

#   -w min,max,timeout [default: -w2,500,300]

可以看出这个参数是控制每个进程的线程数的,1.1.2版本的时候这个参数我配置的是-w30000,51200,10,貌似到了2.0版以后这个最小启动的线程数不能设定过大,于是在进行了几次调试以后最终将参数定为了-w5,51200,30

软件列表

pcre-8.02.tar.gz

varnish-2.1.tar.gz

软件存放位置

/data/software

安装过程

# /usr/sbin/groupadd www -g 48

# /usr/sbin/useradd -u 48 -g www www

# mkdir -p /data/vcache

# chmod +w /data/vcache

# chown -R www:www /data/vcache

# mkdir -p /var/log/varnish

# chmod +w /var/log/varnish

# chown -R www:www /var/log/varnish

# cd /data/software/pkg

# tar zxvf ../pcre-8.02.tar.gz

# cd pcre-8.02

# ./configure

# make && make install

# cd ..

# tar zxvf ../varnish-2.1.tar.gz

# cd varnish-2.1

# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

# ./configure –prefix=/usr/local/varnish

# make && make install

编辑Varnish配置文件

# vi /usr/local/varnish/vcl.conf

backend webserver {

set backend.host = “10.10.10.8″;

set backend.port = “80″;

}

acl purge {

“localhost”;

“127.0.0.1″;

“10.10.10.0″/24;

}

sub vcl_recv {

remove req.http.X-Forwarded-For;

set    req.http.X-Forwarded-For = client.ip;

if (req.request == “PURGE”) {

if (!client.ip ~ purge) {

error 405 “Not allowed.”;

}

lookup;

}

if (req.http.host ~ “(a|b|c).test.com”) {

set req.backend = webserver;

if (req.url ~ “.(png|gif|jpg|swf|css|js)$”) {

lookup;

}

else {

pass;

}

}

else {

error 404 “Test Cache Server”;

pipe;

}

}

sub vcl_hash {

set req.hash += req.url;

if (req.http.host) {

set req.hash += req.http.host;

} else {

set req.hash += server.ip;

}

hash;

}

sub vcl_pipe {

set req.http.connection = “close”;

#pipe;

}

sub vcl_hit {

if (!obj.cacheable) {

pass;

}

if (req.request == “PURGE”) {

set obj.ttl = 0s;

error 200 “Purged.”;

}

deliver;

}

sub vcl_miss {

if (req.request == “PURGE”) {

error 404 “Not in cache.”;

}

}

sub vcl_fetch {

set obj.ttl = 180s;

#set    obj.http.X-Varnish-IP = server.ip;

set    obj.http.Varnish = “Tested by Kevin”;

}

启动Varnish

# /usr/local/varnish/sbin/varnishd -n /data/vcache -f /usr/local/varnish/etc/varnish/default.vcl -a 10.10.10.8:80 -s file,/data/vcache/varnish_cache.data,50G -u www -w2,65536,60 -T 127.0.0.1:3600 -p thread_pool_min=200 -p thread_pool_max=4000 -p thread_pools=4 -p thread_pool_add_delay=2 -p listen_depth=4096 -p lru_interval=20

启动日志记录

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

声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。