Varnish部署以及配置

经过几天的varnish研究发现varnish还是属于轻量级的Proxy Cache,除了大众认为它使用内存的优势外,我发现varnish也非常好嵌入,当然是使用C语言来嵌入

安装…无非就是./configure , make , make install,在此不再重复废话了,可以参考http://blog.s135.com/post/313/

我的启动脚本(使用内存作Cache):

  1. /usr/local/varnish/sbin/varnishd -n /mnt/varnish -f /usr/local/varnish/vcl.conf -a 0.0.0.0:8080 -s malloc,512M -g www -u www -w 30000,51200,10 -T 127.0.0.1:3500 -p thread_pool_min=200 -p thread_pool_max=4000 -p thread_pools=4

还有一点就是上面提及到的比较好嵌入C来完成一些额外的功能
比如有这么个功能:

背景:请先访问 www.sitebot.com.cn,你会发现首页会随机出列表内容,如果使用squid或varnish来cache首页的话就相当于改了老板的需求,当然这个是老板最不能容忍的,我也没有这么看不开去挑战老板的容忍度…

需求:还是把www.sitebot.com.cn缓存起来,但要求首页要随机出列表内容

解决方案:
  方法有很多,你可以使用php层来做,这里我使用varnish来实现,在vcl.conf嵌入少量的C就能很方便的完成这个功能了

嵌入的核心代码是:

  1. char random_index[2];
  2. sprintf(random_index,"%d",(unsigned)time(0)%11);
  3. VRT_l_req_url(sp, replacestr(index_url,"0",random_index), vrt_magic_string_end);

目前这个功能已经完成,下一步将要进行一些压力测试,有兴趣的朋友继续关注我的blog吧:)

This entry was posted on 星期一, 一月 11th, 2010 at 4:50 下午 and is filed under c/c++, 项目经验. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Varnish部署以及配置”

virteman 一月 12th, 2010 at 9:04 下午

很强大,强烈关注中。

Leave a Reply