小内存Centos VPS使用注意事项

小内存的VPS(尤为是Centos)在进行相似于Yum操做的时候会耗费大量的内存(相对于VPS的128MB或者更小的内存来讲),因此就要禁用一些没必要要的服务或者yum的插件。建议128MB内存的VPS用户最好用Deiban系统。 php

1 禁用Yum fastestmirror插件

Yum的fastestmirror插件可以帮助VPS找到最快的源,提升yum下载速度,不过占用内存也很夸张,听说能有100MB+!已经的命令能禁用fastestmirror插件: mysql

sed -i -e 's/enabled=1/enabled=0/'  /etc/yum/pluginconf.d/fastestmirror.conf

2 禁用yum的filesystem

对VPS而言,filesystem是母机的事情,因此禁用yum检查filesystem也能节省一部份内存: nginx

echo "exclude=filesystem" >> /etc/yum.conf

3 禁用不经常使用的服务启动

相似于windows的开机启动,不少Linux服务也会开机启动,在小内存的VPS上能够把不是必须的服务禁用,能节省下很大部份内存: sql

chkconfig --list| awk '{system("chkconfig "$1" off")}'
chkconfig --list| awk '{if($1=="crond" ||  $1=="network"  ||  $1=="sshd"  \
||  $1=="nginx"  ||  $1=="php-fpm"  ||  $1=="mysqld"  ||  $1=="pptpd" \
||  $1=="syslogd") system("chkconfig "$1" on")}'

整合脚本

把下面的shell脚本复制到ssh终端中,运行后重启VPS,你就会发现VPS占用的内存大大减小了。 shell

chkconfig --list| awk '{system("chkconfig "$1" off")}' chkconfig --list| awk '{if($1=="crond" || $1=="network" || $1=="sshd" \ || $1=="nginx" || $1=="php-fpm" || $1=="mysqld" || $1=="pptpd" \ || $1=="syslogd") system("chkconfig "$1" on")}' echo "exclude=filesystem" >> /etc/yum.conf sed -i -e 's/enabled=1/enabled=0/' /etc/yum/pluginconf.d/fastestmirror.con
f
相关文章
相关标签/搜索