54SA.COM|专注于系统亚博体育官方网址管理,为中国SA提供动力!
当前位置: 主页 > Linux > Linux编程 > Shell编程 >

Linux服务器初始化优化Shell脚本

时间:2011-08-10 15:07来源:未知 编辑:admin

??????? Linux服务器系统刚安装好,需要做一些初始化的设置,例如:关闭ipv6模块、关闭selinux、让vim显示颜色、设置系统语言编码、优化系统服务、内核参数优化等。以下Shell脚本将实现这些功能,具体可根据实际情况修改,可在生产环境中使用。

  1. #!/bin/sh ?
  2. #?desc:?lsm03624?modified?by?www.webnginx.com ?
  3. #-------------------cut?begin------------------------------------------- ?
  4. #welcome ?
  5. cat?<
  6. +--------------------------------------------------------------+ ?
  7. |?===?Welcome?to?Centos?System?init?===?| ?
  8. +--------------http://www.linuxtone.org------------------------+ ?
  9. +----------------------Author:NetSeek--------------------------+ ?
  10. EOF ?
  11. #disable?ipv6 ?
  12. cat?<
  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. ?
  22. #disable?selinux ?
  23. sed?-i?'/SELINUX/s/enforcing/disabled/'?/etc/selinux/config ?
  24. echo?"selinux?is?disabled,you?must?reboot!"?
  25. ?
  26. #vim ?
  27. sed?-i?"8?s/^/alias?vi='vim'/"?/root/.bashrc ?
  28. echo?'syntax?on'?>?/root/.vimrc ?
  29. ?
  30. #zh_cn ?
  31. sed?-i?-e?'s/^LANG=.*/LANG="zh_CN.UTF-8"/'?/etc/sysconfig/i18n ?
  32. #?configure?file?max?to?52100 ?
  33. echo?"*?soft?nofile?52100 ?
  34. *?hard?nofile?52100"?>>?/etc/security/limits.conf ?
  35. ?
  36. #tunoff?services ?
  37. #-------------------------------------------------------------------------------- ?
  38. cat?<
  39. +--------------------------------------------------------------+ ?
  40. |?===?Welcome?to?Tunoff?services?===?| ?
  41. +--------------------------------------------------------------+ ?
  42. EOF ?
  43. #--------------------------------------------------------------------------------- ?
  44. for?i?in?`ls?/etc/rc3.d/S*` ?
  45. do?
  46. CURSRV=`echo?$i|cut?-c?15-` ?
  47. ?
  48. echo?$CURSRV?
  49. case?$CURSRV?in ?
  50. cpuspeed?|?crond?|?irqbalance?|?microcode_ctl?|?mysqld?|?network?
    |?nginx?|?php-fpm?|?sendmail?|?sshd?|?syslog?) ?
  51. #这个启动的系统服务根据具体的应用情况设置,其中network、sshd、syslog是三项必须要启动的系统服务! ?
  52. echo?"Base?services,?Skip!"?
  53. ;; ?
  54. *) ?
  55. echo?"change?$CURSRV?to?off"?
  56. chkconfig?--level?235?$CURSRV?off ?
  57. service?$CURSRV?stop ?
  58. ;; ?
  59. esac ?
  60. done ?
  61. ?
  62. rm?-rf?/etc/sysctl.conf ?
  63. echo?"net.ipv4.ip_forward?=?0 ?
  64. net.ipv4.conf.default.rp_filter?=?1 ?
  65. net.ipv4.conf.default.accept_source_route?=?0 ?
  66. kernel.sysrq?=?0 ?
  67. kernel.core_uses_pid?=?1 ?
  68. net.ipv4.tcp_syncookies?=?1 ?
  69. kernel.msgmnb?=?65536 ?
  70. kernel.msgmax?=?65536 ?
  71. kernel.shmmax?=?68719476736 ?
  72. kernel.shmall?=?134217728 ?
  73. net.ipv4.ip_local_port_range?=?1024?65536 ?
  74. net.core.rmem_max?=?16777216 ?
  75. net.core.wmem_max?=?16777216 ?
  76. net.ipv4.tcp_rmem?=?4096?87380?16777216 ?
  77. net.ipv4.tcp_wmem?=?4096?65536?16777216 ?
  78. net.ipv4.tcp_fin_timeout?=?3 ?
  79. net.ipv4.tcp_tw_recycle?=?1 ?
  80. net.core.netdev_max_backlog?=?30000 ?
  81. net.ipv4.tcp_no_metrics_save?=?1 ?
  82. net.core.somaxconn?=?262144 ?
  83. net.ipv4.tcp_syncookies?=?0 ?
  84. net.ipv4.tcp_max_orphans?=?262144 ?
  85. net.ipv4.tcp_max_syn_backlog?=?262144 ?
  86. net.ipv4.tcp_synack_retries?=?2 ?
  87. net.ipv4.tcp_syn_retries?=?2 ?
  88. vm.swappiness?=?6"?>>?/etc/sysctl.conf ?
  89. echo?"optimizited?kernel?configure?was?done!"?

?

[责任编辑:admin]

------分隔线----------------------------