快捷搜索:   nginx

Linux 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
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.zeustech.net/
Copyright (c) 1998-2001 The Apache Group,   This is ApacheBench, Version 1.3d <$Revision: 1.2 $> apache-1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd,

顶(0)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论