1. 程式人生 > >centos下簡單的優化內存的方法

centos下簡單的優化內存的方法

centos 優化內存

使用sync命令將所有未寫的系統緩存區write to disk,包含已修改的i node、已延遲的塊I\O和讀寫映射
sync
cat /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches[可以將3修改為別的 1清空頁緩存 2清空inode和目錄樹緩存 3清空所有的緩存]
清理tmp命令:
find /tmp/ -name "p*" | xargs rm -rf
yum -y install crontabs
修改etc/crontab文件為以下
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat

# | | | | |
# * * * * * user-name command to be executed
10 * * * * root echo 3 > /proc/sys/vm/drop_caches
10 1 * * * root find /tmp/ -name "p*" | xargs rm -rf


設置每天清理一次tmp文件夾
修改/etc/cron.daily/tmpwatch[30d修改為1d]
#! /bin/sh
flags=-umc
/usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \

-x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \
-X '/tmp/hsperfdata_*' 10d /tmp
/usr/sbin/tmpwatch "$flags" 10d /var/tmp
for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
if [ -d "$d" ]; then
/usr/sbin/tmpwatch "$flags" -f 10d "$d"
fi
done

centos下簡單的優化內存的方法