鼓动简谱:varnish cache 配置使用

来源:百度文库 编辑:偶看新闻 时间:2024/04/28 16:19:13

varnish cache 配置使用

类别:网络服务配置 发布时间:2009年05月05日 出处:不详 收藏此篇文章

varnishd 配置及其使用
varnishd是一款全新的cache软件,据作者说采用的是最新的软件体系机构,和现在的硬件体系配合紧密。远胜过以前的squid,相同配置下,据说1台能顶3-4台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
#    -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 参数了
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″;
}

backend images {
set backend.host = ”images.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]

大家可以使用-p参数在启动时候进行配置和优化
例如
/home/admin/varnish/sbin/varnishd -f /etc/varnish/vcl.conf \
-a 172.16.189.1:3128 \
-s malloc \
-p user root -p group root \
-p default_ttl 14400 -p thread_pool_max 8000 -p send_timeout 20 \
-p srcaddr_ttl 720 -p backend_http11 on -p client_http11 on \
-w 4000,12000,10 -T 127.0.0.1:8080
6.关于varnishd的管理
管理功能的启用需要在启动varnishd的时候 启动 -T参数指定 telnet管理使用的地址和端口
使用telnet localhost 8080,然后输入help参看相关的管理选项
或者使用 /home/admin/varnishd/bin/varnishadm -T localhost:8080 cmd进行管理
使用/home/admin/varnishd/bin/varnishstat 来查看varnishd的运行情况
7.关于log
使用home/admin/varnishd/bin/varnishlog  和varnishncsa查看服务器访问log或者让其输出到文件来记录log

具体问题可以在我的blog商讨

http://blog.chinaunix.net/u1/47198/showart_375385.html