2011年6月10日星期五

varnish安装记录

varnish和squid相比最大的优势就是简单快速,简单是安装和配置都简单,快速是运行速度比squid更快,当然,快的前提是varnish比squid占用更多的内存,估计当年设计squid的时候内存还是很贵的东西,所以更多的侧重硬盘,使用内存多,当然还有一个很显而易见的弱点是机器冷启动时候恢复缓存的时间相比squid要长。
wget http://downloads.sourceforge.net/project/varnish/varnish/2.0.6/varnish-2.0.6.tar.gz?use_mirror=ncu
tar zxvf varnish-2.0.6.tar.gz
cd varnish-2.0.6
./configure  –prefix=/srv/varnish
make
make install
启动命令:
/srv/varnish/sbin/varnishd -a :8088 -b localhost:8080
由于我指定了安装目录,所以加上了路径,-a参数表示varnish的监听端口,正常情况下应该监听是80端口,也就是web服务端口,我测试机上被使用掉了,所以用了8088端口, -b 是表示后端(backend)的地址,如果backend在这里指定,那么只能指定一个后端,如果使用的配置文件可以指定多个backend,我的配置文件位置位于/srv/varnish/etc/varnish。
在web服务器的目录中创建一个index.html文件,然后通过varnish进行代理访问.
第一次访问结果如下:
2
第二次访问结果如下:
3
根据请求头,我们看到的确是通过vanish来代理访问后端的,第一次访问age 为0 ,第二次访问age为71,说明这个文件已经在varnish中缓存了,此时可以通过/srv/varnish/bin/varnishstat 来查看一些参数,其中Hitrate 一行应该为1,因为命中了一次。
varnish 配置文件还是很有搞头的一个东西,有点类似与Nginx的语法,虽然不是很像,比如对正则的支持,可以绑定和去除head、Cookie等等功能,有时间的话,翻译一下varnish的introduction
安装编译的时候出现一下错误:
checking for library containing pthread_create... -lpthread
checking for socket in -lsocket... no
checking for getaddrinfo in -lnsl... yes
checking for cos in -lm... yes
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for PCRE... no
configure: error: Package requirements (libpcre) were not met:

No package 'libpcre' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables PCRE_CFLAGS
and PCRE_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

说是缺少 pcre。我安装nginx的时候用到了pcre 安装了的。后又重新安装。错误依旧在。Google  原来是ldconfig 都不行。 后终于找到解决办法:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
你再编辑 成功!
  good luck!

没有评论:

发表评论

上海松善实业有限公司

    上海松善实业有限公司是一家集多品牌销售于一体的电线电缆骨干企业,公司成立于2016年。 公司拥有国内各大品牌:起帆、远东、上上、江南、胜华等。     主要产品有:高低压电力电缆、橡套电缆、控制电缆、架空绝缘电缆、塑胶电缆、电子计算机电缆、通讯电缆、...