Linux cache memory footprint is too large, Centos7 set the timer clear buff / cache script

Linux System buff / cache memory for caching data is too high, regular clean buff / cache, memory release system

root permission to create a script file:

touch cleanCache.sh && vim cleanCache.sh
! # / bin / bash 
echo "started clearing the cache" 
Sync; Sync; Sync # written to the disk to prevent data loss 
sleep 10 # 10-second delay 
echo 1> / proc / SYS / vm / drop_caches 
"liquidation" echo

# Script can modify according to their own situation:

# The default is 0, do not clear the buffer cache and page cache

# Available values ​​0-3

echo 1 > /proc/sys/vm/drop_caches
echo 1 > /proc/sys/vm/drop_caches
echo 1 > /proc/sys/vm/drop_caches

# The higher the value of the program on the system will be up and running more slowly

Set timer task, run once every 2 hours

-e crontab 

0 * / 2 * * * SH /root/cleanCache.sh 

// See if successful 
crontab -l

  To ensure that crond start and boot from Kai

systemctl start crond.service
systemctl enable crond.service

  See if regular tasks to be performed

cat /var/log/cron | grep cleanCache

  

 

Guess you like

Origin www.cnblogs.com/luckyall/p/11957245.html