当前位置: 首页 > 图文教程 > 服务器 > Linux服务器 > 基于反向代理的Web缓存加速现代理服务器

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服务器 中的 基于反向代理的Web缓存加速现代理服务器


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


基于Apachemod_proxy的反向代理缓存加速实现
Apache包含了mod_proxy模块,可以用来实现代理服务器,针对后台服务器的反向加速
安装apache1.3.x编译时:
--enable-shared=max--enable-module=most
注:Apache2.x中mod_proxy已经被分离成mod_proxy和mod_cache:同时mod_cache有基于文件和基于内存的不同实现
创建/var/www/proxy,设置apache服务所用户可写
mod_proxy配置样例:反相代理缓存+缓存
架设前台的www.example.com反向代理后台的www.backend.com的8080端口服务。
修改:httpd.conf
<VirtualHost*>
ServerNamewww.example.com
[email protected]
#reverseproxysetting
ProxyPass/http://www.backend.com:8080/
ProxyPassReverse/http://www.backend.com:8080/
#cachedirroot
CacheRoot"/var/www/proxy"
#maxcachestorage
CacheSize50000000
#hour:every4hour
CacheGcInterval4
#maxpageexpiretime:hour
CacheMaxExpire240
#Expiretime=(now-last_modified)*CacheLastModifiedFactor
CacheLastModifiedFactor0.1
#defaltexpiretag:hour
CacheDefaultExpire1
#forcecompleteafterprecentofcontentretrived:60-90%
CacheForceCompletion80
CustomLog/usr/local/apache/logs/dev_access_logcombined
</VirtualHost>

基于Squid的反向代理加速实现
Squid是一个更专用的代理服务器,性能和效率会比Apache的mod_proxy高很多。
如果需要combined格式日志补丁:
http://www.squid-cache.org/mail-archive/squid-dev/200301/0164.html
squid的编译:
./configure--enable-useragent-log --enable-referer-log--enable-default-err-language=Simplify_Chinese--enable-err-languages="Simplify_ChineseEnglish"--disable-internal-dns 
make
#makeinstall
#cd/usr/local/squid
makedircache
chownsquid.squid*
vi/usr/local/squid/etc/squid.conf
在/etc/hosts中:加入内部的DNS解析,比如:
192.168.0.4[url]www.chedong.com[/url]
192.168.0.4news.chedong.com
192.168.0.3bbs.chedong.com
---------------------cuthere----------------------------------
#visiblename
visible_hostnamecache.example.com
#cacheconfig:spaceuse1Gandmemoryuse256M
cache_dirufs/usr/local/squid/cache102416256
cache_mem256MB
cache_effective_usersquid
cache_effective_groupsquid

http_port80
httpd_accel_hostvirtual
httpd_accel_single_hostoff
httpd_accel_port80
httpd_accel_uses_host_headeron
httpd_accel_with_proxyon
#acceleratermydomainonly
aclacceleratedHostAdstdomain.example1.com
aclacceleratedHostBdstdomain.example2.com
aclacceleratedHostCdstdomain.example3.com
#acceleraterhttpprotocolonport80
aclacceleratedProtocolprotocolHTTP
aclacceleratedPortport80
#accessarc
aclallsrc0.0.0.0/0.0.0.0
#AllowrequestswhentheyaretotheacceleratedmachineANDtothe
#rightportwithrightprotocol
http_accessallowacceleratedProtocolacceleratedPortacceleratedHostA
http_accessallowacceleratedProtocolacceleratedPortacceleratedHostB
http_accessallowacceleratedProtocolacceleratedPortacceleratedHostC
#logging
emulate_httpd_logon
cache_store_lognone
#manager
aclmanagerprotocache_object
http_accessallowmanagerall
cachemgr_passwdpassall

----------------------cuthere---------------------------------
创建缓存目录:
/usr/local/squid/sbin/squid-z
启动squid
/usr/local/squid/sbin/squid
停止squid:
/usr/local/squid/sbin/squid-kshutdown
启用新配置:
/usr/local/squid/sbin/squid-kreconfig
通过crontab每天0点截断/轮循日志:
00***(/usr/local/squid/sbin/squid-krotate)

附:SQUID性能测试试验
phpMan.php是一个基于php的manpageserver,每个man
page需要调用后台的man命令和很多页面格式化工具,系统负载比较高,提供了Cache
Friendly的URL,以下是针对同样的页面的性能测试资料:
测试环境:Redhat8onCyrix266/192MMem
测试程序:使用apache的ab(apachebenchmark):
测试条件:请求50次,并发50个连接
测试项目:直接通过apache1.3(80端口)vssquid2.5(8000端口:加速80端口)

测试1:无CACHE的80端口动态输出:
ab-n100-c10[url]http://www.chedong.com:81/phpMan.php/man/kill/1[/url]
ThisisApacheBench,Version1.3d<$Revision:1.2$>apache-1.3
Copyright(c)1996AdamTwiss,ZeusTechnologyLtd,
[url]http://www.zeustech.net/[/url]
Copyright(c)1998-2001TheApacheGroup,[url]http://www.apache.org/[/url]

Benchmarkinglocalhost(bepatient).....done
ServerSoftware: 
Apache/1.3.23
ServerHostname:localhost
Server
Port: 
80

DocumentPath:
/phpMan.php/man/kill/1
DocumentLength:4655bytes

ConcurrencyLevel: 5
Timetakenfortests: 63.164seconds
Completerequests: 50
Failedrequests:0
Brokenpipeerrors:0
Totaltransferred: 245900bytes
HTMLtransferred: 232750bytes
Requestspersecond:0.79[#/sec](mean)
Timeperrequest: 6316.40[ms]
(mean)
Timeperrequest: 1263.28[ms]
(mean,acrossallconcurrentrequests)
Transferrate:
3.89[Kbytes/sec]received

ConnnectionTimes(ms)

min mean[+/-sd]median max
Connect:0 
29 106.1 0 553
Processing: 2942 6016
1845.4 622710796

Waiting:
2941 59991850.7 622610795

Total: 
2942 60451825.9 622710796

Percentageoftherequestsservedwithinacertaintime(ms)
 50% 6227
 66% 7069
 75% 7190
 80% 7474
 90% 8195
 95% 8898
 98% 9721
 99% 10796
100% 10796(lastrequest)

测试2:SQUID缓存输出
/home/apache/bin/ab-n50-c5
"http://localhost:8000/phpMan.php/man/kill/1"
ThisisApacheBench,Version1.3d<$Revision:1.2$>apache-1.3
Copyright(c)1996AdamTwiss,ZeusTechnologyLtd,
[url]http://www.zeustech.net/[/url]
Copyright(c)1998-2001TheApacheGroup,[url]http://www.apache.org/[/url]

Benchmarkinglocalhost(bepatient).....done
ServerSoftware: 
Apache/1.3.23
ServerHostname:localhost
Server
Port: 
8000

DocumentPath:
/phpMan.php/man/kill/1
DocumentLength:4655bytes

ConcurrencyLevel: 5
Timetakenfortests: 4.265seconds
Completerequests: 50
Failedrequests:0
Brokenpipeerrors:0
Totaltransferred: 248043bytes
HTMLtransferred: 232750bytes
Requestspersecond:11.72[#/sec](mean)
Timeperrequest: 426.50[ms](mean)
Timeperrequest: 85.30[ms](mean,
acrossallconcurrentrequests)
Transferrate:
58.16[Kbytes/sec]received

ConnnectionTimes(ms)

min mean[+/-sd]median max
Connect: 
01 
9.5 068
Processing:
783 537.4
7 3808

Waiting: 
581 529.1
6 3748

Total:
784 547.0
7 3876

Perce