ITeye博客

代理加速服务平台

neatchenheng · 2010-03-19 13:42 · 工作 · 编程语言 · Markdown

Apache是高效的WEB服务器,对于处理大量静态请求的应用环境来说,如果引入Squid做为代理加速缓存,可以更好的提高服务器的性能。下面提供一套代理加速整合草案,并做为Hero Game服务平台的一部分。

Squid和Apache运行在larks(192.168.0.108)上。下面将分别介绍Squid和Apache的安装和配制。

    (一)Squid的安装和配制:

1、下载:squid-3.0.STABLE16-1.el5.x86_64.rpm

2、安装:rpm -ivh squid-3.0.STABLE16-1.el5.x86_64.rpm (注:如果提示有冲突,请删掉旧版本. rpm -q squid , 查询系统已有的软件包,然后 rpm -e 删掉冲突软件包)

3、配制:编辑squid.conf文件(vim /etc/squid/squid.conf)

#定位到TAG : acl 定义规则

acl localnet src 192.168.0.0/16

acl mysites dstdomain .inseekar.cn

acl nullref referer_regex .

acl myreferer referer_regex -i ^http://.*\.inseekar\.cn

acl nolog urlpath_regex -i \.gif$ \.jpg$ \.jpeg$ \.png$ \.swf$ \.css$ \.js$

acl nullref referer_regex .

acl myreferer referer_regex -i ^http://.*\.inseekar\.cn

acl nolog urlpath_regex -i \.gif$ \.jpg$ \.jpeg$ \.png$ \.swf$ \.css$ \.js$

#定位到TAG: http_access定义访问规则

http_access allow manager localnet

http_access allow !nullref

http_access deny !myreferer nolog

http_access allow mysites

    #定位到TAG: http_port定义代理端口

    http_port 80 accel defaultsite=hero.inseekar.cn vhost vport transparent

    #定位到 TAG: cache_peer定义代理缓存单元

    cache_peer 192.168.0.108 parent 81 0 no-query originserver no-digest default          name=hero

    #定位到 TAG: cache_peer_domain定义代理缓存域

    cache_peer_domain hero hero.inseekar.cn

   #定位到TAG: cache_peer_access定义代理缓存访问规则

   cache_peer_access hero deny !mysites

   #定位到TAG: cache_mem       (bytes) 定义缓存可使用的最大内存

   cache_mem 256 MB

   #定位到 TAG: maximum_object_size_in_memory   (bytes)定义最大缓存对象

   maximum_object_size_in_memory 1024 KB

  #定位到TAG: cache_dir定义缓存目录

  cache_dir ufs /var/spool/squid 1024 16 256

 #定位到TAG: logformat定义日志格式(这里使用了awstat的格式,以便分析访问数据)

  logformat combined %>a %ui %un [%tl] “%rm %ru   HTTP/%rv” %Hs %<st   “%{Referer}>h” “%{User-Agent}>h” %Ss:%Sh %{host}>h

  #定位到 TAG: access_log 定义日志路径和格式

  access_log /var/log/squid/access.log combined

  #定位到 TAG: refresh_pattern定义相应文件的缓存策略

refresh_pattern \.gif$ 10080 80% 20160

refresh_pattern \.GIF$ 10080 80% 20160

refresh_pattern \.jpg$ 10080 80% 20160

refresh_pattern \.JPG$ 10080 80% 20160

refresh_pattern \.jpeg$ 10080 80% 20160

refresh_pattern \.JPEG$ 10080 80% 20160

refresh_pattern \.png$ 10080 80% 20160

refresh_pattern \.swf$ 10080 80% 20160

refresh_pattern \.css$ 10080 80% 20160

refresh_pattern \.js$ 10080 80% 20160

refresh_pattern \.jsp$ 0 0% 0

refresh_pattern \.sk$ 0 0% 0

refresh_pattern \.s$ 0 0% 0

refresh_pattern \.php$ 0 0% 0

refresh_pattern \.cgi$ 0 0% 0

#定位到TAG: cachemgr_passwd定义cache管理器的使用范畴

cachemgr_passwd disable shutdown reconfigure offline_toggle

cachemgr_passwd larks all

(上面是squid做为代理加速的基本配制,如欲详细了解,请阅读配制文件本身自带的说明文档)

4、初始化Squid

bash> /usr/sbin/squid -z

5、启动Squid

bash> /usr/sbin/squid

6、关闭Squid

bash> /usr/sbin/squid -k shutdown

7、 查看Squid运行状态

bash> /usr/sbin/squidclient -h larks -p 80 mgr:info@larks

8、如果通过apache来访问squid的运行情况,则还要做下面的设置:

a. 在squid.conf文件里将本地网络加入到localnet中,并允许访问cachemgr,如:

acl localnet src 192.168.0.0/16

http_access allow manager localnet

b.在/etc/squid/cachemgr.conf编辑:

192.168.0.108:80

c、登陆http://blog.inseekar.cn/Squid/cgi-bin/cachemgr.cgi,选择Cache Server : 192.168.0.80:80 ;Manager Name : 任意(但不为空);Password : larks (在 squid.conf 中配制, 如:cachemgr_passwd larks all)

(二) Apache的安装和配制

1、apache是系统安装时默认安装的。对于目前的应用基本都能满足。

2、因为squid 和 apache 运行在同一台机器上,所以这里要把apache 的运行端口改成:

Listen 81 (编辑/etc/httpd/conf/httpd.conf)

3、加入虚拟主要住信息:

<VirtualHost *:81>

ServerAdmin admin@inseekar.cn

DocumentRoot /home/inseekarPhp/hero

ServerName hero.inseekar.cn

ProxyPass /js/ !

ProxyPass /css/ !

ProxyPass /images/ !

ProxyPass /flash/ !

ProxyPass / ajp://192.168.0.114:8009/

ErrorLog logs/hero.inseekar.cn-error_log

CustomLog logs/hero.inseekar.cn-access_log common

</VirtualHost>

下面附两份配制文件样例:

squid.conf

httpd.conf

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。