C4-Squid-Purge

简介:

C4-Squid-Purge

 

删除缓存对象
在某些情况下,你必须从 squid 的 cache 里手工删除一个或多个对象,这些情况可能包括:
你的用户抱怨总接收到过时的数据;
你的 cache 因为某个响应而“中毒”;
Squid 的 cache 索引在经历磁盘 I/O 错误,或频繁的 crash 和重启后变得有问题;
你想删除一些大目标来释放空间给新的数据;
Squid 总从本地服务器中 cache 响应,现在你不想它这样做

上述中的一些可以通过强迫 web浏览器 reload 来解决,然而这并非总是可靠,例如一些浏览器通过载入另外的程序;
从而显示某些类容类型,那个程序可能没有 reload按钮,或甚至它了解 cache 的情况;
假如必要,你总可以使用 squidclient 程序来 reload 缓存目标,简单的在 uri 前面使用-r 选项,例如:
$ squidclient -r http://www.lrrr.org/junk >/tmp/foo
假如你碰巧在 refresh_pattern 指令里设置了 ignore-reload 选项,你和你的用户将不能强迫缓存响应更新;
在这样的情形下,你最好清除这些有错误的缓存对象

删除个别对象
Squid 接受一种客户请求方式,用于删除 cache 对象,PURGE 方式并非官方 HTTP 请求方式之一;
与 DELETE 不同对后 squid 将其转发到原始服务器,PURGE 请求要求squid 删除在 uri 里提交的目标;
squid 返回 200(OK)或 404(Not Found)
PURGE 方式某种程度上有点危险,因为它删除了 cache 目标,除非你定义了相应的ACL,否则 squid 禁止 PURGE 方式;
正常的你仅仅允许来自本机和少数可信任主机的PURGE 请求。配置看起来如下:

1 首先编辑 squid.conf 文件允许下列ip purge

 
  1. acl Admins src 127.0.0.1 192.168.57.0/24 10.0.100.0/24 
  2. acl Purge method PURGE 
  3. http_access allow Admins Purge 
  4. http_access deny Purge 


2 清除单个文件

//第一次purge

 
  1. /usr/local/squid/bin/squidclient -p 80 -m purge http://blog.test.com/wp-content/themes/twentyeleven/images/headers/chessboard.jpg 

HTTP/1.0 200 OK
Server: squid/2.7.STABLE9
Date: Mon, 06 Aug 2012 08:56:48 GMT
Content-Length: 0
Expires: Mon, 06 Aug 2012 08:56:48 GMT
X-Cache: MISS from cache02.test.com
Via: 1.0 cache02.test.com:80 (squid/2.7.STABLE9)
Connection: close
//第二次purge

 
  1. /usr/local/squid/bin/squidclient -p 80 -m purge http://blog.test.com/wp-content/themes/twentyeleven/images/headers/chessboard.jpg

....略
 

2.1 squid日志
//cache01
- - - [06/Aug/2012:16:56:07 +0800] "PURGE http://blog.test.com/wp-content/themes/twentyeleven/images/headers/chessboard.jpg HTTP/1.1" 200 248 "-" "-" TCP_MISS:NONE
- - - [06/Aug/2012:16:56:27 +0800] "PURGE http://blog.test.com/wp-content/themes/twentyeleven/images/headers/chessboard.jpg HTTP/1.1" 404 255 "-" "-" TCP_MISS:NONE

//cache02
- - - [06/Aug/2012:16:56:48 +0800] "PURGE http://blog.test.com/wp-content/themes/twentyeleven/images/headers/chessboard.jpg HTTP/1.1" 200 248 "-" "-" TCP_MISS:NONE
- - - [06/Aug/2012:16:56:49 +0800] "PURGE http://blog.test.com/wp-content/themes/twentyeleven/images/headers/chessboard.jpg HTTP/1.1" 404 255 "-" "-" TCP_MISS:NONE


3 批量清除

 
  1. sh clear_squid_cache.sh test.com
  2.  
  3. cat clear_squid_cache.sh 
  4. #!/bin/bash 
  5. #clear the squid cache file 
  6. #20120806 
  7.  
  8. #variables 
  9. squid_cache_path=/var/ 
  10. squid_client=/usr/local/squid/bin/squidclient 
  11. squid_client_option="-p 80 -m PURGE" 
  12.  
  13. #main 
  14. grep -a -r -E "$1" ${squid_cache_path}cache* | strings | awk '/^http:/' > tmp.txt 
  15.  
  16. while read url;do 
  17.     $squid_client $squid_client_option $url 
  18. done < tmp.txt 



参考
squid缓存清除的方法
http://freehat.blog.51cto.com/1239536/737388

找到一款批量清除Squid缓存的小工具及方法
http://blog.sina.com.cn/s/blog_485acedb0100fvmw.html

Squid 中文权威指南
http://home.arcor.de/pangj/squid/

C1-Squid_Cache-Server 
http://dngood.blog.51cto.com/446195/939524

C2-Squid_Neighbour
http://dngood.blog.51cto.com/446195/955710

C3-Squid-access.log
http://dngood.blog.51cto.com/446195/962182

结束
更多请:
linux 相关 37275208
vmware 虚拟化相关  166682360
 


本文转自 dongnan 51CTO博客,原文链接:http://blog.51cto.com/dngood/967306


相关文章
|
缓存 应用服务中间件 nginx
Nginx 学习笔记(三)proxy_cache 缓存配置和ngx_cache_purge模块
反向代理的缓存清理 一、proxy_cache配置 (1)如何配置和安装,都在这里了:https://github.com/Tinywan/Lua-Nginx-Redis/blob/master/Nginx/Nginx-Web/Nginx-8-proxy_cache.
2877 0
|
Web App开发 开发工具
|
缓存 应用服务中间件 PHP
|
Shell 网络安全