2011年5月20日星期五

Linux 基本系统初始化脚本第一版

继续共享线上脚本,本脚本主要用于新装linux系统初始化工作。

  1. #!/bin/sh
  2. # desc: coralzd modified by www.freebsdsystem.org www.linuxtone.org
  3. #-------------------cut begin-------------------------------------------
  4. #welcome
  5. cat << EOF
  6. +--------------------------------------------------------------+
  7. | === Welcome to Centos System init === |
  8. +--------------http://www.linuxtone.org------------------------+
  9. +----------------------Author:NetSeek--------------------------+
  10. EOF
  11. #disable ipv6
  12. cat << EOF
  13. +--------------------------------------------------------------+
  14. | === Welcome to Disable IPV6 === |
  15. +--------------------------------------------------------------+
  16. EOF
  17. echo "alias net-pf-10 off" >> /etc/modprobe.conf
  18. echo "alias ipv6 off" >> /etc/modprobe.conf
  19. /sbin/chkconfig --level 35 ip6tables off
  20. echo "ipv6 is disabled!"
  21. #disable selinux
  22. sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
  23. echo "selinux is disabled,you must reboot!"
  24. #vim
  25. sed -i "8 s/^/alias vi='vim'/" /root/.bashrc
  26. echo 'syntax on' > /root/.vimrc
  27. #zh_cn
  28. sed -i -e 's/^LANG=.*/LANG="zh_CN.UTF-8"/' /etc/sysconfig/i18n
  29. # configure file max to 52100
  30. echo "* soft nofile 52100
  31. * soft nofile 52100" >> /etc/security/limits.conf
  32. #tunoff services
  33. #--------------------------------------------------------------------------------
  34. cat << EOF
  35. +--------------------------------------------------------------+
  36. | === Welcome to Tunoff services === |
  37. +--------------------------------------------------------------+
  38. EOF
  39. #---------------------------------------------------------------------------------
  40. for i in `ls /etc/rc3.d/S*`
  41. do
  42. CURSRV=`echo $i|cut -c 15-`
  43. echo $CURSRV
  44. case $CURSRV in
  45. crond | irqbalance | microcode_ctl | network | random | sendmail | sshd | syslog | local | mysqld )
  46. echo "Base services, Skip!"
  47. ;;
  48. *)
  49. echo "change $CURSRV to off"
  50. chkconfig --level 235 $CURSRV off
  51. service $CURSRV stop
  52. ;;
  53. esac
  54. done
  55. rm -rf /etc/sysctl.conf
  56. echo "net.ipv4.ip_forward = 0
  57. net.ipv4.conf.default.rp_filter = 1
  58. net.ipv4.conf.default.accept_source_route = 0
  59. kernel.sysrq = 0
  60. kernel.core_uses_pid = 1
  61. net.ipv4.tcp_syncookies = 1
  62. kernel.msgmnb = 65536
  63. kernel.msgmax = 65536
  64. kernel.shmmax = 68719476736
  65. kernel.shmall = 134217728
  66. net.ipv4.ip_local_port_range = 1024 65536
  67. net.core.rmem_max = 16777216
  68. net.core.wmem_max = 16777216
  69. net.ipv4.tcp_rmem = 4096 87380 16777216
  70. net.ipv4.tcp_wmem = 4096 65536 16777216
  71. net.ipv4.tcp_fin_timeout = 3
  72. net.ipv4.tcp_tw_recycle = 1
  73. net.core.netdev_max_backlog = 30000
  74. net.ipv4.tcp_no_metrics_save = 1
  75. net.core.somaxconn = 262144
  76. net.ipv4.tcp_syncookies = 0
  77. net.ipv4.tcp_max_orphans = 262144
  78. net.ipv4.tcp_max_syn_backlog = 262144
  79. net.ipv4.tcp_synack_retries = 2
  80. net.ipv4.tcp_syn_retries = 2
  81. vm.swappiness = 3" >> /etc/sysctl.conf
  82. echo "optimizited kernel configure was done!"