产品有些较真的人
作squid压力测试
发现前台squid的access_log里面
状态是MISS的数量
跟后台real server(nginx)里的access_log里的访问记录条数对应不上(要多一些)
然后就怀疑squid也许会有问题
因为有些不在squid的cache里的请求没有能穿透squid打到后面的nginx上
经过仔细察看
发现squid里有同一时间、多个请求访问同一个不在squid的cashe里的对象
这时,squid在log里记的是“MISS”
但squid去后台real server(nginx)只取一次数据
(或者也是同时多个请求一起取,但nginx的access_log只记录一次)
毕竟
squid返回的是200状态嘛
squid下file descriptor是个非常重要的参数
他关系squid能同时打开多少个文件描述符
跟squid的性能密切相关
而linux下所有用户的file descriptor缺省都是1024
//汗
以前在squid2.5的时候
都是通过编译squid的之前
先手工强制加大file descriptor
ulimit -HSn 65536
然后再等编译完
启动之前
也加上
ulimit -HSn 65536
这样的方法来增大file descriptor的
但这种方法在squid2.6的情况下
也不是不行
主要是这次我不想重新用用源码编译squid
我就想用rpm
哪怕把系统的srpm下下来rebuild下也行
反正我在rebuild的时候
加ulimit -HSn 65536的方式没成功
不知道问题在什么地方
但我明白了一点
redhat系的squid2.6的rpm包里
其实有着一些redhat专门为squid打的补丁
其中就有对config参数”
–enable-fd-config
“的支持
以及相对应的在squid的配置文件里支持参数
max_filedesc
的支持
所以
如果是redhat系列的linux系统自带的squid2.6
只要在配置文件里设置max_filedesc就可以轻松解决file descriptor的问题
squid2.5的配置就不用介绍了
这里的题目是“squid2.6”
2.6下配多个站点的反向加速远没有2.5时的简单
就因为这
手头好些squid2.5没有升级到2.6呢
到现在2.6都成料”old“版本了
(stable的是2.7和3.0)
后来发现其实弄明白了也还是挺简单的
主要就是”http_port“、”cache_peer“和”cache_peer_domain“这三句配置
首先
http_port xxx.xxx.xxx.xxx:80 vhost
这里的xxx.xxx.xxx.xxx是这台squid机器的公网地址
如果要squid绑定所有端口的话
可以简写成
http_port 80 vhost
这里vhost是基于名称的虚拟主机的意思
如果有需要加速基于ip(其实就是基于tcp端口)的虚拟主机
则后面再加个vport即可
然后再就是cache_peer和cache_peer_domain的配合了
首先,给每一个squid后台的real server(web server)建立一个cache_peer
像这样:
cache_peer xxx.xxx.xxx.xxx parent 80 0 no-query originserver
(这里的xxx.xxx.xxx.xxx是real server的ip,当然写域名也可以,只要能够被squid的机器正确解析为ip地址)
80是real server的服务端口,一般应该是80吧
因为后端real server一般应该是web server,不是squid,所以自然没有icp端口之说,所以icp端口设为0
最后的originserver正是指出了,这是台原始(内容)服务器,我们习惯称之为real server
再然后在cache_peer_domain里将由squid提供加速服务的域名分别扔给上面定义的cache_peer
注意:貌似每一个cache_peer必须至少有一个cache_peer_domain与之相对应
像这样
cache_peer_domain xxx.xxx.xxx.xxx www.domain.cn
或者是
cache_peer_domain xxx.xxx.xxx.xxx .domain.cn
上面的xxx.xxx.xxx.xxx是后台real server的ip地址,且是在cache_peer中定义过的
到这里就差不多了
剩下的无非是用acl权限控制什么的
我多半喜欢用dstdomain来定义acl
除了这个acl的都不让访问
呵呵
因为一般反向加速模式的squid都是服务于自己公司的网站
而自己公司的域名一般也就那么两个
最重要的是天知道哪天某个公司的域名要加到squid的服务里来
哪天又要挪出去
这样设好了就一劳永逸
这两天碰到一个比较怪异的问题
在流量比较大的时候(8、9十兆)
squid对系统一个非常重要也访问量非常大的文件MISS的非常多
流量小一点的时候看起来貌似要正常很多(很多的HIT)
这个xml文件有1xxk之大
而且在apache里设定了expire为access后10分钟
但是访问量一大
access_log里就大段大段的报”TCP_MISS/200″
然后real server也发现流量剧增
环境:
linux2.6 + squid2.5stable14
real server: httpd 2.0.x
工作需要,接触了些squid的东西
以下的安装、编译方式适用于反向加速模式
ulimit -HSn 65536
这里是增大file descriptors(缺省是1024,太小了)
export CFLAGS=’-O2 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -mcpu=pentium4 -march=pentium4 -mmmx -msse -msse2′
export这个环境变量是为了在make的时候
1,打开大文件支持(支持存取>2G的文件);
2,针对p4的cpu做优化
阅读全文…
以前做东西总是不求甚解
没有打破砂锅问到底的精神
今天同事问我squid中refresh_pattern的问题
我就语塞了
知道是做过期控制的
但是具体每一个参数什么意思
该怎么配
就不明白了
refresh_pattern的用法是:
refresh_pattern [-i] regex min percent max [options]
这里regex就不用讲了,是用来匹配url的表达式
min和max是时间,单位是分钟
percent是百分数
这里讲讲判断squid上一个缓存对象是否过期的判断策略
这里的DATE是squid上缓存对象的时间
LM_DATE是源生成(或上次更改)的时间
这两个得看httpd的头信息
FRESH if (CURRENT_DATE – DATE) < min
FRESH if (CURRENT_DATE – DATE)/(DATE – LM_DATE) < percent
STABLE if (CURRENT_DATE – DATE) > max
OTHER, STABLE
如果需要把某个url定成永不过期
只需要把option参数设成ignore-reload即可
squid一直用的挺多的
自认为还有些了解
没想到今天同事一个问题就把我搞倒了
问题是:
要在access_log里记录访问url的参数
(也就是”?”后面的一些东西)
squid的access_log缺省是不记url里”?”后面的内容的
于是翻翻squid的文档
这才发现其实很简单
squid.conf里有个叫”strip_query_terms“的参数
设成off即可(缺省是打开的)
squid文档里是这么写的:
| Tag Name |
strip_qury_terms |
| Usage |
strip_query_terms on|off |
Description
Squid by default does not log query parameters. These parameters are however forwarded to the server verbatim. If we want to enable logging of query parameters, the strip_query_terms directive can be used .
By default, Squid strips query terms from requested URLs before logging. This protects your user’s privacy
| Default |
strip_query_terms on |
日前在squid 的access_log里发现很多"TCP_MISS:NONE"
按照squid的faq里讲
TCP_MISS的意思是缓存里没有请求的对象
(The requested object was not in the cache)
而NONE的意思是
For TCP HIT, TCP failures, cachemgr requests and all UDP requests,
there is no hierarchy information
搞不明白"TCP_MISS:NONE"是什么意思
最奇怪的是
他的return code还是200
原文出自这里。
The TCP_ codes refer to requests on the HTTP port (usually 3128). The UDP_ codes refer to requests on the ICP port (usually 3130). If ICP logging was disabled using the log_icp_queries option, no ICP replies will be logged.
The following result codes were taken from a Squid-2, compare with the log_tags struct in src/access_log.c:
- TCP_HIT
-
A valid copy of the requested object was in the cache.
- TCP_MISS
-
The requested object was not in the cache.
- TCP_REFRESH_HIT
-
The requested object was cached but STALE. The IMS query for the object resulted in "304 not modified".
- TCP_REF_FAIL_HIT
-
The requested object was cached but STALE. The IMS query failed and the stale object was delivered.
- TCP_REFRESH_MISS
-
The requested object was cached but STALE. The IMS query returned the new content.
- TCP_CLIENT_REFRESH_MISS
-
The client issued a "no-cache" pragma, or some analogous cache control command along with the request. Thus, the cache has to refetch the object.
- TCP_IMS_HIT
-
The client issued an IMS request for an object which was in the cache and fresh.
- TCP_SWAPFAIL_MISS
-
The object was believed to be in the cache, but could not be accessed.
- TCP_NEGATIVE_HIT
-
Request for a negatively cached object, e.g. "404 not found", for which the cache believes to know that it is inaccessible. Also refer to the explainations for negative_ttl in your squid.conf file.
- TCP_MEM_HIT
-
A valid copy of the requested object was in the cache and it was in memory, thus avoiding disk accesses.
- TCP_DENIED
-
Access was denied for this request.
- TCP_OFFLINE_HIT
-
The requested object was retrieved from the cache during offline mode. The offline mode never validates any object, see offline_mode in squid.conf file.
- UDP_HIT
-
A valid copy of the requested object was in the cache.
- UDP_MISS
-
The requested object is not in this cache.
- UDP_DENIED
-
Access was denied for this request.
- UDP_INVALID
-
An invalid request was received.
- UDP_MISS_NOFETCH
-
During "-Y" startup, or during frequent failures, a cache in hit only mode will return either UDP_HIT or this code. Neighbours will thus only fetch hits.
- NONE
-
Seen with errors and cachemgr requests.
The following codes are no longer available in Squid-2:
- ERR_*
-
Errors are now contained in the status code.
- TCP_CLIENT_REFRESH
-
See: TCP_CLIENT_REFRESH_MISS.
- TCP_SWAPFAIL
-
See: TCP_SWAPFAIL_MISS.
- TCP_IMS_MISS
-
Deleted, TCP_IMS_HIT used instead.
- UDP_HIT_OBJ
-
Hit objects are no longer available.
- UDP_RELOADING
-
See: UDP_MISS_NOFETCH
跑squid碰到一个问题
运行程序的时候报:
FATAL: Bungled squid.conf line xxx: cache_dir ufs /path/cache 256 16 256
Squid Cache (Version 2.5.STABLE13-xxxxxxxx):: Terminated abnormally.
结果发现是因为存储缓存用的是ufs
启用这种格式必须在编译squid的时候加上async-io的支持
在
于是重新编译squid,加上async-io支持
./configure –enable-async-io
这里如果cache_dir不是设的ufs而是aufs的话,还需要加上参数–enable-storeio=aufs
然后再
make;make install
再启动squid
就OK了
最近评论