varnishd 配置及其使用
varnishd是一款全新的cache软件,据作者说采用的是最新的软件体系机构,和现在的硬件体系配合紧密。远胜过以前的squid
varnishd简单安装
1.下载varnishd
varnish 官方网站是
http://varnish.projects.linpro.no/2.编译,没什么说的,默认即可
tar -zxvf varnish-1.1.1.tar.gz;cd varnish-1.1.1; ./configure --prefix=/home/admin/varnishd;make ;make install
3.关于varnishd的启动
进入 /home/admin/varnishd/sbin/,使用 varnishd启动
启动参数说明
-a address:port # varnishd httpd监听地址及其端口
-b address:port # 后台服务器地址及其端口
# -b <hostname_or_IP>
# -b '<hostname_or_IP>:<port_or_service>'
-d # 使用debug模式
-f file # varnishd 服务器存取规则文件
-F # Run in foreground
-h kind[,hashoptions] # Hash specification
# -h simple_list
# -h classic [default]
# -h classic,<buckets>
-n dir # varnishd working directory
-P file # PID file
-p param=value # 服务器参数,用来优化性能
-s kind[,storageoptions] # 缓存内容存放方式
# -s malloc
# -s file [default: use /tmp]
# -s file,<dir_or_file>
# -s file,<dir_or_file>,<size>
-t # Default TTL
-T address:port # telnet管理地址及其端口
-V # version
-w int[,int[,int]] # 工作线程数
# -w <fixed_count>
# -w min,max
# -w min,max,timeout [default: -w1,1000,120]
一般使用varnishd -a address:port -b address:port 其他使用默认即可启动
注意:vcl 中指定 后台服务器的话就不用使用-b 参数了
4.关于vcl文件的使用说明
vcl是varnishd的存取策略,即varnishd的配置文件
#基本格式如下指定后台服务器机器端口
backend www {
set backend.host = "
www.example.com";
set backend.port = "http";
}
#acl访问控制
acl local {
"locahost"; /* myself */
"10.0.0.1"/8; /* and everyone on the local network */
! "10.0.0.23"; /* except for the dialin router */
}
#如果使用虚拟主机,请参照下面代码
backend www {
set backend.host = "
www.example.com";
set backend.port = "80";
}
sub vcl_recv {
if (req.http.host ~ "^(
www.)?example.com$") {
set req.backend = www;
} elsif (req.http.host ~ "^images.example.com") {
set req.backend = images;
} else {
error 404 "Unknown virtual host";
}
}
#关于cache存在时间设置
sub vcl_fetch {
if (obj.ttl < 120s) {
set obj.ttl = 120s;
}
}
#cache图片等内容配置
sub vcl_recv {
if (req.request == "GET" && req.url ~ "\.(gif|jpg||jpeg|tom|swf|css|js)$") {
lookup;
}
lookup;
}
5.关于服务器 param的设置
param有以下选项
user root (0)
group root (0)
default_ttl 14400 [seconds]
thread_pools 1 [pools]
thread_pool_max 12000 [threads]
thread_pool_min 4000 [threads]
thread_pool_timeout 10 [seconds]
overflow_max 100 [%]
http_workspace 8192 [bytes]
sess_timeout 5 [seconds]
pipe_timeout 60 [seconds]
send_timeout 20 [seconds]
auto_restart on [bool]
fetch_chunksize 128 [kilobytes]
sendfile_threshold unlimited [bytes]
vcl_trace off [bool]
listen_address 172.16.189.1:3128
listen_depth 1024 [connections]
srcaddr_hash 1049 [buckets]
srcaddr_ttl 720 [seconds]
backend_http11 on [bool]
client_http11 on [bool]
ping_interval 3 [seconds]