定时清理缓存

2018-08-05  本文已影响0人  Nick_4438

前言

本文介绍如何在centos 中清理RAM Memory Cache, Buffer and Swap Space

清理脚本

clearcache.sh

#!/bin/bash
# Note, we are using "echo 3", but it is not recommended in production instead use "echo 1"
su -c "echo 3 >'/proc/sys/vm/drop_caches' && swapoff -a && swapon -a && printf '\n%s\n' 'Ram-cache and Swap Cleared'" root

设置定时任务

crontab -e
0 4 * * * root /{path of file}/clearcache.sh

参数

  1. Clear PageCache only.
sync; echo 1 > /proc/sys/vm/drop_caches
  1. Clear dentries and inodes.
sync; echo 2 > /proc/sys/vm/drop_caches
  1. Clear PageCache, dentries and inodes.
sync; echo 3 > /proc/sys/vm/drop_caches 

参考文献

http://man.linuxde.net/sync
https://www.tecmint.com/clear-ram-memory-cache-buffer-and-swap-space-on-linux/

上一篇 下一篇

猜你喜欢

热点阅读