此脚本出自http://kerry.blog.51cto.com/   很实用!

  1. #!/bin/bash  
  2. #CentOS System init script!!!  
  3.   
  4. cat << EOF  
  5. +--------------------------------------------------------------+  
  6. |         === Welcome to Centos System init ===                |  
  7. +--------------------------------------------------------------+  
  8. EOF  
  9.   
  10. #同步时间  
  11. yum -y install ntp  
  12. ntpdate asia.pool.ntp.org  
  13. echo "* 3 * * * /usr/sbin/ntpdate asia.pool.ntp.org > /dev/null 2>&1" >> /etc/crontab  
  14. service crond restart  
  15. #设置 ulimit  
  16. echo "ulimit -SHn 102400" >> /etc/rc.local  
  17. #close ctrl+alt+del  
  18. sed -i "s/ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/" /etc/inittab  
  19. #设置用户权限安全  
  20. #chmod 600 /etc/passwd  
  21. #chmod 600 /etc/shadow  
  22. #chmod 600 /etc/group  
  23. #chmod 600 /etc/gshadow  
  24.   
  25. #禁用IPV6  
  26. echo "alias net-pf-10 off" >> /etc/modprobe.conf  
  27. echo "alias ipv6 off" >> /etc/modprobe.conf  
  28. /sbin/chkconfig --level 35 ip6tables off  
  29. echo "ipv6 is disabled!"  
  30. #禁用SElinux  
  31. sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config  
  32. echo "selinux is disabled,you must reboot!"  
  33. #vim  
  34. sed -i "8 s/^/alias vi='vim'/" /root/.bashrc  
  35. echo 'syntax on' > /root/.vimrc  
  36. #zh_cn  
  37. sed -i -e 's/^LANG=.*/LANG="zh_CN.UTF-8"/'   /etc/sysconfig/i18n  
  38. #设置SSH  
  39. ssh_cf="/etc/ssh/sshd_config"  
  40. sed -i -e '74 s/^/#/' -i -e '76 s/^/#/' $ssh_cf  
  41. #sed -i "s/#Port 22/Port 65535/" $ssh_cf  
  42. sed -i "s/#UseDNS yes/UseDNS no/" $ssh_cf  
  43. #client  
  44. sed -i -e '44 s/^/#/' -i -e '48 s/^/#/' $ssh_cf  
  45. service sshd restart  
  46. echo "ssh is init is ok.............."  
  47.   
  48. #chkser  
  49. #关掉不必要的服务  
  50. #--------------------------------------------------------------------------------  
  51. cat << EOF  
  52. +--------------------------------------------------------------+  
  53. |         === Welcome to Tunoff services ===                   |  
  54. +--------------------------------------------------------------+  
  55. EOF  
  56. #---------------------------------------------------------------------------------  
  57. for i in `ls /etc/rc3.d/S*`  
  58. do  
  59.               CURSRV=`echo $i|cut -c 15-`  
  60. echo $CURSRV  
  61. case $CURSRV in  
  62.           crond | irqbalance | microcode_ctl | network | random | sshd | syslog | local )  
  63.       echo "Base services, Skip!"  
  64.       ;;  
  65.       *)  
  66.           echo "change $CURSRV to off"  
  67.           chkconfig --level 235 $CURSRV off  
  68.           service $CURSRV stop  
  69.       ;;  
  70. esac  
  71. done  
  72. echo "service is init is ok.............."