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

[经验分享] squid配置文档

[复制链接]

尚未签到

发表于 2018-12-26 10:06:49 | 显示全部楼层 |阅读模式
  Squid配置文档
一.测试安装环境:
Centos5.4—64位    2.6.18-164.el5
Suqid3.1.4
安装目录:
/usr/local/squid
  squid log目录:
/usr/local/squid/var/logs
  二.编译安装:
[root@zyw home]# tar zxvf squid-3.1.4.tar.gz
[root@zyw home]# cd squid-3.1.4
[root@zyw squid-3.1.4]# ./configure --prefix=/usr/local/squid --enable-gnuregex --disable-carp --enable-async-io=240 --with-pthreads --enable-storeio=ufs,aufs,diskd --disable-wccp --enable-icmp --enable-kill-parent-hack --enable-cachemgr-hostname=localhost --enable-default-err-language=Simplify_Chinese --with-maxfd=65535 --enable-poll --enable-linux-netfilter --enable-large-cache-files --disable-ident-lookups --enable-default-hostsfile=/etc/hosts --with-dl --with-large-files --enable-delay-pools --enable-snmp --disable-internal-dns --enable-underscore --enable-arp-acl
[root@zyw home]#make && make install
解释:
–prefix=/usr/local/squid :指定软件的安装路径
–enable-gnuregex :支持GNU正则表达式。
–disable-carp: Cache数组路由协议(CARP)用来转发丢失的cache到父cache的数组或cluste
–enable-async-io=240等同于同时打开./configure如下三个选项
--with-aufs-threads=N_THREADS
--with-pthreads
--enable-storeio=ufs,aufs
这个主要是设置async模式来运行squid,我的理解是设置用线程来运行squid,如果服务器配置很不错,有1G以上内存,cpu使用SMP的方式的话可以考虑设成160或者更高。如果服务器比较糟糕就根据实际情况设了。另外此项还另cache文件支持aufs
  --disable-wccp用于阻止或分发HTTP请求到一个或多个caches
–enable-icmp :加入icmp支持
–enable-kill-parent-hack :关掉suqid的时候,要不要连同父进程一起关掉
--enable-cachemgr-hostname=localhost:指定cachemgr-hostname值为localhost
-- enable-snmp :此选项可以让MRTG使用SNMP协议对服务器的流量状态进行监测,因此必须选择此项,使Squid支持SNMP接口。
–disable-ident-lookups :防止系统使用RFC931规定的身份识别方法。
--enable-delay-pools 开启squid延时池功能
–enable-cahce-digests :加快请求时,检索缓存内容的速度。
–enable-err-language=”Simplify_Chinese” 和
–enable-default-err-languages=”Simplify_Chinese” :指定出错是显示的错误页面为简体中文
--with-maxfd=65535指定最大文件描述
–enable-poll :指定使用Poll()函数,提升性能就是啦。
--disable-ident-lookups允许服务器利用客户端的特殊TCP连接来发现用户名
–enable-linux-netfilter :可以支持透明代理
--enable-large-cache-files开启大文件支持,支持2GB以上的文件
--disable-internal-dns使用自己的内部DNS查询
–enable-underscore :允许解析的URL中出现下划线,因为默认squid会认为带下划线的URL地址是非法的,并拒绝访问该地址
–enable-arp-acl :可以在规则设置中直接通过客户端的MAC地址进行管理,防止客户使用IP欺骗。
  三.Squid工作模式及原理
[传统代理]
1.SQUID被绑定到代理服务器的3128端口。
2. 客户端浏览器被配置使用代理服务器的3128端口。
3.客户端不需要配置DNS。
  4.代理服务器上需要配置代理服务器。
5.客户端不需要 配置缺省路由。
当我们在客户端浏览器中打开一个web请求,比如“http://www.baidu.com”,这时将陆续发生以下事件:
1. 客户端使用某一端口(比如1025)连接代理服务器3128端口,请求web页面“http://www.baidu.com”
2.代理服务器向 DNS请求“www.baidu.com”,得到相应的IP地址192.168.77.223。然后,代理服务器使用某一端口(比如1037)向该IP地址的80端口发 起web连接请求,请求web页面。
3.收到响应的web页面后,代理服务器把该数据传送给客户端。
4.客户端浏览器显示该页面。
从 www.baidu.com的角度看来,连接是在192.168.77.222地1037端口和192.168.77.223的80端口之间建立的。
从client的角度看 来,连接是在192.168.7.223的1025端口和192.168.77.222的3128端口之间建立的。
[透明代理]
透明代理的意思是客户端根本不需要知道有代理服务器 的存在。
在以上基础上我们做以下工作:
1.配置透明代理服务器软件运行在代理服务器的3128端口。
2.配置代理服务器将所有对 80端口的连接重定向到3128端口。
3.配置客户端浏览器直接连解到Internet。
4.在客户端配置好DNS.
5.配置客 户端的缺省网关为192.168.1.1.
当我们在客户端浏览器中打开一个web请求,比如 “http://www.baidu.com”,这时将陆续发生以下事件:
1.客户端向DNS请求“www.baidu.com”,得到相应的 IP地址192.168.77.223。然后,客户端使用某一端口(比如1066)向该IP地址的80端口发起web连接请求,请求web页面。
2.当该请求包 通过透明代理服务器时,被防火墙将该数据包重定向到代理服务器的绑定端口3128。于是,透明
代理服务器用某一端口(比如1088)向 192.168.77.223的80端口发起web连接请求,请求web页面。
3.收到响应的web页面后,代理服务器把该数据传送给客户端。
4.客户 端浏览器显示该页面。
从www.baidu.com的角度看来,连接是在192.168.77.222地1088端口和192.168.77.223的80端口之间建立的。从 client的角度看来,连接是在192.168.7.223的1066端口和192.168.77.223的80端口之间建立的。
以上就是传统代理服务器和透 明代理服务器的区别所在。
[反向代理]
反向代理是相对于传统代理而言,是代理web服务器接受客户端的请求
在此,我们忽略客户端的设置,假设客户端是可以直接访问互联网
web服务器与客户端的结构如下:
假设已经将www.baidu.com的域名指向了squid服务器所在的ip,并且在web服务器集群里做了dns轮询。
web server1 -|
web server2 -|- squid 服务器/ INTERNET / - Client
web server3 -|
1.客户端通过IE向DNS服务器发送访问www.baidu.com的请求,由客户所在地的DNS服务器解析www.baidu.com的IP为192.168.77.223并返回给用户。
2.客户收到DNS返回的服务器IP地址,重新向 www.baidu.com指向的IP地址发送访问请求。
3.squid服务器接收到用户的请求后,查询自身缓存中是否有用户请求内容,有则直接发送给客户端,如果没有则通过内部DNS轮询查询空闲服务器,并将客户请求发送到该服务器,在获取到用户数据并返回给用户的同时保留一份在自己本身的缓存当中。在用户看来,自己访问的是www.baidu.com这个服务器,实际上真正的WEB服务器为SQUID缓存后面的服务器或者服务器集群,通过外部DNS做CNAME转向,将用户请求转发到内部真正的web服务器上去
SQUID工作原理
一、SQUID缓存的存放方式:
每一台Squid 代理服务器上都有若干颗硬盘,每颗硬盘又分割成多个分区,每一个分区又可建立很多目录,目录下才放文件(Squid 把它叫object)。
二、 SQUID的查询方式:
SQUID通过查询表的方式来定位某个资源的位置,所查询的表叫Hash table 和Digest table;Digest table在这里可以称之为摘要或者索引,它记录了磁盘上每个分区,每个目录里存的缓存摘要,Hash table在这里可以称之为目录或者提纲,它记录所有的Digest table表信息,SQUID接受到请求后先查询Hash table,在根据Hash table所指向的Digest table查询需要的信息。
三、SQUID服务器之间的关系:
SQUID 服务器存在两种工作关系,一种为Child、Parent,当child squid server没有用户需要的数据时,就象parent server发出请求,并持续等待,直到parent server回应自己为止;另外一种为ibling,当本地SQUID server没有用户请求数据时,会向sibling server发出请求,如果sibling server没有资料则会向上级sibling或者INTERNET发送数据请求
四、SQUID运作模式
1. 当Squid Server没有资料时,会先向Sibling 的Squid Server 要资料,如果Sibling没资料,就跳过它直接向Parent 要。
2. 向Parent 要资料,然後一直等,直到Parent 给它资料为止(Parent 自己有的资料或上Internet 去拿)。
3. 没有Parent 时,就自己上Internet 去拿。
4. 如果这三者都拿不到资料,才向用户端回报拿不到资料。
一般而言,把网路上 一层的Squid Server 设成Sibling 是不错的选择(例如:一个学校将所在城市网和附近的大学设成Sibling),因为网路上一层的Squid Server 服务对象较多,其硬件功能较强,离我们比较近,速度也比较快;万一要不到资料,我们还可以自己上Internet 去拿。那什麽时候设Parent?当您的出口只有一个,或上一层Squid Server 拿不到资料,自己也一定拿不到,只好将上一层Squid Server 设为Parent。
  四.Squid 配置:
创建用户和组
[root@zyw squid-3.1.4]# /usr/sbin/groupadd squid
[root@zyw squid-3.1.4]# /usr/sbin/useradd -g squid squid
赋予squid用户和组权限
[root@zyw local]# chown -R squid.squid /usr/local/squid/
主配置文档配置:
/usr/local/squid/etc/squid.conf
(1) 透明代理配置文件
#acl limit
acl woyoSYS src 192.168.77.0/24
http_access allow woyoSYS
#cache limit
cache_dir ufs /usr/local/squid/var/cache 100 16 256
cache_mem 100 MB
cache_swap_low 90
cache_swap_high 95
cache_access_log /usr/local/squid/var/logs/access.log
cache_log /usr/local/squid/var/logs/cache.log
cache_store_log /usr/local/squid/var/logs/store.log
coredump_dir /usr/local/squid/var/cache
cache_mgr sam_li@staff.woyo.com
visible_hostname song.domain.com #必须指明自己的主机名,否则squid无法正常启动
http_port 192.168.7.222:3128 transparent #squid监听192.168.7.222的3128端口
  注意:
1.透明代理中一定要把client的网关指向squid,否则无法使正常代理
2.Squid.conf编辑:http_port 192.168.7.222:3128 transparent #支持透明代理
3. # iptables -t nat -A PREROUTING -s 192.168.7.223/32 -p tcp --dport 80 -j REDIRECT --to-port 3128
4. # service iptables save
  验证squid.conf的语法和配置:
/usr/local/squid/sbin/squid -k parse
  初始化cache目录:
初始化ca在初次运行squid之前,或者无论何时你增加了新的cache_dir,你必须初始化cache目录。
/usr/local/squid/sbin/squid –z
  前台启动squid,查看是否报错:
/usr/local/squid/sbin/squid -N -d1
  (2)反向代理设置:
1.Squid.conf编辑:http_port 192.168.7.222:80 vhost vport #支持域名和IP的虚拟主机
  cache_peer 192.168.77.222 parent 81 0 no-query originserver weight=1 name=a
cache_peer 192.168.77.222 parent 82 0 no-query originserver weight=1 name=b
#cache_peer 192.168.77.253 parent 80 0 no-query originserver weight=1 name=c
  cache_peer_domain a www.serverA1.com
cache_peer_domain b www.serverA2.com
#cache_peer_domain c www.serverB.com
  #以上六行配置,让 Squid 服务器知道:
#从客户端过来的请求,如果是 www.serverA1.com,则 Squid 向 ServerA 192.168.77.222 的端口 81发送请求;
#从客户端过来的请求,如果是 www.serverA2.com,则 Squid 向 ServerA 192.168.77.222 的端口 82发送请求;
#从客户端过来的请 求,如果是 www.serverB.com,则 Squid 向 ServerA 192.168.77.51 的端口 80发送请求;
以下是实际配置文件:
  visible_hostname   squid1 . ihompy . com
#设定squid的主机名,如无此项squid将无法启动
http_port 192.168.70.13:80 accel defaultsite=www.rising.com.cn vhost
#设定squid为accel加速模式,vhost必须要加.否则将无法将主机头转发至后端服务器,访问时就会出现无法找到主机头的错误
cache_peer www.rising.com.cn parent 80 0 no-query originserver name=wwwsite
cache_peer it.rising.com.cn parent 80 0 no-query originserver name=itsite
#定义不同的父节点,将节点设为no-query以及originserver说明这些节点是实际服务器
acl manager proto cache_object
acl localhost src 127.0.0.1/32
#允午本机IP
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32
#允午目的地址为本机IP
acl www dstdomain www.rising.com.cn
acl it dstdomain it.rising.com.cn
acl Safe_ports port 80
acl CONNECT method CONNECT
http_access allow www
http_access allow it
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access allow localhost
http_access deny all
cache_peer_access wwwsite allow www
cache_peer_access itsite allow it
cache_peer_access wwwsite deny all
cache_peer_access itsite deny all
cache_mem 200 MB
#设置缓存内存值
max_open_disk_fds 0
maximum_object_size 30 MB
#大于此容量的对象将不会被保存在磁盘上,默认大小是4M,如果squid服务器用于缓冲flash等大型文件,建议将此值变大.否则过大的文件在下次重启后将需要重新获取
maximum_object_size_in_memory 20 MB
#最大位于内存中的对象的大小,默认大小是8K,如果服务器内存很大.可以适当提高此值的大小,建议根据网站的80%图片的大小来定.或者根据WEB服务器实际存取文件中最常访问的文件大小来定制
cache_dir ufs /usr/local/squid/cache 1500 16 256
#设置缓存目录大小为1500MB 一级目录为16个二级目录为256个
cache_swap_low 80
cache_swap_high 97
strip_query_terms off
request_header_max_size 10 kb
request_body_max_size 1 MB
memory_pools on
memory_pools_limit 100 MB
#设置内存池
coredump_dir /usr/local/squid/cache
cache_store_log /usr/local/squid/var/logs/store.log
emulate_httpd_log on
#logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %h" "%{User-Agent}>h" %Ss:%Sh
cache_access_log /usr/local/squid/var/logs/access.log
# Add any of your own refresh_pattern entries above these.
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .               0       20%     4320
refresh_pattern -i \.css$       360     50%     2880     reload-into-ims
refresh_pattern -i \.js$        1440    50%     2880     reload-into-ims
refresh_pattern -i \.html$      720     50%     1440     reload-into-ims
refresh_pattern -i \.jpg$       1440    90%     2880     ignore-reload
refresh_pattern -i \.gif$       1440    90%     2880     ignore-reload
refresh_pattern -i \.swf$       1440    90%     2880     ignore-reload
refresh_pattern -i \.jpg$       1440    50%     2880     ignore-reload
refresh_pattern -i \.png$       1440    50%     2880     ignore-reload
refresh_pattern -i \.bmp$       1440    50%     2880     ignore-reload
refresh_pattern -i \.doc$       1440    50%     2880      ignore-reload
refresh_pattern -i \.ppt$       1440    50%     2880      ignore-reload
refresh_pattern -i \.xls$       1440    50%     2880      ignore-reload
refresh_pattern -i \.pdf$       1440    50%     2880      ignore-reload
refresh_pattern -i \.rar$       1440    50%     2880      ignore-reload
refresh_pattern -i \.zip$       1440    50%     2880      ignore-reload
refresh_pattern -i \.txt$       1440    50%     2880      ignore-reload
###############################
cache_effective_user squid
cache_effective_group squid
cache_mgr root
###
dns_timeout 2 seconds
forward_timeout 30 seconds
connect_timeout 30 seconds
peer_connect_timeout 30 seconds
read_timeout 30 seconds
request_timeout 6 seconds
persistent_request_timeout 16 seconds
#
logfile_rotate 0
squid常用命令:
/usr/local/squid/sbin/squid -z 初始化缓存空间
/usr/local/squid/sbin/squid 启动
/usr/local/squid/sbin/squid -k shutdown 停止
/usr/local/squid/sbin/squid -k reconfigure 重新载入配置文件
/usr/local/squid/sbin/squid -k rotate 轮循日志
  六.Squid优化:
  1.日志周期性滚动:
0 4 * * * /usr/local/squid/sbin/squid -k rotate &
2.Log 目录周期性检查:
  0 4 * * 6 /usr/local/squid/movelog.sh &
3.Cache周期性优化:
0 4 * * * /usr/local/squid/clear_squid_cache.sh gif &
0 4 * * * /usr/local/squid/clear_squid_cache.sh swf &
0 4 * * * /usr/local/squid/clear_squid_cache.sh gif &
4.最大文件描述符数量限制优化:
通常情况下,Squid 默认为1024个文件描述,一般情况已经够用。当系同高度繁忙时,肯能会用到4096个或更大。在编译 Squid 前推荐将描述符更改至,系统限制级别的 2~3倍
-H 设置硬件资源限制.
-S 设置软件资源限制
-n size:设置内核可以同时打开的文件描述符的最大值.单位:n
查看默认文件描述符数量:
# ulimit -n
1024
临时修改文件描述符数量
# ulimit –SHn 65536
永久修改文件描述符数量
# vim /usr/include/bits/typesizes.h
#define __FD_SETSIZE 65536
#vi /etc/security/limits.conf
* hard nofile 102400
* soft nofile 102400
# vim /etc/sysctl.conf
fs.file-max=102400
# ulimit -n
65553
5.脚本优化:
log脚本:
# cat /usr/local/squid/movelog.sh
#!/bin/bash
SLOG=`du -sh /usr/local/squid/var/logs/ | awk '{print $1}' | awk -F '.' '{print $1}'`
if [ $SLOG -gt 100 ];then
if [ ! -d /var/log/squid ];then
mkdir /var/log/squid
else
mv /usr/local/squid/var/logs/ /var/log/squid
echo "move squid log to /var/logs" | mail -s sam_li@staff.woyo.com
fi
else
echo "The size of /usr/local/squid/var/logs/ is `du -sh /usr/local/squid/var/logs/ | awk '{print $1}' | awk -F 'M' '{print $1}'`"
fi
  squid脚本:
# cat /usr/local/squid/squid.sh
#!/bin/bash
# this script is for Squid
case "$1" in
start)
/usr/local/squid/sbin/squid –s
sleep 1
if netstat -tnulp | grep squid ;then echo "squid is start" ;else echo "please check it";fi
;;
stop)
/usr/local/squid/sbin/squid -k shutdown
sleep 1
if ! netstat -tnulp | grep squid ;then echo "squid is stop" ;else echo "please check it";fi
;;
status)
if netstat -tnulp | grep squid ;then echo "squid is running" ;else echo "squid is stop";fi
;;
reload)
/usr/local/squid/sbin/squid -k reconfigure
sleep 1
if netstat -tnulp | grep squid ;then echo "squid is reload" ;else echo "please check it";fi
;;
restart)
if netstat -tnulp | grep squid ;then echo "Squid proess is running" ;else
/usr/local/squid/sbin/squid -k shutdown && /usr/local/squid/sbin/squid -s
sleep 1
if netstat -tnulp | grep squid ;then echo "squid is restart" ;else echo "please check it";fi
fi
;;
esac
cache清除脚本:
Cache 脚本:
# cat clear_squid_cache.sh
squidcache_path=" /usr/local/squid/cache/"
squidclient_path="/usr/local/squid/bin/squidclient"
grep -a -r $1 $squidcache_path/* | strings | grep "http:" | awk -F'http:' '{print "http:"$2;}' > cache_list.txt
for url in `cat cache_list.txt`; do
$squidclient_path -m PURGE -p 80 $url
done
七.脚本用法:
Cache脚本用法:
  清楚所有Flash缓存(扩展名.swf)
# /usr/local/squid/clear_squid_cache.sh swf
Squid.sh脚本用法:
/usr/local/squid/sbin/squid.sh | Squid.sh start | stop | status | restart | reload
八. 补充
1. 打补丁
在你运行squid一段时间后,你可能发现需要打源代码补丁,用以修正bug或者增加试验性的功能
为了打补丁-或者有时候叫差别文件-你需要一个叫做"patch"的程序。你的操作系统必须有该程序。如果没有,你可以从GNU工具集里下载(http://www.gnu.org/directory/patch.html).
为了打补丁,你必须把补丁文件存放在系统中某处。然后进入到squid的源代码目录,运行如下命令:
#patch < /tmp/patch_file
2. 重运行configure
有时候你可能发现有必要重新运行./configure。例如,假如你调整了内核参数,你必须再次运行./configure以使它能发现新设置
在运行./configure之后,你必须再次编译和安装squid。安全起见,建议先运行make clean:
#make clean
以相同的选项重运行./configure,使用如下命令:
#config.status –recheck
九. Cachemgr.cgi监控squid运行状态
9.1Cachemgr.cgi配置过程
#cp /usr/local/squid/libexec/cachemgr.cgi /var/www/cgi-bin/
修改配置文件/etc/http/conf/http.conf
           &lt;Location /cgi-bin/cachemgr.cgi>
AuthType Basic
AuthName &quot;Squidadmin&quot;
AuthUserFile /usr/local/squid/etc/passwd/.htaccess
require valid-user

9.2生成口令文件
htpasswd -c /usr/local/squid/etc/passwd/.htaccess squidadmin   “创建密码文件 ”
New passwd:
Re-type new passwd:
Adding password for user squidadmin
9.3验证
在浏览器的地址列中键入 http://192.168.7.222(服务器的名称或IP地址)/cgi-bin/cachemgr.cgi。
squidclient 使用方法
一.基本使用:
1. squidclient -p 80 mgr:info # squid 的运行统计信息  
2. squidclient -p 80 mgr:mem  # 内存使用情况  
3 .squidclient -p 80 mgr:diskd #硬盘缓存使用情况  
4. squidclient -p 80 mgr:objects #已经缓存的列表  
5 .squidclient -p 80 mgr:io  #IO 情况
查看帮助
1. squidclient -h  
2 .squidclient -p 80 mgr:     
3. -h host      Retrieve URL from cache on hostname.  Default is localhost.  
4. -l host      Specify a local IP address to bind to.  Default is none.  
5. -p port      Port number of cache.  Default is 3128.  
6.-U user      WWW authentication username  
7.-W password  WWW authentication password
二. cacahemgr.cgi 程序
squidclient 得到的信息都可以运行 Squid 提供的 CGI 程序 cachemgr.cgi 获得:
将cachemgr.conf 拷到 Apache 的 cgi-bin 目录,也可是其他支持CGI的WEB 服务器
squid.conf 中有关 cachemgr.cgi 的配置
1. acl localhost src 127.0.0.1/255.255.255.255  
2 .acl manager proto cache_object  
3 .http_access allow manager localhost #只允许localhost  
4 .http_access deny manager  
5 .#cachemgr_passwd unixvip all  
6 .cachemgr_passwd unixvip info stats/objects
访问 http://ip/cgi-bin/cachecgi.cgi 时 Manager name: 就是 manager  Password: 就是 unixvip
因为 squid不是运行在3128端口,还要修改cachemgr.conf 文件,cachemgr.cgi 运行时会读取这个文件
cachemgr.conf 只有一行,hostanme:port 形式,例如:
localhost:80
启动 Apache ,输入 http://ip/cgi-bin/cachecgi.cgi 登录即可获得 Squid 的各种状态信息。
注: Squid.conf 中进行了上面的配置,squidclient 应该增加 -U manager -W unixvip 参数
#squidclient -U squid -W test -p 80 mgr:info
HTTP/1.0 200 OK
Date: Tue, 11 Mar 2008 16:08:14 GMT
Content-Type: text/plain
Expires: Tue, 11 Mar 2008 16:08:14 GMT
Last-Modified: Tue, 11 Mar 2008 16:08:14 GMT
Connection: close
  Squid Object Cache: Version 2.6.STABLE6
Start Time:     Tue, 11 Mar 2008 10:21:47 GMT
Current Time:   Tue, 11 Mar 2008 16:08:14 GMT
Connection information for squid:
Number of clients accessing cache:      2023      访问客户端数量,使用proxy的电脑数量
Number of HTTP requests received:       81787    客户端http请求数量
Number of ICP messages received:        0        接受到的icp query数量
Number of ICP messages sent:    0                发出icp query数量
Number of queued ICP replies:   0
Request failure ratio:   0.00
Average HTTP requests per minute since start:   236.1   每分钟http request的数量
Average ICP messages per minute since start:    0.0     平均每分钟 ICP 请求数量
Select loop called: 24789642 times, 0.839 ms avg
Cache information for squid:
Request Hit Ratios:     5min: 99.6%, 60min: 98.7%    5分钟/60分钟 请求命中率
Byte Hit Ratios:        5min: 100.0%, 60min: 100.0%  5分钟/60分钟 命中率,以 Byte 计算
Request Memory Hit Ratios:      5min: 1.6%, 60min: 1.2%   内存中请求命中率
Request Disk Hit Ratios:        5min: 82.0%, 60min: 90.5%   磁盘请求命中率
Storage Swap size:      7723212 KB                cache对象占用硬盘的存储空间
Storage Mem size:       7992 KB                  cache对象占用内存的存储空间
Mean Object Size:       264.01 KB            
Requests given to unlinkd:      279
Median Service Times (seconds) 5 min    60 min:
        HTTP Requests (All):   2.94900 3.46762
        Cache Misses:          0.03427 0.03427
        Cache Hits:            5.06039 4.79440
        Near Hits:             0.30459 0.35832
        Not-Modified Replies: 0.00179 0.00179
        DNS Lookups:           0.00000 0.00000
        ICP Queries:           0.00000 0.00000
Resource usage for squid:
        UP Time:        20787.011 seconds
        CPU Time:       128.799 seconds
        CPU Usage:      0.62%                    
        CPU Usage, 5 minute avg:        0.44%       5 分钟内平均CPU使用率  
        CPU Usage, 60 minute avg:       0.51%      60 分钟内平均CPU使用率  
        Process Data Segment Size via sbrk(): 34292 KB
        Maximum Resident Size: 0 KB
        Page faults with physical i/o: 0
Memory usage for squid via mallinfo():
        Total space in arena:   34424 KB
        ordinary blocks:        27031 KB   8599 blks
        Small blocks:               0 KB      0 blks
        Holding blocks:          6152 KB      2 blks
        Free Small blocks:          0 KB
        Free ordinary blocks:    7392 KB
        Total in use:           33183 KB 82%
        Total free:              7392 KB 18%
        Total size:             40576 KB
Memory accounted for:                记忆体使用状态
        Total accounted:        21777 KB
        memPoolAlloc calls: 15446992
        memPoolFree calls: 15337015
File descriptor usage for squid:
Maximum number of file descriptors:   16384     能使用的最大文件描述符   
Largest file desc currently in use:   1165         目前最大使用文件描述符
Number of file desc currently in use: 571         目前正在使用文件描述符
Files queued for open:                   0
Available number of file descriptors: 15813
Reserved number of file descriptors:   100
Store Disk files open:                 266
IO loop method:                     epoll
Internal Data Structures:
29315 StoreEntries                        Cache中存放的快取档案数量
190 StoreEntries with MemObjects           记忆体斗的快取档案数量
176 Hot Object Cache Items                 磁碟机中存放的快取档案数量
29253 on-disk objects
  
补充:
Squid 中 refresh_pattern 的作用
用于确定一个页面进入cache后,它在cache中停留的时间。refresh_pattern 规则仅仅应用到没有明确过时期限的响应。原始服务器能使 用 Expires 头部,或者 Cache-Control:max-age 指令来指定过时期限 ,只要没有在设置 override-expire。
  语法:
  refresh_pattern [-i] regexp min percent max [options]
min 参数是分钟数量。它是过时响应的最低时间限制。如果某个响应驻留在 cache 里的时间没有超过这个最低限制,那么它不会过期。类似的,max 参数是存活响应的最高时间限制。如果某个响应驻留在 cache 里的时间高于这个最高限制,那么它必须被刷新。
  在最低和最高时间限制之间的响应,会面对 squid 的最后修改系数 LM-factor 算法 LM-factor=(response age)/(resource age)。对这样的响应,squid 计算响应的年龄和最后修改系数,然后将它作为百分比值进行比较。响应年龄简单的就是从原始服务器产生,或最后一次验证响应后,经历的时间数量。源年龄在 Last-Modified 和 Date头 部之间是不同的。LM-factor 是响应年龄与源年龄的比率。这个基本不用详细了解,这是不是一个精确控制过期的参数,如果要精确控制过期,就不要使用这个。
  Refresh_pattern 有14个参数
我讲讲常用的几个参数的意思
override-expire
该选项导致 squid 在检查 Expires 之前,先检查 min 值。这样,一个非零的 min 时间让 squid 返回一个未确认的 cache 命中,即使该响应准备过期。
  override-lastmod
改选项导致 squid 在检查 LM-factor 百分比之前先检查min ,它生效在expire 之后
  reload-into-ims
该选项让 squid 在确认请求里,以 no-cache 指令传送一个请求。换句话说,squid 在转发请求之前,对该请求增加一个 If-Modified- Since 头部。注意这点仅仅在目标有 Last-Modified 时间戳时才能工作。外面进来的请求保留 no-cache 指令,以便它到达原始服务器。
一般情况可以使用 reload-into-ims。它其实是强行控制对象的超时时间,这违反了http协议的精神,但是在带宽较窄的场合,可以提高明显系统相应时间。
举例:
  refresh_pattern -i \.css$ 1440 50% 129600 reload-into-ims
refresh_pattern -i \.xml$ 1440 50% 129600 reload-into-ims
refresh_pattern -i \.html$ 1440 90% 129600 reload-into-ims-
refresh_pattern -i \.shtml$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.hml$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.jpg$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.png$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.gif$ 1440 90% 129600 ignore-reload
refresh_pattern -i \.bmp$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.js$ 1440 90% 129600 reload-into-ims
ignore-reload
该选项导致 squid 忽略请求里的任何 no-cache 指令。
所以。如果希望内容一进入 cache 就不删除,直到被主动 purge 掉为止,可以加上 ignore-reload 选项,这个我们常用在mp3,wma,wmv,gif之类。
Examples:
  refresh_pattern -i \.mp3$ 1440 50% 2880 ignore-reload
refresh_pattern -i \.wmv$ 1440 50% 2880 ignore-reload
refresh_pattern -i \.rm$ 1440 50% 2880 ignore-reload
refresh_pattern -i \.swf$ 1440 50% 2880 ignore-reload
refresh_pattern -i \.mpeg$ 1440 50% 2880 ignore-reload
refresh_pattern -i \.wma$ 1440 50% 2880 ignore-reload
ignore-no-cache
该选项导致 Squid 强制忽略从源站而来的“Pragma: no-cache”和“Cache-control: no-cache”
  ignore-private
该选项导致 Squid 强制忽略从源站而来的“Cache-control: private”
  ignore-auth:强制将一个请求认为是源站发送的带有“Cache-control: public”
  ignore-auth
该选项导致 Squid 强制将一个请求认为是源站发送的带有“Cache-control: public”
  Refresh_pattern  percent 的计算
resource age =对象进入cache的时间-对象的last_modified
response age =当前时间-对象进入cache的时间
LM-factor=(response age)/(resource age)
  举个例子,这里只考虑percent, 不考虑min 和max
  例如:refresh_pattern 20%
  假设源服务器上www.aaa.com/index.htm —–lastmodified 是 2007-04-10 02:00:00
squid上 proxy.aaa.com/index.htm index.htm进入cache的时间 2007-04-10 03:00:00
  1)如果当前时间 2007-04-10 03:00:00
resource age =3点-2点=60分钟
response age =0分钟
index.htm还可以在cache停留的时间(resource age)*20%=12分钟
也就是说,index.htm进入cache后,可以停留12分钟,才被重新确认。
  2)如果当前时间 2007-04-10 03:05:00
resource age =3点-2点=60分钟
response age =5分钟
index.htm还可以在cache停留的时间(resource age)*20%=12分钟-5=7
LM-factor=5/60=8.3%

运维网声明 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-655964-1-1.html 上篇帖子: squid+sarg的安装和使用(转) 下篇帖子: squid中refresh_pattern参数用法及解释
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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