设为首页 收藏本站
查看: 1075|回复: 0

[经验分享] Squid3.0的安装配置

[复制链接]

尚未签到

发表于 2015-11-19 11:48:10 | 显示全部楼层 |阅读模式
  <!--/* 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:&quot;/@宋体&quot;;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:&quot;&quot;;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:&quot;Times New Roman&quot;;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 &quot;$1&quot; in
start)
          ./squid -s
          echo -n ' Squid'
          ;;
stop)
          ./squid -k shutdown
          ;;
restart)
        sh $0 stop
        sleep 10
        sh $0 start
        echo &quot;restart finished&quot;
;;
reconfig)
        ./squid -k reconfigure
;;
esac


             版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-141132-1-1.html 上篇帖子: Centos5上Squid3.0的安装部署 下篇帖子: squid缓存:refresh_pattern指令
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表