Centos 5.x 系统优化脚本

适用于centos 5系列i386 i686 x86_64

根据别人修改的

 

#!/bin/bash#welcomecat << EOF+--------------------------------------------------------------+|         === Welcome to Centos System init ===                |+--------------------------------------------------------------+EOF#update yum#update system#set ntpyum -y install ntpecho "* 3 * * * /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1" >> /etc/crontabservice crond restart#set ulimitecho "ulimit -SHn 102400" >> /etc/rc.localcat >> /etc/security/limits.conf << EOF*           soft   nofile       65535*           hard   nofile       65535EOF#set locale#true > /etc/sysconfig/i18n#cat >>/etc/sysconfig/i18n<
/etc/sysctl.confcat >> /etc/sysctl.conf << EOFnet.ipv4.ip_forward = 0net.ipv4.conf.default.rp_filter = 1net.ipv4.conf.default.accept_source_route = 0kernel.sysrq = 0kernel.core_uses_pid = 1net.ipv4.tcp_syncookies = 1kernel.msgmnb = 65536kernel.msgmax = 65536kernel.shmmax = 68719476736kernel.shmall = 4294967296net.ipv4.tcp_max_tw_buckets = 6000net.ipv4.tcp_sack = 1net.ipv4.tcp_window_scaling = 1net.ipv4.tcp_rmem = 4096 87380 4194304net.ipv4.tcp_wmem = 4096 16384 4194304net.core.wmem_default = 8388608net.core.rmem_default = 8388608net.core.rmem_max = 16777216net.core.wmem_max = 16777216net.core.netdev_max_backlog = 262144net.core.somaxconn = 262144net.ipv4.tcp_max_orphans = 3276800net.ipv4.tcp_max_syn_backlog = 262144net.ipv4.tcp_timestamps = 0net.ipv4.tcp_synack_retries = 1net.ipv4.tcp_syn_retries = 1net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_mem = 94500000 915000000 927000000net.ipv4.tcp_fin_timeout = 1net.ipv4.tcp_keepalive_time = 1200net.ipv4.ip_local_port_range = 1024 65535EOF/sbin/sysctl -pecho "sysctl set OK!!"#close ctrl+alt+delsed -i "s/ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/" /etc/inittab#set purviewchmod 600 /etc/passwdchmod 600 /etc/shadowchmod 600 /etc/groupchmod 600 /etc/gshadow#disable ipv6cat << EOF+--------------------------------------------------------------+| === Welcome to Disable IPV6 === |+--------------------------------------------------------------+EOFecho "alias net-pf-10 off" >> /etc/modprobe.confecho "alias ipv6 off" >> /etc/modprobe.conf/sbin/chkconfig --level 35 ip6tables offecho "ipv6 is disabled!"#disable selinuxsed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/configecho "selinux is disabled,you must reboot!"#vimsed -i "8 s/^/alias vi='vim'/" /root/.bashrcecho 'syntax on' > /root/.vimrc#zh_cn#sed -i -e 's/^LANG=.*/LANG="en"/' /etc/sysconfig/i18n#init_sshssh_cf="/etc/ssh/sshd_config"sed -i -e '74 s/^/#/' -i -e '76 s/^/#/' $ssh_cfsed -i "s/#Port 22/Port 2222/" $ssh_cfsed -i "s/#UseDNS yes/UseDNS no/" $ssh_cf#clientsed -i -e '44 s/^/#/' -i -e '48 s/^/#/' $ssh_cfservice sshd restartecho "ssh is init is ok.............."#chkser#tunoff services#--------------------------------------------------------------------------------cat << EOF+--------------------------------------------------------------+| === Welcome to Tunoff services === |+--------------------------------------------------------------+EOF#---------------------------------------------------------------------------------for i in `ls /etc/rc3.d/S*`do CURSRV=`echo $i|cut -c 15-`echo $CURSRVcase $CURSRV in crond | irqbalance | microcode_ctl | lvm2-monitor | network | random | sshd | syslog | vmware-tools ) echo "Base services, Skip!" ;; *) echo "change $CURSRV to off" chkconfig --level 235 $CURSRV off service $CURSRV stop ;;esacdoneecho "service is init is ok.............."echo 'HISTTIMEFORMAT="%F %T "' >> /root/.bashrcecho 'export HISTTIMEFORMAT' >> /root/.bashrcsource /root/.bashrc/sbin/iptables -F/etc/init.d/iptables save