编译安装 Varnish Cache 2.1.3 通过 

前端时间,squid 爆了漏洞,心里感觉还是不能情绪稳定.最近又看到了varnish 这款http 缓存服务器的崛起,觉得很是棒.

再者说,squid 本不是专业反向代理服务器(服务端缓存),而是正向代理服务器(客户端缓存).而varnish cache 则是专业做反向代理的。这是其一.

再者,squid 的体积越来越大,这是我不敢想的。源码压缩包 3M多,解压后竟达10多M...

再看varnish 则小巧了许多.不要1M.解压后才3M多.而且在内存占用方面,varnish 更是让我这台512M 的vps 轻松的多。

最后一点,varnish 的效率据说高于squid.有这么多的理由,我便干掉了squid,投奔varnish了.

下载最新版本 2.1.3 的源码包,解压,进入目录
我的configure:
[root@PowerPC varnish-2.1.3]# ./configure \
> --prefix=/usr/local/varnish \
> --exec-prefix=/usr/local \
> --sysconfdir=/etc/sysconfig/varnish \
> --localstatedir=/var \
> --enable-shared=yes \
> --enable-static=no \
> --disable-largefile

检查依赖,一切OK.接下来 make && make install.
编译时间很快,比起squid 真是快了几倍。呵呵

编辑自动生成的default.vcl 配置文件,这里要说一下,不同于一下配置文件的格式,varnish 使用的是一个叫VCL (Varnish Confingure Language)的语言作为配置文件。囧rz 其实就是一些很简单的条件判断语句什么 if else 之类的.
更不会有switch 之类的,只要你写过一点程序,这些都不是难题.

为了让用户更好的编辑VCL文件,varnish 还提供了用于VIM 的语法高亮文件.
地址:http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/~checkout~/packages/vim-syntax-vcl/vcl.vim

下载放到指定目录即可.

接下开始编辑配置文件,按照官方的wiki提示,
新建几台后置服务器,分别运行于不同端口.

比如我的vps 有cherokee、nginx、lighttpd、tomcat 等.

backend to_cherokee {
.host = "127.0.0.1";
.port = "81";
}

backend to_lighttpd {
.host = "127.0.0.1";
.port = "82";
}

backend to_nginx {
.host = "127.0.0.1";
.port = "83";
}

backend to_tomcat {
.host = "127.0.0.1";
.port = "84";
}


再根据不同的域名转发到对应的后置服务器,

if (req.http.host ~ "^(\w*.)?xiazhengxin.cn$") {
set req.backend = to_cherokee;
}

if (req.http.host ~ "^(\w*.)?xiazhengxin.tk$") {
set req.backend = to_nginx;
}

if (req.http.host ~ "^(\w*.)?xiazhengxin.org.cn$") {
set req.backend = to_lighttpd;
}

if (req.http.host ~ "^(\w*.)?xxx.xxx$") {
set req.backend = to_tomcat;
}


上段代码须放入sub vcl_recv {} 块中.

当然还可以自定义错误.编辑 sub vcl_error {} 块即可.

更多配置详见:http://www.varnish-cache.org/trac/wiki/VCL

这里还有一些例子可供参考:
http://www.varnish-cache.org/trac/wiki/VCLExamples

一切配置完成后,运行 varnishd 启动服务器.
报错:
varnishstat: error while loading shared libraries: libvarnish.so.1: cannot open shared object file: No such file or directory


运行ldconfig 即可.

再次运行
[root@PowerPC varnish]# varnishd -a :80 -f default.vcl -u http
启动成功.
[ ] ( 2679 次浏览 ) 永久链接 ( 3 / 2574 )

<< <上一页 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 下一页> >>