分享
 
 
 

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

王朝other·作者佚名  2008-05-19
窄屏简体版  字體: |||超大  

基于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 www.chedong.com

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 http://www.chedong.com:81/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,

http://www.zeustech.net/

Copyright (c) 1998-2001 The Apache Group, http://www.apache.org/

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

"http://localhost: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,

http://www.zeustech.net/

Copyright (c) 1998-2001 The Apache Group, http://www.apache.org/

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

Perce

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有