[文章作者:张宴 本文版本:v1.0 最后修改:2007.08.02 转载请注明出处:http://blog.zyan.cc]

  Squid web缓存加速软件目前已经是新浪、搜狐、网易等各大网站广泛应用。Squid会在设置的缓存目录下建立多个目录,每一个目录下又建立多个目录,然后才在最里层的目录中存放缓存文件(object)。squid会根据用户请求网页的URL进行哈希,生成缓存文件,存放在某一个目录中。squid启动之后,将在内存中建立一个哈希表,记录硬盘中缓存文件配置的情形。

  对于类似http://you.video.sina.com.cn/index.html之类的网页,squid只会生成一个缓存文件。可以用squid附带的squidclient工具清除:
引用
squidclient -m PURGE -p 80 "http://you.video.sina.com.cn/index.html"


  而对于带有参数的网页,例如新浪播客的Flash播放器http://vhead.blog.sina.com.cn/player/outer_player.swf?auto=0&vid=4469852&uid=1278987704,因“?”后面的参数不同,导致URL也不同,squid会生成多个缓存文件,哈希分散存放在不同的目录。如果修改了这个outer_player.swf文件,要更新squid缓存就要去清除不同目录下及内存中的很多个缓存文件,十分麻烦,于是我编写了一个Linux下的shell脚本,去完成这件麻烦的事:

  脚本文件名:clear_squid_cache.sh(8月2日修正了UC网友“城市中的寂寞”反馈的BUG)
引用
#!/bin/sh
squidcache_path="/data1/squid/var/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

  注意:请赋予clear_squid_cache.sh可执行权限(命令:chmod +x ./clear_squid_cache.sh)。请确保脚本所在目录可写。

  设置:
  squidcache_path= 表示squid缓存目录的路径
  squidclient_path= 表示squidclient程序所在的路径,默认为squid安装目录下的bin/squidclient

  用法:
  1、清除所有Flash缓存(扩展名.swf):
  ./clear_squid_cache.sh swf

  2、清除URL中包含sina.com.cn的所有缓存:
  ./clear_squid_cache.sh sina.com.cn

  3、清除文件名为zhangyan.jpg的所有缓存:
  ./clear_squid_cache.sh zhangyan.jpg

  效率:
  经测试,在DELL 2950上清除26000个缓存文件用时2分钟左右。平均每秒可清除缓存文件177个。

Tags: , ,



技术大类 » Cache与存储 | 评论(36) | 引用(0) | 阅读(61291)
你好
2008-8-4 10:33
client: ERROR: Cannot connect to localhost:80: Connection refused


缓存清理脚本出现的错误信息 不知道哪里出错了
帮忙看一下 谢谢了
todayboy Email
2008-12-20 14:24
client: ERROR: Cannot connect to localhost:80: Host unknown.

我也有同样的错误,不知是什么原由:
[root@mamiai01 etc]# . clear_squid_cache.sh  .jpg
client: ERROR: Cannot connect to localhost:80: Host unknown.
client: ERROR: Cannot connect to localhost:80: Host unknown.
HTTP/1.1 301 Moved Permanently
Server: nginx/0.5.23
Date: Sat, 20 Dec 2008 06:22:33 GMT
Content-Type: text/html
Content-Length: 185
Connection: close
Location: http://bjdns3.cncmax.cn:8080?HOST=mamiai.cn&R=/mamiai/baby/images/index_81_13.jpg&
D Homepage
2009-4-3 15:53
运行squidclient -h ip PURGE http://ip:port/index.html
提示 403 forbidden
xi2008wang
2009-5-6 17:03
ls的兄弟, 不是哪个人都能随便清除的.
看一下htcp_clr_access就知道了
默认是拒绝所有人
htcp_clr_access deny all

并且squid在编译时要加上--enable-htcp
小丑鱼 Email
2010-1-20 16:48
张老师我觉得你的grep那段结果还是会出来很多不相关的连接,我对你的grep优化了下好像有好转,你看下

grep -aR $1 $squidcache_path/* | strings | grep "^http:" |grep "$1$" > cache_list.txt
aa
2010-6-29 16:03
看一下你/etc/hosts是否是正常的
client: ERROR: Cannot connect to localhost:80: Host unknown.

我也有同样的错误,不知是什么原由:
[root@mamiai01 etc]# . clear_squid_cache.sh  .jpg
client: ERROR: Cannot connect to localhost:80: Host unknown.
client: ERROR: Cannot connect to localhost:80: Host unknown.
HTTP/1.1 301 Moved Permanently
Server: nginx/0.5.23
Date: Sat, 20 Dec 2008 06:22:33 GMT
Content-Type: text/html
Content-Length: 185
Connection: close
Location: http://bjdns3.cncmax.cn:8080?HOST=mamiai.cn&R=/mamiai/baby/images/index_81_13.jpg&
心远
2010-8-4 10:51
[root@vps238 bin]# ./clear_squid_cache.sh uggs4sale.com
grep: /dev/kmem: Permission denied
不知道这是什么原因?
狂奔的鹿
2010-12-21 15:33
client: ERROR: Cannot connect to localhost:80: Host unknown.
client: ERROR: Cannot connect to localhost:80: Host unknown.

HOSTS文件没有解析localhost                 打/etc/hosts   添加  127.0.0.1 localhost
dresses Email Homepage
2011-7-26 10:14
Here are a variety of the empire <a href="http://www.romancearound.com/">dresses</a>, I want to introduce yourself. The first shoulder chiffon <a href="http://www.romancearound.com/bridesmaid-dresses-c-197.html">bridesmaid dresses</a> empire style wedding will <a href="http://www.romancearound.com/wedding-dresses-trumpet-wedding-dresses-c-180_253.html">trumpet wedding dresses</a>.This Tia cowries, dressed in her wedding day.Chiffon of the empire the best clothes, because they are the size of the drum as complete motion from the wind the site makes it easy to create a plan impression.One romantic flowers floating above shoulder function and help catch the eyes of the cut of the chest and neck problems, so that more comprehensive coverage of physical illusion bust.Clothing do not like big long torso, short legs, or pear-shaped<a href="http://www.romancearound.com/bridesmaid-dresses-ankle-length-bridesmaid-dresses-c-197_198.html">ankle length bridesmaid dresses</a> figure.special is also suitable for pregnant brides since the mobility as a dress can accommodate more Many of the abdomen.
louis vuitton uk Email Homepage
2011-11-23 08:48
This louis vuitton uk for sale belongs to the sounding just what are termed as Louis Vuitton vintage best sellers, many other products and services for the reason that range appearing companies.You will easily notice the unfold zippers of this coach outlet store online. That is the decoration. There are some inside pockets for you as well. They are easy to match your clothes and to carry.Let us inspire your inner beauty with fine christian louboutin sale. Purse the elegance in bridal wedding. Enjoy the fashion.
coach factory outlet Email Homepage
2012-5-17 10:52
Today, following half a century, mentor leather-bases coach factory outlet continues to be the delicate craft of leather-based master is accountable for,Would you like to meet more friends, or go with the times? If yes, coach factory online is opening welcome doors to you.in the market you definitely can find various colorways that are designed in as well as the high quality that applied in. For most of you would like to come. So just come to our coach factory outlet online store to choose one.
louis vuitton sale Email Homepage
2012-5-17 10:52
Louis Vuitton belt at louis vuitton sale is one kind of fashion accessory with high cost performance among the Louis Vuitton accessories.Offering quality LV products with favorable prices, louis vuitton outlet store is at your service. Hurry up, or you can not seize the chance.in fact, louis vuitton is one of the most famous fashion design master.he opened the fist suitcase shop called after his name.
coach outlet online Email Homepage
2012-5-17 10:52
I heard of coach outlet online through the advertisement when I was shopping. And now I often brow the webpage and buy Coach bags online.It is a symbol regarding position not to mention nature.Here I would like to launch a excellent bags pertaining to business men.Which may be coach outlet store.coach outlet has always been simple,durable style features to win consumers.The products are more flexible,with easy bleaching,wear characteristics,and simply use a damp cloth.
coach outlet, Email Homepage
2012-5-17 10:52
Remember the coach outlet provide coach bags which won't be deteriorated into its overall styles by any means. It will maintain its looks, colors, and uniqueness for long time.coach outlet store online has been voted by Hour Detroit magazine readers as the Best of Detroit in their 12th annual readers'poll.Lots of women like which usually amount normally include a coach outlet online ,it provides coziness to many girls that don't even think it is a great bushel of great interest directly to them.
xujie777 Email
2012-5-18 15:58
We aim to make all our customers satisfy with our products. You will find a variety of Men's fashion louis vuitton uk, fashion Women's cheap Louis Vuitton bags in our store at affordable price.Thinking of interesting ways to cost a milestone birthday? louis vuitton online shop had one of the most distinctive distinctive celebrations.bakery along with living room operated by means of about three moment louis vuitton online Most effective Pastry Chef’s of the year Rammy Nominee Chef’s.
xujie777 Email
2012-5-18 15:58
The choices are likely to be basically countless seeing that louis vuitton outlet occurs with the help of completely new and also incredible concepts once in a while.Louis vuitton Wholesale Monogram Canvas HandbagsLouis Vuitton Collection Beach Handbags louis vuitton bags outlet Damier Canvas HandbagsLouis vuitton Mahina HandbagsLouis Vuitton Monogram Mini Lin HandbagsLouis Vuitton Monogram Multicolore HandbagsLouis vuitton Monogram Vernis HandbagsLouis Vuitton Wholesale Epi Leather HandbagsLouis Vuitton For Men HandbagsLouis Vuitton Damier Canvas WalletsLouis Vuitton Epi Leather WalletsLouis Vuitton Monogram Canvas WalletsLouis Vuitton Monogram Vernis WalleLouis Vuitton ShoesLouis Vuitton Men wallets.As the Authentic Louis Vuitton are so high-priced, so came the louis vuitton handbags outlet.
xujie777 Email
2012-5-18 15:58
coach outlet has become a popular shopping experience for consumers around the world, and a desirable distribution channel for manufacturer's and retailers.Getting your hands on coach outlet store online can be a hefty investment of hundreds of dollars.But do not despair,the Coach Outlet store could be the answer to your prayers.coach outlet online is your smart choice when you want to get the discount Coach accessory. You can find the exact Coach Bags and other accessory you want at a low price that's right for you. My dear friends, let the coach outlet online pave your way into the world of high fashion with their ultimate fashion factory.
xujie123
2012-5-21 11:02
Our online store offers you discounted Designer louis vuitton replica wallet at present. You could find them in desirable quality and price. If you don't mind high class louis vuitton uk, have a good time here.louis vuitton Store Online Handbags can also bring great accuracy as well as practical applicability and fashionable.Have you ever dreamed of being as charming as Madonna? Have you ever thought of becoming an envy of all your friends? If so, come to louis vuitton outlet.<br/>
分页: 1/2 第一页 1 2 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]