Chinaunix首页 | 论坛 | 博客
  • 博客访问: 80242
  • 博文数量: 52
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: -20
  • 用 户 组: 普通用户
  • 注册时间: 2018-06-04 17:51
文章分类

全部博文(52)

文章存档

2013年(6)

2012年(3)

2011年(4)

2010年(18)

2009年(21)

我的朋友

分类: 系统运维

2010-06-28 10:32:05

varnishd简单安装
1.下载varnishd
     varnish 官方网站是
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 = "";
             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 = "";
             set backend.port = "80";
         }
         backend images {
             set backend.host = "images.example.com";
             set backend.port = "80";
         }
         sub vcl_recv {
             if (req.http.host ~ "^(") {
                 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
阅读(1265) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~