[root@myhost001 ~]# free -h
total used free shared buff/cache available
Mem: 974M 433M 66M 8.9M 474M 374M
Swap: 2.0G 107M 1.9G
[root@myhost001 ~]#
sync; echo 3 > /proc/sys/vm/drop_caches 释放包括网页,目录项,索引这3项的内存
[root@myhost001 ~]# echo 3 > /proc/sys/vm/drop_caches
[root@myhost001 ~]#
[root@myhost001 ~]#
[root@myhost001 ~]# free -h
total used free shared buff/cache available
Mem: 974M 414M 484M 8.9M 75M 447M
Swap: 2.0G 107M 1.9G
[root@myhost001 ~]#
那如何使用yum清理缓存呢?清理yum缓存使用yum clean 命令,yum clean 的参数有headers, packages, metadata, dbcache, plugins, expire-cache, rpmdb, all等。
释放内存脚本
freemem.sh
#!/bin/bash
used=`free -m | awk 'NR==2' | awk '{print $3}'`
free=`free -m | awk 'NR==2' | awk '{print $4}'`
echo "===========================" >> /var/log/mem.log
date >> /var/log/mem.log
echo "Memory usage | [Use:${used}MB][Free:${free}MB]" >> /var/log/mem.log
if [ $free -le 1000 ] ; 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" >> /var/log/mem.log
else
echo "Not required" >> /var/log/mem.log
fi
定时任务命令
echo "*/30 * * * * root /home/freemem.sh" >> /etc/crontab
作者:iFreek
链接:https://www.jianshu.com/p/1de44c9bedeb
来源:简书