Varnish安装搭建配置缓存服务器

boante 2011-04-02

Varnish特点:安装 配置 简单,支持后端服务器的负载均衡和健康检查,URL地址重写。

官方下载地址:
wget http://www.varnish-software.com/sites/default/files/varnish-2.1.4.tar.gz
 
标准安装:

yum -y install automake autoconf libtool ncurses-devel libxslt groff pcre-devel pkgconfig
cd varnish-2.1.4
./configure --prefix=/usr/local/varnish
make && make install


简单配置文件:cat /usr/local/varnish/etc/varnish/default.vcl

backend default {
     .host = "127.0.0.1";
     .port = "9999";
}
#定义后端应用端口
sub vcl_recv {
     if (req.restarts == 0) {
        if (req.http.x-forwarded-for) {
            set req.http.X-Forwarded-For =
                req.http.X-Forwarded-For ", " client.ip;
        } else {
            set req.http.X-Forwarded-For = client.ip;
        }
     }

     if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
         return (lookup);
     }
     return (pass);
}
#图片、swf等静态文件设置缓存,其他类型文件pass到后端.
sub vcl_pipe {
      set bereq.http.connection = "close";
     return (pipe);
}

sub vcl_pass {
     return (pass);
}

启动Varnish:
/usr/local/varnish/sbin/varnishd -f /usr/local/varnish/etc/varnish/default.vcl -s malloc,128M -T 127.0.0.1:2500 -a 0.0.0.0:80

查看状态:
/usr/local/varnish/bin/varnishstat

查看Referer:
/usr/local/varnish/bin/varnishtop -i rxheader -I Referer

查看访问路径:
/usr/local/varnish/bin/varnishtop -i rxurl

相关推荐