当前位置: 首页 > 图文教程 > 服务器 > Linux服务器 > 搭建性能比Squid高很多的Varnish服务器

Linux服务器
Linux上双网卡绑定方法(Suse9SP3)
Linux操作系统调优参数的意义
Linux下使用SSH客户端及其Sftp文件传送
教你恢复被误删除的Linux文件
SQL Server注入大全及防御
Linux无法解析域名的解决办法
Linux系统下安装和配置MyEclipse的方法
Ubuntu下VirtualBox 1.4.0设置文件共享
Windows与Linux系统共享StarDict字典文件
修改Linux下相关的登陆信息
Windows通过SecureCRT远程登录Linux主机
Linux操作系统如何修改SWAP交换区的大小
Linux操作系统下为Apache目录添加密码
Linux时间设置与同步(NTP)
Linux内核补丁AMD旁路转换缓冲(TLB)错误
Linux架设DHCP服务器的方法
Fedora 8下Apache配置与管理
Linux操作系统下用单网卡捆绑双IP的方法
Ubuntu Linux系统环境变量配置文件
SUSE Linux中将Tomcat作为Service运行

Linux服务器 中的 搭建性能比Squid高很多的Varnish服务器


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-18   浏览: 79 ::
收藏到网摘: n/a

Arnish是一款高性能的开源HTTP加速器,挪威最大的在线报纸VerdensGang(http://www.vg.no)使用3台Varnish代替了原来的12台squid。性能比以前更好。varnish的作者Poul-HenningKamp是FreeBSD的内核开发者之一,他认为现在的计算机比起1975年已经复杂许多。在1975年时,储存媒介只有两种:内存与硬盘。但现在计算机系统的内存除了主存外,还包括了cpu内的L1、L2,甚至有L3快取。硬盘上也有自己的快取装置,因此squidcache自行处理物件替换的架构不可能得知这些情况而做到最佳化,但操作系统可以得知这些情况,所以这部份的工作应该交给操作系统处理,这就是Varnishcache设计架构。1.下载源码包编译安装:cd/usr/local/src&&wgethttp://nchc.dl.sourceforge.net/s...arnish-1.1.1.tar.gztarzxvf/usr/local/src/varnish-1.1.1.tar.gzcd/usr/local/src/varnish-1.1.1./autogen.sh./configure--enable-debugging-symbols--enable-developer-warnings--enable-dependency-tracking注:如果你的gcc版本是4.2.0或更高的版本,可以加上--enable-extra-warnings编译参数,在出错时,得到附加的警告信息。我这里是用源码包安装的,如果你是redhat或centos可以用rpm包来安装(rpm下载位置:http://sourceforge.net/project/showfiles.php?group_id=155816&package_id=173643&release_id=533569).2.建立cache目录:mkdir-p/cache/varnish/V&&chown-Rnobody:nobody/cache3.编写启动文件:cd/usr/local/varnish/sbinvistart.sh内容如下:#!/bin/sh#file:go.shdate-u/usr/local/varnish/sbin/varnishd\-a10.0.0.129:80\-sfile,/cache/varnish/V,1024m\-f/usr/local/varnish/sbin/vg.vcl.default\-pthread_pool_max=1500\-pthread_pools=5\-plisten_depth=512\-pclient_http11=on\注:-a是指定后端服务器的ip或hostname,就象squid做reveseproxy时的originserver.不过这个也可以在vcl里面写。-f是指定所用的vcl的文件。-s指定cache目录的存储类型,文件位置和大小。-p是指定varnish的启动的一些启动参数,可以根据自己的机器配置来优化varnish的性能。其他参数已经参数的具体含义可以用varnishd--help来查看。

4.编写vcl:我的vcl如下:backenddefault{setbackend.host="127.0.0.1";setbackend.port="http";}#我用的是一台机器做测试,使用的backend用的是127.0.0.1:80.如果varnish机器和后台的机器分开的。写上对应的机器的ip或hostname就可以了。subvcl_recv{if(req.request!="GET"&&req.request!="HEAD"){pipe;}if(req.http.Expect){pipe;}if(req.http.Authenticate||req.http.Cookie){pass;}if(req.request=="GET"&&req.url~"\.(gif|jpg|swf|css|js)$"){lookup;}lookup;}subvcl_pipe{pipe;}subvcl_pass{pass;}subvcl_hash{hash;}subvcl_hit{if(!obj.cacheable){pass;}deliver;}subvcl_timeout{discard;}subvcl_discard{discard;}如果是多个站点在不同的originserver时,可以使用下面配置:backendwww{setbackend.host="www.jackbillow.com";setbackend.port="80";}backendimages{setbackend.host="images.jackbillow.com";setbackend.port="80";}subvcl_recv{if(req.http.host~"^(www.)?jackbillow.com$"){setreq.http.host="www.jackbillow.com";setreq.backend=www;}elsif(req.http.host~"^images.jackbillow.com$"){setreq.backend=images;}else{error404"Unknownvirtualhost";}5.启动varnish:/usr/local/varnish/sbin/start.shMonSep303:13:19UTC2007file/cache/varnish/V/varnish.tEKXXx(unlinked)size1073741824bytes(262144fs-blocks,262144pages)UsingoldSHMFILEpswaux|grepvarnishroot162540.00.011200708?Ss10:430:00/usr/local/varnish/sbin/varnishd-a10.0.0.129:80-s/varnish/V,1024m-f/usr/local/varnish/sbin/vg.vcl.default-pthread_pool_max1500-pthread_pools5-plisten_depth512-pclient_http11onnobody162550.00.111525521808?Sl10:430:00/usr/local/varnish/sbin/varnishd-a10.0.0.129:80-sfile,/cache/varnish/V,1024m-f/usr/local/varnish/sbin/vg.vcl.default-pthread_pool_max1500-pthread_pools5-plisten_depth512-pclient_http11on看到上面信息说明varnish正确启动,恭喜你,你已经配置成功了。

上一页[1][2]