Squid 缓存的相关操作及使用说明
一、查看squid命中情况除了之前在squid的access.log中查看squid缓存命中的方法之外,还可以通过以下方法进行查看:
这里对图片服务器的httpd配置文件添加一些新的配置如下:
ExpiresActive on
ExpiresDefault "access plus 12 month"
ExpiresByType text/html "access plus 12 months"
ExpiresByType text/css "access plus 12 months"
ExpiresByType image/gif "access plus 12 months"
ExpiresByType image/jpeg "access plus 12 months"
ExpiresByType image/jpg "access plus 12 months"
ExpiresByType image/png "access plus 12 months"
ExpiresByType application/x-javascript "access plus 12 months"
ExpiresByType vedio/x-flv "access plus 12 months"
把以上内容追加到httpd.conf文件中,然后重新启动httpd服务。
1)使用curl命令查看
# curl -I -s http://192.168.49.135/lnmp.jpg
HTTP/1.0 200 OK
Date: Mon, 31 Oct 2016 03:10:20 GMT
Server: Apache/2.2.15 (CentOS)
Last-Modified: Thu, 26 Jun 2014 01:12:31 GMT
ETag: "bf742-2f37a-4fcb2e3149dc0"
Accept-Ranges: bytes
Content-Length: 193402
Content-Type: image/jpeg
Age: 22522
X-Cache: HIT from cache1.contoso.com
Via: 1.0 cache1.contoso.com (squid/3.0.STABLE20)
Connection: close
# curl -I -s http://192.168.49.135/lnmp.jpg|grep -i x-cache
X-Cache: HIT from cache1.contoso.com
# curl -I -s http://192.168.49.135/php.jpg|grep -i x-cache
X-Cache: HIT from cache1.contoso.com
# curl -I -s http://192.168.49.135/nginx.jpg|grep -i x-cache
X-Cache: HIT from cache1.contoso.com
# curl -I -s http://192.168.49.135/mysql.png|grep -i x-cache
X-Cache: HIT from cache1.contoso.com
2)使用Firefox的firebug插件进行查看
http://s4.运维网.com/wyfs02/M01/89/8B/wKiom1gXD5azPaNFAAHmzPm0qCY191.png-wh_500x0-wm_3-wmp_4-s_10850382.png
可以看到,在响应头信息中,有max-age也就是我在httpd中设置的expire时间,同样也可以在Expires看到过期时间,Server项显示web服务器的类型,这里是Apache;Via表示通过哪个代理服务器进行访问,这里是我在squid.conf中配置的名称cache1.contoso.com(后面还有squid的版本信息);X-Cache中HIT from cache1.contoso.com表示请求内容在cache1.contoso.com上命中。
3)可能遇到的问题及原因
问题1:日志看不到命中
原因:curl的不是squid缓存服务器地址,而是web服务器,所以看不到命中。
问题2:看到的总是MISS
原因:使用了Ctrl+F5刷新,所以总是cache丢失。
问题3:是否做了服务器时间同步?
服务器时间同步会影响缓存结果,需要在服务器上进行时间同步。
二、修改squid的默认日志格式
squid默认记录日志格式如下:
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %h %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %
页:
[1]