cacheClean.sh
#!/bin/bash # 日期: 20191218 # 作者: 黃慧豐/何鵬舉 # 說明: fastdfs所在的linux系統的buffer cache過大, 且並沒有有效的自動回收, 因此手動編寫腳本定時執行 # 參考: https://blog.csdn.net/c123m/article/details/78060149 log=cacheClean.log echo "***開始***" >> $log date '+%Y-%m-%d %H:%M:%S' >> $log echo "清理前:" >> $log free -h >> $log # 寫入硬盤,防止數據丟失 sync;sync;sync # 延遲10秒 sleep 10 # *****清理緩存***** # echo 1 > /proc/sys/vm/drop_caches:表示清除pagecache。 # echo 2 > /proc/sys/vm/drop_caches:表示清除回收slab分配器中的對象(包括目錄項緩存和inode緩存)。slab分配器是內核中管理內存的一種機制,其中很多緩存數據實現都是用的pagecache。 # echo 3 > /proc/sys/vm/drop_caches:表示清除pagecache和slab分配器中的緩存對象。 echo 3 > /proc/sys/vm/drop_caches date '+%Y-%m-%d %H:%M:%S' >> $log echo "清理后:" >> $log free -h >> $log echo "***結束***" >> $log echo "" >> $log
cacheClean.log 示例
***開始*** 2019-12-18 13:52:38 清理前: total used free shared buff/cache available Mem: 15G 14G 1.2G 3.8M 197M 1.1G Swap: 7.9G 3.1G 4.8G 2019-12-18 13:52:48 清理后: total used free shared buff/cache available Mem: 15G 14G 1.2G 3.8M 153M 1.1G Swap: 7.9G 3.1G 4.8G ***結束*** ***開始*** 2019-12-18 13:52:49 清理前: total used free shared buff/cache available Mem: 15G 14G 1.2G 3.8M 153M 1.1G Swap: 7.9G 3.1G 4.8G 2019-12-18 13:52:59 清理后: total used free shared buff/cache available Mem: 15G 14G 1.2G 3.8M 152M 1.1G Swap: 7.9G 3.1G 4.8G ***結束***