Remove the Squid Proxy Server Cache Manually / Automatically
If you want to delete an object in the Squid proxy server cache, all you can do is manually and automatically delete the Squid proxy cache, here we will discuss how to maintain our proxy machine, the following methods can be run manually or automatically in removing the cache your squid proxy.
Manually delete the squid proxy cache;
1. Stop/stop the running Squid process
# /etc/init.d/squid stop
2. Clean all of Squid’s swap directory cache
# rm -rf /cache/*
3. Make / re-install the Squid cache swap directory
# squid -z
4. Run the squid proxy server again
# /etc/init.d/squid start
Automatically delete the Squid proxy cache
If you want to delete the squid proxy cache automatically, the following steps:
- Create a script that will be used to automatically check and delete the squid proxy cache
# touch /root/clear-cache-squid.sh
# vim /root/clear-cache-squid.sh
Enter the following code, where in the following code setting the Squid proxy hard drive is 80GB, the squid cache directory is in / cache and the script will be placed on / root
#!/bin/bash
#!/bin/bash
# direktori cache proxy
CACHEDIR=/cache
# proxy cache directory capacity (80GB)
CACHEDIRSIZE=85899345920
ONEMB=1048576
ONEGB=1073741824
COUNTMB=`expr $CACHEDIRSIZE / $ONEMB`
COUNTGB=`expr $CACHEDIRSIZE / $ONEGB`
COUNTALOC=`expr $CACHEDIRSIZE / $ONEMB`
# get the current cache directory size
SIZE=`du -bc $CACHEDIR | grep total | awk '{print $1}'`
SIZEM=`du -bch $CACHEDIR | grep total | awk '{print $1}'`
# if the cache directory size is currently equal to or greater than
# proxy cache directory capacity then delete proxy cache
if [ $SIZE -ge $CACHEDIRSIZE ]
then
/usr/bin/clear
echo "=================================="
echo "=== Generate Clear Cache Squid ==="
echo "=================================="
echo "Cahce Squid Proxy :" $CACHEDIR
echo "Jumlah cache tersimpan :" $SIZE Byte / $SIZEM
echo "Batas maximum cache :" $CACHEDIRSIZE Byte / $COUNTALOC MB
echo " * Clear cache squid in proccess ..."
sleep 10
/etc/init.d/squid stop # stop service squid
rm -fdR $CACHEDIR/* # hapus cache proxy
squid -z # membuat cache direktori
/etc/init.d/squid start # start service squid
/usr/bin/clear
echo "===================================="
echo "=== Clear Cache Squid Success !! ==="
echo "=== http://www.backlinux.com ==="
echo "===================================="
else
/usr/bin/clear
echo "================================================"
echo "=== Status Directory Cache Squid Proxy [OK] ==="
echo "=== http://www.techsoftcenter.com ==="
echo "================================================"
echo "Cahce directory squid :" $SIZE Byte / $SIZEM
echo "Alokasi cahce squid :" $CACHEDIRSIZE Byte / $COUNTMB MB / $COUNTGB GB
fi
Give access rights so that the clear-cache-squid.sh script can be run
# chmod ug+x /root/clear-cache-squid.sh
After you have created the file, it is time to put it on your cronjob system, so that the script can run automatically every day at midnight.
Edit cronjob
# crontab -e
Enter the following cronjob code
0 0 * * * /root/clear-cache-squid.sh
To more easily convert the amount of GB to KB or vice versa you can use website services including KB, MB, GB Converter, squid clear cache script that you can.
