Linux 設置定時清除buff/cache的腳本
查看內存緩存狀態
[root@heyong ~]# free -m total used free shared buff/cache available Mem: 96406 19256 11311 66 65837 76421 Swap: 4095 1016 3079
清理緩存的腳本
[root@heyong ~]# vim /home/script/clear_buff_cache.sh
#!/bin/bash #開始清理緩存 echo "開始清除緩存" #寫入硬盤,防止數據丟失 sync;sync;sync #延遲10秒 sleep 10 #清理緩存 echo 3 > /proc/sys/vm/drop_caches
設置定時任務(每天凌晨2:30清理一次)
[root@heyong ~]# crontab -e # clear buff/cache 30 2 * * * /home/script/clear_buff_cache.sh