linux清理buffer缓存脚本
1、清理缓存脚本
[root@host-172-21-210-62 opt]# more cleanCache.sh #!/bin/bash #每24小时清除一次缓存 echo "开始清除缓存" sync;sync;sync #写入硬盘,防止数据丢失 sleep 10 #延迟10秒 echo 1 > /proc/sys/vm/drop_caches echo 2 > /proc/sys/vm/drop_caches echo 3 > /proc/sys/vm/drop_caches
2、清理前buff情况
[root@host-172-21-210-62 ~]# free -g total used free shared buff/cache available Mem: 31 4 6 1 19 24 Swap: 0 0 0
3、清理buff
[root@host-172-21-210-62 opt]# sh cleanCache.sh
4、清理后缓存情况
[root@host-172-21-210-62 opt]# free -g total used free shared buff/cache available Mem: 31 4 23 1 2 24 Swap: 0 0 0
drop_caches的详细文档如下:
Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free. To free pagecache: echo 1 > /proc/sys/vm/drop_caches To free dentries and inodes: echo 2 > /proc/sys/vm/drop_caches To free pagecache, dentries and inodes: echo 3 > /proc/sys/vm/drop_caches As this is a non-destructive operation, and dirty objects are notfreeable, the user should run “sync” first in order to make sure allcached objects are freed. This tunable was added in 2.6.16.
做一个决定,并不难,难的是付诸行动,并且坚持到底。

浙公网安备 33010602011771号