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

Linux服务器
linux下用cron定时执行任务的方法
.htaccess绑定域名到子目录的方法
linux apache下虚拟主机配置方法
apache 局域网访问配置方案
linux Apache服务器系统安全设置与优化
linux中mac地址绑定方法
linux托盘不断闪烁之解决方法
Apache配置 虚拟转向实例
Apache No space left on device的解决办法
Apache rewrite的重写相关的参数说明
LINUX入门级常用命令20条整理
Ubuntu设置开机自动挂载所有格式硬盘分区
5个可能被你忽略的Linux安全设置方法
学习Apache的mod rewrite、access写法
改版时保留原链接,创建新的URL的方法
rsync中文手册之使用rsync实现网站镜像和备份linux
rsync 数据同步使用详解
linux URL的301重定向代码分析
eclipse3.2.2 + MyEclipse5.5 + Tomcat5.5.27 配置数据库连接池
Apache服务器二级域名的完美实现

Linux服务器 中的 基于反向代理的Web缓存加速现代理服务器


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-18   浏览: 79 ::
收藏到网摘: 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