自己参考了系统优化的点,写了一个一键优化脚本,适用于CentOS6.x版本,各个项已经单独进行测试通过。适用于CentOS6.x系统最小化安装执行,可以根据自己的需求进行添加或修改完善。主要优化内容有:关闭系统不必要的服务;关闭selinux,关闭iptables;关闭ctrl+alt+del重启;设置ssh端口,关闭DNS解析;设置系统最大文件描述符;设置系统关键文件权限;配置安装ntp;安装vim;配置安装阿里云yum源和epel源;脚本如下:[root@localhost ~]# cat youhua.sh #!/bin/bash #written by mofansheng@2015-11-03 #system optimization script #The fllow apply to CentOS 6.x . /etc/init.d/functions
function check_ok(){ if [ $? -eq 0 ] then echo "" continue else echo "pls check error" exit fi }
cat<<EOF ----------------------------------------------------------------------- | system optimization | ----------------------------------------------------------------------- EOF
#close unimportant system services echo "===Close unimportant system services,it will take serval mintinues===" for s in `chkconfig --list|grep 3:on|awk "{print $1}"|grep -Ev "crond|sshd|sysstat|rsyslog|network"` do chkconfig $s off done check_ok action "Close unimportant system services" /bin/true
#close selinux echo "===close SELINUX===" if [ `getenforce` != "Disabled" ] then sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config echo "selinux is disabled,you must reboot!" else action "SELINUX is closed" /bin/true fi check_ok action "Close SELINUX" /bin/true