搭建性能比Squid高很多的Varnish服務(wù)器 |
發(fā)布時(shí)間: 2012/8/11 11:03:32 |
Arnish是一款高性能的開源HTTP加速器,挪威最大的在線報(bào)紙VerdensGang(http://www.vg.no)使用3臺(tái)Varnish代替了原來的12臺(tái)squid。性能比以前更好。varnish的作者Poul-HenningKamp是FreeBSD的內(nèi)核開發(fā)者之一,他認(rèn)為現(xiàn)在的計(jì)算機(jī)比起1975年已經(jīng)復(fù)雜許多。在1975年時(shí),儲(chǔ)存媒介只有兩種:內(nèi)存與硬盤。但現(xiàn)在計(jì)算機(jī)系統(tǒng)的內(nèi)存除了主存外,還包括了cpu內(nèi)的L1、L2,甚至有L3快取。硬盤上也有自己的快取裝置,因此squidcache自行處理物件替換的架構(gòu)不可能得知這些情況而做到最佳化,但操作系統(tǒng)可以得知這些情況,所以這部份的工作應(yīng)該交給操作系統(tǒng)處理,這就是Varnishcache設(shè)計(jì)架構(gòu)。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編譯參數(shù),在出錯(cuò)時(shí),得到附加的警告信息。我這里是用源碼包安裝的,如果你是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.編寫啟動(dòng)文件:cd/usr/local/varnish/sbinvistart.sh內(nèi)容如下:#!/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是指定后端服務(wù)器的ip或hostname,就象squid做reveseproxy時(shí)的originserver.不過這個(gè)也可以在vcl里面寫。-f是指定所用的vcl的文件。-s指定cache目錄的存儲(chǔ)類型,文件位置和大小。-p是指定varnish的啟動(dòng)的一些啟動(dòng)參數(shù),可以根據(jù)自己的機(jī)器配置來優(yōu)化varnish的性能。其他參數(shù)已經(jīng)參數(shù)的具體含義可以用varnishd--help來查看。 4.編寫vcl:我的vcl如下:backenddefault{setbackend.host="127.0.0.1";setbackend.port="http";}#我用的是一臺(tái)機(jī)器做測(cè)試,使用的backend用的是127.0.0.1:80.如果varnish機(jī)器和后臺(tái)的機(jī)器分開的。寫上對(duì)應(yīng)的機(jī)器的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;}如果是多個(gè)站點(diǎn)在不同的originserver時(shí),可以使用下面配置: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.啟動(dòng)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正確啟動(dòng),恭喜你,你已經(jīng)配置成功了。 本文出自:億恩科技【www.allwellnessguide.com】 服務(wù)器租用/服務(wù)器托管中國(guó)五強(qiáng)!虛擬主機(jī)域名注冊(cè)頂級(jí)提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM] |