此脚本出自http://kerry.blog.51cto.com/ 很实用!
- #!/bin/bash
- #CentOS System init script!!!
- cat << EOF
- +--------------------------------------------------------------+
- | === Welcome to Centos System init === |
- +--------------------------------------------------------------+
- EOF
- #同步时间
- yum -y install ntp
- ntpdate asia.pool.ntp.org
- echo "* 3 * * * /usr/sbin/ntpdate asia.pool.ntp.org > /dev/null 2>&1" >> /etc/crontab
- service crond restart
- #设置 ulimit
- echo "ulimit -SHn 102400" >> /etc/rc.local
- #close ctrl+alt+del
- sed -i "s/ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/" /etc/inittab
- #设置用户权限安全
- #chmod 600 /etc/passwd
- #chmod 600 /etc/shadow
- #chmod 600 /etc/group
- #chmod 600 /etc/gshadow
- #禁用IPV6
- echo "alias net-pf-10 off" >> /etc/modprobe.conf
- echo "alias ipv6 off" >> /etc/modprobe.conf
- /sbin/chkconfig --level 35 ip6tables off
- echo "ipv6 is disabled!"
- #禁用SElinux
- sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
- echo "selinux is disabled,you must reboot!"
- #vim
- sed -i "8 s/^/alias vi='vim'/" /root/.bashrc
- echo 'syntax on' > /root/.vimrc
- #zh_cn
- sed -i -e 's/^LANG=.*/LANG="zh_CN.UTF-8"/' /etc/sysconfig/i18n
- #设置SSH
- ssh_cf="/etc/ssh/sshd_config"
- sed -i -e '74 s/^/#/' -i -e '76 s/^/#/' $ssh_cf
- #sed -i "s/#Port 22/Port 65535/" $ssh_cf
- sed -i "s/#UseDNS yes/UseDNS no/" $ssh_cf
- #client
- sed -i -e '44 s/^/#/' -i -e '48 s/^/#/' $ssh_cf
- service sshd restart
- echo "ssh is init is ok.............."
- #chkser
- #关掉不必要的服务
- #--------------------------------------------------------------------------------
- cat << EOF
- +--------------------------------------------------------------+
- | === Welcome to Tunoff services === |
- +--------------------------------------------------------------+
- EOF
- #---------------------------------------------------------------------------------
- for i in `ls /etc/rc3.d/S*`
- do
- CURSRV=`echo $i|cut -c 15-`
- echo $CURSRV
- case $CURSRV in
- crond | irqbalance | microcode_ctl | network | random | sshd | syslog | local )
- echo "Base services, Skip!"
- ;;
- *)
- echo "change $CURSRV to off"
- chkconfig --level 235 $CURSRV off
- service $CURSRV stop
- ;;
- esac
- done
- echo "service is init is ok.............."