zoukankan      html  css  js  c++  java
  • 定时 回收 CentOS 系统 内存

    #!/bin/bash
    
    LIMIT=512
    LOG_FILE="/data/logs/timing_dropcaches.log"
    
    #定时清理系统内存
    #https://blog.csdn.net/gaojinshan/article/details/40710369
    used=`free -m | awk 'NR==2' | awk '{print $3}'`
    free=`free -m | awk 'NR==2' | awk '{print $4}'`
    
    echo "===========================" >> $LOG_FILE
    date +"%Y-%m-%d %H:%M.%S" >> $LOG_FILE
    echo "Memory usage | [Use:${used}MB][Free:${free}MB] | limit[${LIMIT}MB]" >> $LOG_FILE
    
    # drop caches when the free memory less than 512M
    if [ $free -le $LIMIT ] ; then
     #sync && echo 1 > /proc/sys/vm/drop_caches
     #sync && echo 2 > /proc/sys/vm/drop_caches
     sync && echo 3 > /proc/sys/vm/drop_caches
     echo "OK" >> $LOG_FILE
    else
     echo "Not required" >> $LOG_FILE
    fi

    以上脚本加入crontab

    #每半小时检查内存使用情况,并清理一次内存
    */30 * * * * /data/shell/timing_dropcaches.sh >> /data/logs/timing_dropcaches.log

    #删除3天前的日志
    0 1 * * * /usr/bin/find /data/logs/ -name *.log -mtime +3 | grep 2018 | xargs rm -Rf {} > /dev/null 2>&1
  • 相关阅读:
    轻时代来临 资深架构师分享手游五大设计要点
    Netty 介绍
    Socket编程与线程
    java多线程并发访问解决方案
    throws 和throw 的区别
    JRE
    Servlet的生命周期
    页面介绍
    项目技术介绍
    软件开发环境
  • 原文地址:https://www.cnblogs.com/phpdragon/p/10182469.html
Copyright © 2011-2022 走看看