Squid安装(Windows)入门实例简介

本文详细介绍了如何在Windows系统中安装并配置Squid反向代理服务器,包括下载安装文件、配置squared.conf文件、启动Squid服务等步骤,并通过测试验证了其缓存和负载均衡功能。
转自IT农夫http://blog.youkuaiyun.com/kkdelta/article/details/7827950

squid 可以做反向代理将系统中相对静态的页面进行缓存和负责均衡,
提高网站访问速度,增强网站可用性、安全性.
用户访问Squid 反向代理服务器的 IP 地址,这样客户端的 URL 请求将被发送到反向代理服务器。
如果Squid反向代理服务器中缓存了该请求的资源,则将该请求的资源直接返回给客户端,
否则反向代理服务器将向后台的 WEB服务器请求资源,然后将请求的应答返回给客户端,
同时也将该应答缓存在本地,供下一个请求者使用。

其示意图如下:


Windows中安装squid步骤:
1,从http://squid.acmeconsulting.it下载squid windows的安装文件.
也可以从http://download.youkuaiyun.com/detail/kkdelta/4474605下载.
下载后解压将squid放在C:\目录下(default),你也可以把Squid放到其他的路径,
但是需要大量的配置squid配置文件中的路径信息。
2,重命名etc文件夹下的文件
squid.conf.default ==> squid.conf
mime.conf.default ==> mime.conf
cachemgr.conf.default ==> cachemgr.conf 
3,简单配置squid.conf,使配置达到如下图的效果


visible_hostname squidhost
#设定squid的主机名,如无此项squid将无法启动
http_port 3128 accel vhost vport
#设定squid为accel加速模式,vhost必须要加.否则将无法将主机头转发至后端服务器,
#访问时就会出现无法找到主机头的错误
cache_peer 147.151.240.234 parent 8080 0 no-query originserver round-robin name=webserver1
cache_peer 147.151.241.151 parent 8080 0 no-query originserver round-robin name=webserver2
cache_peer_domain  webserver1 webserver2 localhost
#将 localhost的请求通过 RR 轮询方式转发到2个父节点中的一个.
#http://localhost:3128的请求将转发到147.151.240.234:8080或者147.151.241.151:8080
acl all src 0.0.0.0/0.0.0.0
http_access allow all

4,启动squid
C:\squid\sbin>squid -z #创建cache目录.
C:\squid\sbin>squid #启动squid

测试:
将147.151.240.234和147.151.241.151的tomcat启动,放上一个test.jsp文件.
在151的机器上的test.jsp输出 The JSP in Tomcat instance 151 
在234的机器上的test.jsp输出 The JSP in Tomcat instance 234
访问http://localhost:3128/xxxweb/test.jsp会轮流输出上面的结果.
对一个jsp的访问每次都会转发到web server上:X-Cache:  MISS  from squidhost
[plain]  view plain copy
  1. [root@Fedora-WLS9-1 bin]# curl -I http://147.151.240.52:3128/examples/jsp/test.jsp  
  2. HTTP/1.0 200 OK  
  3. Server: Apache-Coyote/1.1  
  4. Set-Cookie: JSESSIONID=F3C10D53A916B1852D06687E9E581A2F; Path=/examples  
  5. Content-Type: text/html  
  6. Content-Length: 972  
  7. Date: Fri, 03 Aug 2012 17:51:01 GMT  
  8. X-Cache: MISS from squidhost  
  9. X-Cache-Lookup: MISS from squidhost:3128  
  10. Via: 1.0 squidhost:3128 (squid/2.6.STABLE22)  
  11. Connection: close  
对一个静态的html的访问每次都会转发到web server上:X-Cache:  HIT  from squidhost
[plain]  view plain copy
  1. [root@Fedora-WLS9-1 bin]# curl -I http://147.151.240.52:3128/examples/jsp/test.html  
  2. HTTP/1.0 200 OK  
  3. Server: Apache-Coyote/1.1  
  4. Accept-Ranges: bytes  
  5. ETag: W/"26-1343982480000"  
  6. Last-Modified: Fri, 03 Aug 2012 08:28:00 GMT  
  7. Content-Type: text/html  
  8. Content-Length: 26  
  9. Date: Fri, 03 Aug 2012 17:28:54 GMT  
  10. Age: 195  
  11. <span style="color:#FF0000;"></span>X-Cache: HIT from squidhost  
  12. X-Cache-Lookup: HIT from squidhost:3128  
  13. Via: 1.0 squidhost:3128 (squid/2.6.STABLE22)  
  14. Connection: close  

笔者记录:

重新加载配置文件squid -k reconfigure -n squid

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值