Sie sind auf Seite 1von 2

Clear Memory in Linux Box

Clear Memory in Linux (specially for squid servers)


If you are hosting SQUID proxy server on your Linux box, you may have noticed that SQUID as a proxy server is very greedy with memory. Over the period of time, it consumes large amount of memory , even in some cases 98-99%. This script will clear the memory so that it be used by system or SQ I! again. "a#e sure you are logged in with root user in order to continue. $ust create a new script and put it in any folder li#e %temp &reate 'ile by following command

1 2 3 4 5 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

mkdir /temp cd /temp touch clearmem.sh touch /var/log/cron.log chmod +x clearmem.sh


(ow edit the file by

nano /temp/clearmem.sh
.)nd *aste the following code.

#!/bin/bash # Clear/Dump Cache Memory, to increase ree memory, use ul or !"#$D proxy %& or # !yed 'ahan(aib / )mail* aacable+hotmail.com ,eb* http*//aacable.-ordpress.com # Make sure you are .ogged in -ith user root. # !etting variables or script set /0date1 time23date 4a-k 56print /7853 # 9ction . . . sync: echo ; < /proc/sys/vm/drop=caches

# 9dd entry in /var/log/cron.log to make record. echo >'(? Cache Memory Clear, 9ction .ogged at /@A/BA/; /time < /var/log/cron.log

.Save, and Exit. (ow change the permission so it can be executed.

1
.

chmod CDD /temp/clearmem.sh

(ow first execute

ree Am
and note down the free memory, (ow execute the file by running + /temp/clearmem.sh chec# the log file by cat %var%log%cron.log (ow again chec# the free amount from terminal with the command

ree Am
.)nd you will see the changes before and after running the file clearmem.sh .Howto schedule this file to run daily/hourly using crontab To run this file on hourly basis, open terminal, ,ma#e sure you are logged in with the root user. type crontab -e ,if it as#s for text editor, select nano ,(ow paste following code + @dail /temp/clearmem.sh ! "#n Dail in ni$ht at %%&%% ho#rs

! @ho#rl

/temp/clearmem.sh ! Enable this i' o# (ant to r#n the script on ho#rl basis

(ow, based on above selection, cron .ob will run this command at selected scheduled timings and clear any memory cache (ow some /xplanation of what above script do . . . It will cause the #ernel to drop clean caches, dentries and inodes from memory, causing that memory to become free. ) s nc only ma#es dirty cache to clean cache. cache is still preserved. ) drop*caches doesn0t touch dirty caches and only drops clean caches. So to ma#e all memory free, it is necessary to do sync first before drop*caches in case flushing daemons hasn0t written the changes to dis#. This is in generally a non1destructive operation.

Das könnte Ihnen auch gefallen