博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

ljh1405

  ljh1405.cublog.cn

关于作者
姓名:李建辉
职业:
年龄:
位置:
个性介绍:
|| << >> ||
我的分类


varnish cache 配置使用
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";
         }
         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
 
 

发表于: 2007-09-06,修改于: 2007-09-06 13:11,已浏览1929次,有评论7条 推荐 投诉


网友评论
网友: 本站网友 时间:2007-09-06 15:57:09 IP地址:218.14.65.★
它能用作代理上网的服务器?

网友: ljh1405 时间:2007-09-06 16:50:03 IP地址:121.0.31.★
理论上是不合适的,主要是用作网站加速,反向代理

网友: 本站网友 时间:2007-09-09 15:40:48 IP地址:61.240.220.★
上述的你的配置文件,都测试通过了了没有!为什么我的虚拟主机配置不能成功,怎么可以才能确认有没有缓存,缓存文件类型和大小都是怎么控制的,这些你都测试过了!!嘿嘿,希望你能的写的太详细一点!谢谢…………

网友: ljh1405 时间:2007-09-09 22:28:58 IP地址:60.177.68.★
以上配置都在身产环境测试过了,至于缓存是否命中可以使用工具比如firfox的firbug等来看http的头是否有cache命中记录等。

网友: shgjj9 时间:2007-09-28 13:52:30 IP地址:121.0.31.★
你的blog更新速度能不能快点?写着写着怎么就睡着了呢?……

网友: 本站网友 时间:2007-12-22 00:50:58 IP地址:211.145.7.★
我编译varnish在as 4.4,configure是我看到脚本已经检测到epoll,但是当程序运行时我使用strace命令查看发现varnish在使用poll,怎么才能让varnish使用epoll呢,谢谢!

网友: 本站网友 时间:2008-02-26 18:18:12 IP地址:61.171.222.★
请教您在多大的生产环境下使用了这个技术啊..
效率真的有那么高吗..比squid强2-4被

 发表评论