In the daily operations, as long as the use of Squid cache service, will often be asked to clean up the squid cache.
For example, the company leader asked to delete a piece of news, news is generated static. OPS personnel to the server on the static news page deleted, but the proxy server on the cache.
Cache server If you are using Suqid, here's a comb for how to clean up the squid cache:
(1) First add the ACL list to the squid's master profile and allow trusted hosts to clear the cache.
[Email protected] ~]# vim/etc/squid/squid.conf
.......
.......
ACL managercache src 192.168.1.145 127.0.0.1
ACL Purge Method Purge
Http_access Allow Managercache Purge
Http_access Deny Purge
(2) Use squid to bring command squidclient
The following clears the squid in a cache,-H is the trusted cleanup cache server Ip,-p is the specified squid port
[Email protected] ~]#/usr/bin/squidclient-h 192.168.1.145-p 80-m PURGE http://www.linuxidc.com/404.html
Or
[Email protected] ~]#/usr/bin/squidclient-p 80-m PURGE http://www.linuxidc.com/404.html
-------------------------------------------------------
Get information on all cache *.jpg
[Email protected] ~]#/usr/bin/squidclient-p mgr:objects | grep jpg
Get Squid Run status information
[Email protected] ~]#/usr/bin/squidclient-p mgr:info
Get Squid memory usage
[Email protected] ~]#/usr/bin/squidclient-p Mgr:mem
Get a list of squid already cached (Use caution with this command may cause crashes):
[Email protected] ~]#/usr/bin/squidclient-p mgr:objects
Get Squid disk usage:
[Email protected] ~]#/usr/bin/squidclient-p MGR:DISKD
To force a URL to be updated:
[Email protected] ~]#/usr/bin/squidclient-p 80-m PURGE http://www.yejr.com/static.php
-------------------------------------------------------
(3) Delete by script
For example, write a script to delete the squid cache clear_squid_cache.sh, as follows:
[Email protected] ~]# vim clear_squid_cache.sh
#!/bin/sh
Squidcache_path= "/data1/squid/var/cache"
Squidclient_path= "/usr/bin/squidclient"
GREP-A-R $ $squidcache _path/* | Strings | grep "http:" | Awk-f ' http: ' {print ' http: "$ $;} ' > Cache_list.txt
For URLs in ' cat cache_list.txt '; Do
$squidclient _path-m purge-p $url
Done
[[email protected] ~]# chmod 755 clear_squid_cache.sh # give script permission to execute
Note: The following two settings are in the script:
Squidcache_path= represents the path to the Squid cache directory, which can be found in the squid.conf configuration file
Squidclient_path= represents the path to the Squidclient program, which defaults to the bin/squidclient in the Squid installation directory
-P is the port that specifies squid listening
Usage:
Clear all flash caches (extension. swf):
[[Email protected] ~]# SH clear_squid_cache.sh swf
Clear all caches that contain sina.com.cn in the URL:
[Email protected] ~]# sh clear_squid_cache.sh sina.com.cn
Clear all caches with file name huanqiu.jpg:
[Email protected] ~]# sh clear_squid_cache.sh huanqiu.jpg
If you have a frequently updated GIF or something, you can add the corresponding command line to the crontab
Assume that the above script is in the/root directory. As follows:
[Email protected] ~]# CRONTAB-E
0 * * * */bin/bash/root/clear_squid_cache.sh GIF &
This will be a refresh operation every one hours, it is convenient
If you need to let the image update staff to refresh themselves, you can find the appropriate person to develop a Web page, make a call to the script can be
Scripting efficiency:
After testing, this script clears 26,000 cache files for 2 minutes or so, with an average of 177 cache files per second.
(4) There is also a way to directly delete the Squid cache directory, so that the entire cache of squid deleted!
Then re-create an empty directory with the same name as the cache directory, then squid-z reinitialization, and finally restart squid!
View the squid.conf configuration file, such as the cache directory is/data1/squid/var/cache (Cache_dir set later)
[Email protected] ~]# Rm-rf/data1/squid/var/cache
[Email protected] ~]# squid-z
[Email protected] ~]#/etc/init.d/squid restart
Method records for clearing squid cache under Linux