查看緩存
[root@bogon ~]# free -h
total used free shared buff/cache available
Mem: 62G 26G 18G 2.0G 18G 34G
Swap: 15G 14M 15G
清除緩存腳本
#!/bin/bash
echo "開始清除緩存"
sync;sync;sync; # 將未寫入的緩存寫入硬盤,防止數(shù)據(jù)丟失
sleep 60 # 暫停 60秒
echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches
創(chuàng)建定時腳本
crontab e 打開定時器編輯
0 */2 * * * ./cleanCache.sh