Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5283801
  • 博文数量: 1144
  • 博客积分: 11974
  • 博客等级: 上将
  • 技术积分: 12312
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-13 20:06
文章存档

2017年(2)

2016年(14)

2015年(10)

2014年(28)

2013年(23)

2012年(29)

2011年(53)

2010年(86)

2009年(83)

2008年(43)

2007年(153)

2006年(575)

2005年(45)

分类: LINUX

2006-04-12 15:40:44

本文以redhat as3以及squid2.5 stable11(最新为stable12)为例,详细介绍一下如何实现用squid来加速多个web站点。
首先下载squid,地址是:
下载完后放在/usr/src备用。
要支持多个web站点,必须要关闭squid使用外部dns解析,所以我们必须重新编译,如果你在安装linux的时候选择了squid的安装包,需要先卸载掉。
下一步,我们来编译squid
#cd /usr/src
#tar zxvf squid-2.5.STABLE11.tar.gz
#cd squid-2.5.STABLE11
#./configure --disable-internal-dns
#make
#make install

这样,就完成了squid的安装,简单吧?重要的是--disable-internal-dns,不允许squid使用dns解析。
然后我们需要编辑/etc/hosts文件,在其中加上我们需要加速的web站点的域名及ip对应关系,如
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost localhost.localdomain localhost
211.86.9.1 sdada.edu.cn test2.sdada.edu.cn
221.214.14.215 rencai.design.sd.cn
221.214.14.226 guqunye.com
221.214.14.235 qqxq.net qqxq.com

接下来,我们需要将需要加速的web站点的域名,从dns解析上,全部指向安装squid的这台服务器,这样就比较清楚的明白其工作原理了,首先用户请求某一域名,被指向cache服务器(安装squid的服务器),然后squid根据其主机上的hosts表,会去访问web站点所在的真实服务器。

最后需要编辑squid的配置文件,默认在/usr/local/squid/etc/squid.conf
在最后添加如下内容:


http_port 80
icp_port 0

dns_children 20
redirect_children 20

cache_mem 256 MB
cache_dir ufs /usr/local/squid/cache 2048 16 256
log_icp_queries off
buffered_logs off
emulate_httpd_log off
redirect_rewrites_host_header off
half_closed_clients off

cache_swap_high 100
cache_swap_low 80
maximum_object_size 1024 KB

refresh_pattern -i .html 1440 100% 129600 reload-into-ims
refresh_pattern -i .shtml 1440 100% 129600 reload-into-ims
refresh_pattern -i .hml 1440 100% 129600 reload-into-ims
refresh_pattern -i .gif 1440 100% 129600 reload-into-ims
refresh_pattern -i .swf 1440 100% 129600 reload-into-ims
refresh_pattern -i .png 1440 100% 129600 reload-into-ims
refresh_pattern -i .bmp 1440 100% 129600 reload-into-ims
refresh_pattern -i .js 1440 100% 129600 reload-into-ims

http_access deny all
cache_mgr gf_l@hotmail.com
cache_effective_user squid
cache_effective_group squid
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_uses_host_header on


visible_hostname cache2.sdada.edu.cn


然后需要添加squid用户及组,以及建立cache目录并且改为squid用户所有。
然后运行
#/usr/local/squid/sbin/squid -z
初始化cache目录

一切ok了!(
阅读(2357) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~