Squid3.0的安装配置

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} --> 1   下载,编译安装:

到官方站站下载squid3.0: http://www.squid-cache.org
./configure --prefix=/opt/squid3
--disable-carp --with-aufs-threads=32
--with-pthreads --enable-storeio='ufs,aufs,null'
--enable-disk-io='AIO,Blocking'
--enable-removal-policies='heap,lru'
--disable-wccp
--enable-kill-parent-hack
--disable-snmp
--disable-poll
--disable-select
--enable-epoll
--enable-auth=basic
--with-aio
--disable-ident-lookup
--with-filedescriptors=65536
Make
Make install
注意标红部分,使用squid3 最主要的原因,就是应为它开始支持epool了,而且,配置简化了很多。没有2.x 那么繁杂。

 

2  squid 关键配置说明:

#缓存服务器的名字,可以任意 
visible_hostname up1

#服务器端口 
#设定squid为accel加速模式,vhost必须要加.否则将无法将主机头转发至后端服务器,访问时就会出现无法找到主机头的错误 
http_port 80 accel vhost vport 

#配置需要代理的realserver服务器 
#定义不同的父节点,将节点设为no-query以及originserver说明这些节点是实际服务器 
cache_peer 127.0.0.1 parent 80 0 no-query originserver name= appsvr

#设定不同域名转发到不同的cache_peer上,如果没有这项.不同域名的域名可能被分发到同一台服务器上. 
cache_peer_domain  appsvr up1.upload.chinaren.com

#允许所有客户端访问 appsvr
cache_peer_access appsvr allow all
#日志格式 
logformat squid  %ts.%03tu %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt 
#
服务器运行日志 
cache_log /opt/squid3/var/logs/cache.log 

#客户端请求日志 
access_log /opt/squid3/var/logs/access.log squid

#设置PID和日志文件位置 
pid_filename /usr/local/squid3/var/logs/squid.pid 

#最大缓存文件大小,超过此值则不缓存 
maximum_object_size_in_memory 4096 KB

#共享内存大小(squid在提供服务的时候所使用的内存) 
cache_mem 3072 MB

#替换机制  (lru叫做 最近不常用的单元 unit一般就是常说的object 也就是当cache中的内容比如内存或硬盘达到上限时的 那么就需要进行数据的换进和换出工作) 
memory_replacement_policy lru 

cache 的存放地,这里使用的是squid的内存cache,没有使用硬盘cache,所以,设置了为cache_dir null 。
cache_dir null /opt/squid3/var/cache

如果使用硬盘cache的话,如下所示:
cache_dir ufs /opt/squidcache/cache 512 16 256 
#注意:size是按照M为单位的也就这个目录中最大存储容量的上限 
#512M其中1层目录16个 并且每个1层目录下又有256个2层目录[或者说子目录] 

监控cache存放状态信息,一般,只有在调试过程才打开这个选项
cache_store_log none

为了防止F5刷新后,跑到后台同realserver确认,而带来大量穿透,特设置如下,忽略F5刷新,如果真的要重新获得cache内容,ctrl + F5 。
refresh_pattern -i /.jpg 10000 100% 30000 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-cache ignore-private

不允许下载和访问的文件类型:
acl QUERY urlpath_regex cgi-bin .php .cgi .exe .asp .jsp .aspx .sh
cache deny QUERY

启动squid所用的用户名和所在的用户组
cache_effective_user squid
cache_effective_group squid

3  完整的squid配置文件如下:
......
4  squid 相关信息查看:
查看squid 运行状态以及cache命中率:
./squidclient -h 61.135.131.102 -p 80 mgr:info

会出现如下信息:(标红部分为我们一般关注的问题)
HTTP/1.0 200 OK
Server: squid/3.0.STABLE15
Mime-Version: 1.0
Date: Wed, 21 Oct 2009 07:42:52 GMT
Content-Type: text/plain
Expires: Wed, 21 Oct 2009 07:42:52 GMT
Last-Modified: Wed, 21 Oct 2009 07:42:52 GMT
X-Cache: MISS from up1
Via: 1.0 up1 (squid/3.0.STABLE15)
Connection: close

Squid Object Cache: Version 3.0.STABLE15
Start Time:     Sat, 17 Oct 2009 04:38:28 GMT
Current Time:   Wed, 21 Oct 2009 07:42:52 GMT
Connection information for squid:
        Number of clients accessing cache:      1416
        Number of HTTP requests received:       758148
        Number of ICP messages received:        0
        Number of ICP messages sent:    0
        Number of queued ICP replies:   0
        Number of HTCP messages received:       0
        Number of HTCP messages sent:   0
        Request failure ratio:   0.00
        Average HTTP requests per minute since start:   127.5
        Average ICP messages per minute since start:    0.0
        Select loop called: 546359604 times, 0.653 ms avg
Cache information for squid:
        Hits as % of all requests:      5min: 93.6%, 60min: 91.5%
        Hits as % of bytes sent:        5min: 89.6%, 60min: 87.5%
        Memory hits as % of hit requests:       5min: 98.3%, 60min: 97.2%
        Disk hits as % of hit requests: 5min: 0.0%, 60min: 0.1%
        Storage Swap size:      0 KB
        Storage Swap capacity:   0.0% used,  0.0% free
        Storage Mem size:       3145724 KB
        Storage Mem capacity:   100.0% used,  0.0% free
        Mean Object Size:       0.00 KB
        Requests given to unlinkd:      0
Median Service Times (seconds)  5 min    60 min:
        HTTP Requests (All):   0.00000  0.00000
        Cache Misses:          0.01745  0.01035
        Cache Hits:            0.00000  0.00000
        Near Hits:             0.00000  0.00000
        Not-Modified Replies:  0.00000  0.00000
        DNS Lookups:           0.00000  0.00000
        ICP Queries:           0.00000  0.00000
Resource usage for squid:
        UP Time:        356663.590 seconds
        CPU Time:       369.248 seconds
        CPU Usage:      0.10%
        CPU Usage, 5 minute avg:        0.15%
        CPU Usage, 60 minute avg:       0.18%
        Process Data Segment Size via sbrk(): 3113352 KB
        Maximum Resident Size: 0 KB
        Page faults with physical i/o: 1
Memory usage for squid via mallinfo():
        Total space in arena:  -1080680 KB
        Ordinary blocks:       -1081238 KB     96 blks
        Small blocks:               0 KB      0 blks
        Holding blocks:        287928 KB   2048 blks
        Free Small blocks:          0 KB
        Free Ordinary blocks:     557 KB
        Total in use:          -793310 KB 100%
        Total free:               557 KB 0%
        Total size:            -792752 KB
Memory accounted for:
        Total accounted:       -926732 KB 117%
        memPool accounted:     -926732 KB 117%
        memPool unaccounted:   133979 KB -16%
        memPoolAlloc calls: 114756510
        memPoolFree calls:  112230395
File descriptor usage for squid:
        Maximum number of file descriptors:   15000
        Largest file desc currently in use:    185
        Number of file desc currently in use:  159
        Files queued for open:                   0
        Available number of file descriptors: 14841
        Reserved number of file descriptors:   100
        Store Disk files open:                   0
Internal Data Structures:
         48286 StoreEntries
         48286 StoreEntries with MemObjects
         48281 Hot Object Cache Items
             0 on-disk objects

清除一个页面的cache:
./squidclient -h 61.135.131.102 -p 80 -m PURGE  http://up1.upload.chinaren.com/userpic/1e/e7/m_12538444730417.jpg

注意:一定要添加
acl myip src 61.135.131.102
acl purge method PURGE
http_access allow purge myip
将自己所在的那台机器的ip地址添加到权限管理中,只有本机才能是使用管理和perge命令。
其他机器上的 squidclient 不能够管理本机的squid。

其他的功能:
使用 ./squidclient –h 可以看到。

 

5  squid 管理脚本
#!/bin/sh
#
ulimit -HSn 15000
# this script starts and stops Squid
#echo 15000 > /proc/sys/fs/file-max
case "$1" in
start)
          ./squid -s
          echo -n ' Squid'
          ;;
stop)
          ./squid -k shutdown
          ;;
restart)
        sh $0 stop
        sleep 10
        sh $0 start
        echo "restart finished"
;;
reconfig)
        ./squid -k reconfigure
;;
esac

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值