系统初始化SHELL脚本推荐

此脚本用于新装CentOS的相关配置工作,比如禁掉iptable和SElinux及ipv6,优化系统内核,停掉一些没必要启动的系统服务等。此脚本尤其适全大批新安装的CentOS 5.X系列的服务器,脚本代码如下所示(此脚本在Centos5.5_x64下已通过):

#!/bin/bash# Created by kerryhu# MAIL:king_819@163.com# BLOG:http://kerry.blog.51cto.comcat EOF+--------------------------------------------------------------+| === Welcome to Centos System init === |+--------------------------------------------------------------++--------------------------by kerry----------------------------+#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.local#set locale#true /etc/sysconfig/i18n#cat /etc/sysconfig/i18n EOF#LANG="zh_CN.GB18030"#SUPPORTED="zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en"#SYSFONT="latarcyrheb-sun16"#set sysctltrue /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 65535/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 === |+--------------------------------------------------------------+echo "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!"sed -i "8 s/^/alias vi='vim'/" /root/.bashrcecho 'syntax on' /root/.vimrc#zh_cnsed -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_cf#sed -i "s/#Port 22/Port 65535/" $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 === |+--------------------------------------------------------------+#---------------------------------------------------------------------------------for i in `ls /etc/rc3.d/S*` CURSRV=`echo $i|cut -c 15-`echo $CURSRVcase $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 stopecho "service is init is ok.............."

看着它洗涤一缕缕阳光,看着它映衬一片片星辉,

系统初始化SHELL脚本推荐

相关文章:

你感兴趣的文章:

标签云: