Selasa, 10 September 2013

Clear Cache Squid

1. Matikan Proses squid yang berjalan
  root#/etc/init.d/squid stop

2.Membersihkan semua swap directory cache squid
  root#rm -rf /cache/*
  jika ada banyak folder cache maka lanjutkan 
  root#rm -rf /cache1/*

3.Membuat/buil kembali directory swap cache squid 
  root#squid -z

4.Menjalankan kembali squid proxy server 
  root#/etc/init.d/squid start

Menghapus cache squid proxy secara otomatis
Jika anda ingin menghapus cache squid proxy secara otomatis berikut langkahnya:
1. Buat sebuat script yang akan digunakan untuk memeriksa dan menghapus cache     squid proxy secara otomatis 

  root#touch /root/clear-cache-squid.sh
  root#vim /root/clear-cache-squid.sh
2. Masukkan kode berikut, dimana dalam kode berikut pengaturan Hardisk squid proxy sebesar 80GB, direktory cache squid berada pada /cache dan script akan diletakkan pada /root 

#!/bin/bash
#!/bin/bash
 
# direktori cache proxy
CACHEDIR=/cache
 
# kapasitas direktori cache proxy (80GB)
CACHEDIRSIZE=85899345920
ONEMB=1048576
ONEGB=1073741824
COUNTMB=`expr $CACHEDIRSIZE / $ONEMB`
COUNTGB=`expr $CACHEDIRSIZE / $ONEGB`
 
COUNTALOC=`expr $CACHEDIRSIZE / $ONEMB`
 
# mendapatkan besaran direktori cache saat ini
SIZE=`du -bc $CACHEDIR | grep total | awk '{print $1}'`
SIZEM=`du -bch $CACHEDIR | grep total | awk '{print $1}'`
 
 
# jika besaran direktori cache saat ini sama atau lebih besar dari
# kapasitas direktori cache proxy maka hapus cache proxy
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.backlinux.com          ==="
echo "================================================"
echo "Cahce directory squid :" $SIZE Byte / $SIZEM
echo "Alokasi cahce squid   :" $CACHEDIRSIZE Byte / $COUNTMB MB / $COUNTGB GB
 
fi
   
Beri hak akses agar script clear-cache-squid.sh dapat dijalankan 
   root#chmod ug+x /root/clear-cache-squid.sh
 
Setelah file sudah anda buat sekarang saatnya untuk meletakkannya pada cronjob system anda, agar script dapat dijalankan secara otomatis setiap hari tepat tengah malam.
Edit cronjob  
 
   root#crontab -e
 
Masukkan code cronjob berikut  
0 0 * * * /root/clear-cache-squid.sh
 
 
 
SUMBER:http://