Varnish 缓存服务器配置
来源:百度文库 编辑:神马文学网 时间:2024/04/29 16:35:13
Arnish是一款高性能的开源HTTP加速器,挪威最大的在线报纸 Verdens Gang ([url]http://www.vg.no[/url]) 使用3台Varnish代替了原来的12台squid。 性能比以前更好。 varnish的作者Poul-Henning Kamp是FreeBSD的内核开发者之一,他认为现在的计算机比起1975年已经复杂许多。在1975年时,储存媒介只有两 种:内存与硬盘。但现在计算机系统的内存除了主存外,还包括了cpu内的L1、L2,甚至有L3快取。硬盘上也有自己的快取装置,因此squid cache自行处理物件替换的架构不可能得知这些情况而做到最佳化,但操作系统可以得知这些情况,所以这部份的工作应该交给操作系统处理, 这就是 Varnish cache设计架构。 1.下载源码包编译安装: cd /usr/local/src && wget [url]http://nchc.dl.sourceforge.net/s ... arnish-1.1.1.tar.gz [/url] tar zxvf /usr/local/src/varnish-1.1.1.tar.gz cd /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 -R nobody:nobody /cache 3.编写启动文件: cd /usr/local/varnish/sbin vi start.sh 内容如下: #!/bin/sh # file: go.sh date -u /usr/local/varnish/sbin/varnishd \ -a 10.0.0.129:80 \ -s file,/cache/varnish/V,1024m \ -f /usr/local/varnish/sbin/vg.vcl.default \ -p thread_pool_max=1500 \ -p thread_pools=5 \ -p listen_depth=512 \ -p client_http11=on \ 注:-a 是指定后端服务器的ip或hostname,就象squid做revese proxy时的originserver. 不过这个也可以在vcl里面写。 -f 是指定所用的vcl的文件。 -s 指定cache目录的存储类型,文件位置和大小。 -p 是指定varnish的启动的一些启动参数,可以根据自己的机器配置来优化varnish的性能。 其他参数已经参数的具体含义可以用varnishd --help 来查看。 4.编写vcl: 我的vcl如下: backend default { set backend.host = "127.0.0.1"; set backend.port = "http"; } #我用的是一台机器做测试,使用的backend用的是127.0.0.1:80.如果varnish机器和后台的机器分开的。 写上对应的机器的ip或hostname就可以了。 sub vcl_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; } sub vcl_pipe { pipe; } sub vcl_pass { pass; } sub vcl_hash { hash; } sub vcl_hit { if (!obj.cacheable) { pass; } deliver; } sub vcl_timeout { discard; } sub vcl_discard { discard; } 如果是多个站点在不同的originserver时,可以使用下面配置: backend www { set backend.host = "www.jackbillow.com"; set backend.port = "80"; } backend images { set backend.host = "images.jackbillow.com"; set backend.port = "80"; } sub vcl_recv { if (req.http.host ~ "^(www.)?jackbillow.com$") { set req.http.host = "www.jackbillow.com"; set req.backend = www; } elsif (req.http.host ~ "^images.jackbillow.com$") { set req.backend = images; } else { error 404 "Unknown virtual host"; } 5.启动varnish: /usr/local/varnish/sbin/start.sh Mon Sep 3 03:13:19 UTC 2007 file /cache/varnish/V/varnish.tEKXXx (unlinked) size 1073741824 bytes (262144 fs-blocks, 262144 pages) Using old SHMFILE ps waux | grep varnish root 16254 0.0 0.0 11200 708 ? Ss 10:43 0:00 /usr/local/varnish/sbin/varnishd -a 10.0.0.129:80 -s /varnish/V,1024m -f /usr/local/varnish/sbin/vg.vcl.default -p thread_pool_max 1500 -p thread_pools 5 -p listen_depth 512 -p client_http11 on nobody 16255 0.0 0.1 1152552 1808 ? Sl 10:43 0:00 /usr/local/varnish/sbin/varnishd -a 10.0.0.129:80 -s file,/cache/varnish/V,1024m -f /usr/local/varnish/sbin/vg.vcl.default -p thread_pool_max 1500 -p thread_pools 5 -p listen_depth 512 -p client_http11 on 看到上面信息说明varnish正确启动,恭喜你,你已经配置成功了本文出自 51CTO.COM技术博客
Varnish 缓存服务器配置
hibernate缓存配置
Hibernate缓存配置
服务器配置
使用Varnish代替Squid做网站缓存加速器的详细解决方案
服务器网页缓存的深入分析
安全配置服务器
DHCP服务器的配置
Linux时间服务器配置
Windows WEB服务器配置
DHCP服务器的配置
服务器的配置
Windows Internet服务器安全配置
Apache服务器配置全攻略
Linux DHCP 服务器的配置
Linux上配置ftp服务器
Apache服务器配置全攻略
Ubuntu 7.04 桌面服务器配置
linux 下bind服务器配置
网吧大师 服务器要求配置
Linux网络服务器配置基础
DHCP服务器的配置11
windows2003下FTP服务器配置
windows2003 时间服务器ntp配置