Chinaunix首页 | 论坛 | 博客
  • 博客访问: 311634
  • 博文数量: 95
  • 博客积分: 3010
  • 博客等级: 中校
  • 技术积分: 840
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-01 13:05
文章分类

全部博文(95)

文章存档

2009年(8)

2008年(87)

我的朋友

分类: LINUX

2008-07-20 09:46:07

Squid工作模式及实例

jimmy | 14 十一月, 2006 16:40

《补充:发现一个较好的文章: 》

Squid可以工作在两种模式:

A,加速模式

B,代理模式

这里重点考虑在网页加速方面的应用。Squid的访问速度比Apache快很多,及时静态内容用Squid进行一次处理也会提高很多效率。

Squid的主要配置及缺省值:

#Default:
#使用的端口号
# http_port 3128
#定义不Cache的内容
# acl QUERY urlpath_regex cgi-bin ?
# no_cache deny QUERY
#内存使用限制
# cache_mem 8 MB
#swap使用限制
# cache_swap_low 90
# cache_swap_high 95
#最大缓冲文件大小
# maximum_object_size 4096 KB
#最小缓冲文件大小
# minimum_object_size 0 KB
#内存缓冲文件大小
# maximum_object_size_in_memory 8 KB
#换入换出规则
# lru : Squid's original list based LRU policy 最近使用
# heap GDSF : Greedy-Dual Size Frequency 频繁,小文件优先
# heap LFUDA: Least Frequently Used with Dynamic Aging 字节点击优化
# heap LRU : LRU policy implemented using a heap
# cache_replacement_policy lru
# memory_replacement_policy lru
#缓冲存储目录
#参数:类型,目录,大小(Mbytes), 第一级目录数,第二级目录数
# cache_dir ufs /opt/itc/squid/cache 2048 16 256
#日志
# cache_access_log /opt/itc/squid/logs/access.log
# cache_log /opt/itc/squid/logs/cache.log
# cache_store_log /opt/itc/squid/logs/store.log
#定义操作
# acl aclname acltype string1 ...
#访问许可
#http_access deny all
#刷新规则
# TAG: refresh_pattern
# usage: refresh_pattern [-i] regex min percent max [options]
# options: override-expire
# override-lastmod
# reload-into-ims
# ignore-reload
#refresh_pattern . 86400 100% 172800 override-expire override-lastmod ignore-reload
#网络控制许可
# TAG: httpd_accel_host
# TAG: httpd_accel_port
# httpd_accel_port 80
#单一数据源
# httpd_accel_single_host off
#代理模式
# httpd_accel_with_proxy off
#头信息控制失效
# httpd_accel_uses_host_header off
#控制密码保护
# Usage: cachemgr_passwd password action action ...
#平均大小
# store_avg_object_size 13 KB


典型的单网站加速基本配置:

http_port 80
cache_mem 3000 MB

tcp_recv_bufsize 4096 bytes
maximum_object_size_in_memory 1024 KB
maximum_object_size 2048 KB
cache_replacement_policy heap GDSF
memory_replacement_policy heap GDSF

禁止硬盘缓冲:

cache_dir null /tmp

访问控制:

acl all src 0.0.0.0/0.0.0.0
http_access allow all
httpd_accel_host 10.10.82.84
httpd_accel_port 80
httpd_accel_with_proxy off
httpd_accel_single_host on
httpd_accel_uses_host_header on

(注释: http_accel_host 就是被加速的网站地址。如果是同一台机器,可以将apache绑定到8088或其它端口,然后设置为:
http_accel_host 127.0.0.1
http_accel_port 8088

参数:

half_closed_clients off
cache_swap_high 100%
cache_swap_low 99%
visible_hostname 10332server
connect_timeout 15 seconds
read_timeout 15 seconds
request_timeout 15 seconds
cache_access_log /opt/itc/squid/logs/access.log
cache_access_log none
cache_log /opt/itc/squid/logs/cache.log
client_persistent_connections off
server_persistent_connections off
client_db off
cache_store_log none

对于需要同时加速多个网站,编译时禁止internal_dns,用Host文件来控制被加速网站的真实地址。(其实还有一个方法是用的Proxy模式,对需要加速的网站进行代理缓冲,但是会存在安全风险,配置会更复杂)。

典型配置段:

httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy off
httpd_accel_single_host off
httpd_accel_uses_host_header on
hosts_file /etc/hosts

(注释:对比上面可以看到,主要变化是: virtual, single_host off)

顺便再提几个可能会有兴趣的点:

1,Squid集群。即,一组Squid,之间互相通讯,分担同样的任务。目前来说基本没有意义。将需缓冲内容更好的分布在多个squid上面会更好。对被加速网站而言,前面架个Squid就是了,集群配置实在是鸡肋。

2,Squid文件的更新。之前曾经写过Purge的用法的。这里再提一下:
acl Purge method PURGE
http_access allow all Purge

3,Squid的snmp控制。这个还算有些意义,但是除了特别专业的应用,一般也用不到。

~~呵呵~~

阅读(1050) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~