squid反向代理配置(web服务器的前端内容缓存器)
本文在介绍 squid 反向代理的工作原理的基础上,指出反向代理技术在提高网站访问速度,增强网站可用性、安全性方面有很好的用途。作者在具体的实验环境下,利用 DNS 轮询和 Squid 反向代理技术,实现了网站的负载均衡,从而提高了网站的可用性和可靠性。
系统结构
组织架构
Expires: 告诉反向代理页面什么时间应该从缓冲区中删除
Cache-Control: 告诉反向代理页面是否应该被缓冲
Pragma: 用来包含实现特定的指令,最常用的是 Pragma:no-cache
系统结构
三台 Squid 服务器:操作系统 Linux AS 4,软件 Squid 3.0,相应的 IP 如下:
Squid1:192.168.76.223
Squid2:192.168.76.224
Squid3:192.168.76.225
webServer1:210.82.118.195
webServer2:192.168.76.226
webServer1:192.168.76.227
type master;
file "master/ cache.xxx.com.cn ";
};
@ IN SOA search. xxx.com.cn. root. xxx.com.cn. (
20080807; Serial
3600; Refresh
900 ; Retry
3600000 ; Expire
3600 ) ; Minimum
IN NS search.xxx.com.cn.
1 IN PTR localhost.xxx.com.cn.
wenjin IN A 192.168.76.223
wenjin IN A 192.168.76.224
wenjin IN A 192.168.76.225
配置完成后,运行 rndc star t 启动 bind 服务。可在 /etc/rc.conf 中设置 named_enable="YES" 使得开机自启动。
用 ps – A |grep named 查看 bind 服务是否起来;
用 nslookup wenjin.cache.xxx.com.cn 测试 bind 服务是否正常运行。
解压缩tar – zxvf squid-3.0.STABLE8.tar.gz
设置配置参数:cd squid-3.0.STABLE10
编译安装:make&make install安装完以后会在 /usr/local 目录下看见 squid 目录。
配置 squid 配置文件
cache_effective_group squid
######### 设定 squid 的主机名 , 如无此项 squid 将无法启动
visible_hostname squid1.nlc.gov.cn
############# 配置 squid 为加速模式 #################
http_port 80 accel vhost vport
icp_port 3130
##### 配置 squid2、squid3 为其邻居,当 squid1 在其缓存中没有找到请求的资源时,
通过 ICP 查询去其邻居中取得缓存
cache_peer squid2.xxx.com.cn sibling 80 3130
cache_peer squid3.xxx.com.cn sibling 80 3130
##### squid1 的三个父节点,originserver 参数指明是源服务器,
round-robin 参数指明 squid 通过轮询方式将请求分发到其中一台父节点;
squid 同时会对这些父节点的健康状态进行检查,如果父节点 down 了,
那么 squid 会从剩余的 origin 服务器中抓取数据
cache_peer 210.82.118.195 parent 8080 0 no-query originserver round-robin
name=webServer1
cache_peer 192.168.76.226 parent 8080 0 no-query originserver round-robin
name=webServer2
cache_peer 192.168.76.227 parent 8080 0 no-query originserver round-robin
name=webServer3
#### 将 wenjin.cache.xxx.com.cn 域的请求通过 RR 轮询方式转发到三个父节点中的一个
cache_peer_domain webServer1 webServer2 webServer3 wenjin.cache.xxx.com.cn
##### 下面是一些访问控制、日志和缓存目录的设置
acl localnet src 192.168.76.223 192.168.76.224 192.168.76.225
acl all src 0.0.0.0/0.0.0.0
http_access allow all
icp_access allow localnet
cache_log /usr/local/squid/var/logs/cache.log
access_log /usr/local/squid/var/logs/access.log squid
cache_dir ufs /usr/local/squid/var/cache/ 1000 16 256
####### 对 squid 的一些优化 ###############
maximum_object_size 10240 KB ### 能缓存的最大对象为 10M
maximum_object_size_in_memory 512 KB ### 内存中缓存的最大对象 512K
cache_mem 256 MB ###squid 用于缓存的内存量
192.168.76.224 squid2.xxx.com.cn
192.168.76.225 squid3.xxx.com.cn
2008/11/17 10:08:47| Configuring Sibling squid1.xxx.com.cn/80/3130
2008/11/17 10:08:47| Configuring Sibling squid3.xxx.com.cn/80/3130
2008/11/17 10:08:47| Configuring Parent 210.82.118.195/8080/0
2008/11/17 10:08:47| Configuring Parent 192.168.76.226/8080/0
2008/11/17 10:08:47| Configuring Parent 192.168.76.227/8080/0
2008/11/17 10:08:47| Ready to serve requests.
您可能感兴趣的文章:
squid反向代理配置(web服务器的前端内容缓存器)
squid2.6反向代理实验模型
squid2.5配置详解+认证
squid代理配置一例
决定squid反向代理的性能要素
squid3.x透明代理配置详解
清除代理服务器squid上的cache记录
squid2.6透明代理配置一例
squid反向代理服务器加速web
简单配置squid+iptables的透明代理