极限首页 业界焦点 软件工程师之路 系统工程师之路 网络工程师之路 软件下载 技术社区
 Linux操作系统的内核编译内
 Linux下设备完全驱动之四
 Linux下设备完全驱动之二
 Linux下设备完全驱动之三
 Linux下设备完全驱动之一
 Linux内核如何从2.4升级到
 开源世界的虚拟机 QEMU
 Linux下软件RAID的实现
 RHEL4内建LVM工具入门
 linux SSH 的一些安全小技
 Linux操作系统的内核编译内
 Linux下设备完全驱动之四
 Linux下设备完全驱动之二
 Linux下设备完全驱动之三
 Linux下设备完全驱动之一
 Linux内核如何从2.4升级到
 开源世界的虚拟机 QEMU
 Linux下软件RAID的实现
 RHEL4内建LVM工具入门
 linux SSH 的一些安全小技

Shell 中文手册

Python 2.3 中文手册

Python 2.4 中文手册

Mysql 4.x 中文手册

PHP 4.x 中文手册

Apache 2.x 中文手册
更多手册

站内搜索:
当前位置:首页>>系统工程师之路>>管理进阶>>正文
基于反向代理的Web缓存加速
时间:2005-04-27 作者:不详 来源:不详

  基于Apache mod_proxy的反向代理缓存加速实现
Apache包含了mod_proxy模块,可以用来实现代理服务器,针对后台服务器的反向加速
安装apache 1.3.x 编译时:
--enable-shared=max --enable-module=most
注:Apache 2.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 *>
ServerName www.example.com
ServerAdmin admin@example.com
# reverse proxy setting
ProxyPass / http://www.backend.com:8080/
ProxyPassReverse / http://www.backend.com:8080/
# cache dir root
CacheRoot "/var/www/proxy"
# max cache storage
CacheSize 50000000
# hour: every 4 hour
CacheGcInterval 4
# max page expire time: hour
CacheMaxExpire 240
# Expire time = (now - last_modified) * CacheLastModifiedFactor
CacheLastModifiedFactor 0.1
# defalt expire tag: hour
CacheDefaultExpire 1
# force complete after precent of content retrived: 60-90%
CacheForceCompletion 80
CustomLog /usr/local/apache/logs/dev_access_log combined
</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_Chinese English" --disable-internal-dns  
make
#make install
#cd /usr/local/squid
make dir cache
chown squid.squid *
vi /usr/local/squid/etc/squid.conf
在/etc/hosts中:加入内部的DNS解析,比如:
192.168.0.4 [url]www.chedong.com[/url]
192.168.0.4 news.chedong.com
192.168.0.3 bbs.chedong.com
---------------------cut here----------------------------------
# visible name
visible_hostname cache.example.com
# cache config: space use 1G and memory use 256M
cache_dir ufs /usr/local/squid/cache 1024 16 256
cache_mem 256 MB
cache_effective_user squid
cache_effective_group squid

http_port 80
httpd_accel_host virtual
httpd_accel_single_host off
httpd_accel_port 80
httpd_accel_uses_host_header on
httpd_accel_with_proxy on
# accelerater my domain only
acl acceleratedHostA dstdomain .example1.com
acl acceleratedHostB dstdomain .example2.com
acl acceleratedHostC dstdomain .example3.com
# accelerater http protocol on port 80
acl acceleratedProtocol protocol HTTP
acl acceleratedPort port 80
# access arc
acl all src 0.0.0.0/0.0.0.0
# Allow requests when they are to the accelerated machine AND to the
# right port with right protocol
http_access allow acceleratedProtocol acceleratedPort acceleratedHostA
http_access allow acceleratedProtocol acceleratedPort acceleratedHostB
http_access allow acceleratedProtocol acceleratedPort acceleratedHostC
# logging
emulate_httpd_log on
cache_store_log none
# manager
acl manager proto cache_object
http_access allow manager all
cachemgr_passwd pass all

----------------------cut here---------------------------------
创建缓存目录:
/usr/local/squid/sbin/squid -z
启动squid
/usr/local/squid/sbin/squid
停止squid:
/usr/local/squid/sbin/squid -k shutdown
启用新配置:
/usr/local/squid/sbin/squid -k reconfig
通过crontab每天0点截断/轮循日志:
0 0 * * * (/usr/local/squid/sbin/squid -k rotate)




附:SQUID性能测试试验

phpMan.php是一个基于php的man page server,每个man
page需要调用后台的man命令和很多页面格式化工具,系统负载比较高,提供了Cache
Friendly的URL,以下是针对同样的页面的性能测试资料:
测试环境:Redhat 8 on Cyrix 266 / 192M Mem
测试程序:使用apache的ab(apache benchmark):
测试条件:请求50次,并发50个连接
测试项目:直接通过apache 1.3 (80端口) vs squid 2.5(8000端口:加速80端口)

测试1:无CACHE的80端口动态输出:
ab -n 100 -c 10 [url]http://www.chedong.com:81/phpMan.php/man/kill/1[/url]
This is ApacheBench, Version 1.3d <$Revision: 1.2 $> apache-1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd,
[url]http://www.zeustech.net/[/url]
Copyright (c) 1998-2001 The Apache Group, [url]http://www.apache.org/[/url]

Benchmarking localhost (be patient).....done
Server Software:      
Apache/1.3.23                                    
Server Hostname:        localhost
Server
Port:           
80

Document Path:         
/phpMan.php/man/kill/1
Document Length:        4655 bytes

Concurrency Level:      5
Time taken for tests:   63.164 seconds
Complete requests:      50
Failed requests:        0
Broken pipe errors:     0
Total transferred:      245900 bytes
HTML transferred:       232750 bytes
Requests per second:    0.79 [#/sec] (mean)
Time per request:       6316.40 [ms]
(mean)
Time per request:       1263.28 [ms]
(mean, across all concurrent requests)
Transfer rate:         
3.89 [Kbytes/sec] received

Connnection Times (ms)
            
min  mean[+/-sd] median   max
Connect:        0   
29  106.1      0   553
Processing:  2942  6016
1845.4   6227 10796

Waiting:   
2941  5999 1850.7   6226 10795

Total:      
2942  6045 1825.9   6227 10796

Percentage of the requests served within a certain time (ms)
  50%   6227
  66%   7069
  75%   7190
  80%   7474
  90%   8195
  95%   8898
  98%   9721
  99%  10796
100%  10796 (last request)

测试2:SQUID缓存输出
/home/apache/bin/ab -n50 -c5
":8000/phpMan.php/man/kill/1"
This is ApacheBench, Version 1.3d <$Revision: 1.2 $> apache-1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd,
[url]http://www.zeustech.net/[/url]
Copyright (c) 1998-2001 The Apache Group, [url]http://www.apache.org/[/url]

Benchmarking localhost (be patient).....done
Server Software:      
Apache/1.3.23                                    
Server Hostname:        localhost
Server
Port:           
8000

Document Path:         
/phpMan.php/man/kill/1
Document Length:        4655 bytes

Concurrency Level:      5
Time taken for tests:   4.265 seconds
Complete requests:      50
Failed requests:        0
Broken pipe errors:     0
Total transferred:      248043 bytes
HTML transferred:       232750 bytes
Requests per second:    11.72 [#/sec] (mean)
Time per request:       426.50 [ms] (mean)
Time per request:       85.30 [ms] (mean,
across all concurrent requests)
Transfer rate:         
58.16 [Kbytes/sec] received

Connnection Times (ms)
            
min  mean[+/-sd] median   max
Connect:      
0     1   
9.5      0    68
Processing:   
7    83  537.4     
7  3808

Waiting:      
5    81  529.1     
6  3748

Total:         
7    84  547.0     
7  3876

Percentage of the requests served within a certain time (ms)
  50%      7
  66%      7
  75%      7
  80%      7
  90%      7
  95%      7
  98%      8
  99%   3876
100%   3876 (last request)

结论:No Cache / Cache = 6045 / 84 = 70
推荐】【 】【关闭


关于极限 | 站内地图 | 意见反馈 | 广告服务 | 数据服务 | 联系我们
本站所刊登的文章,技术资料,软件均整理于网络资源或本站原创,转载请务必联系原作者或本站。
Copyright ? 2001-2004 UPLinux.com All Rights Reserved.
本站唯一联系信箱:
京ICP备05010519