公司新一批服务器,要一台台做初始化很繁琐,写了了shell脚本,给大家参考!
#!/bin/bash 如有问题,请联系我,希望有大家多交流!
#author luoz
#2013-07-01
echo "Welcome to Centos5.5 64 System init!"
#set service
for i in `ls /etc/rc3.d/S* | grep -v local`
do
CURSRV=`echo $i|cut -c 15-`
echo $CURSRV
case $CURSRV in
crond | irqbalance | network | sshd | syslog )
echo "Base services, Skip!"
;;
*)
echo "change $CURSRV to off"
chkconfig --level 235 $CURSRV off
service $CURSRV stop
;;
esac
done
echo "service set OK"
#set tty
sed -i '/^4:2345/s/4:2345/#4:2345/' /etc/inittab
sed -i '/^5:2345/s/5:2345/#5:2345/' /etc/inittab
sed -i '/^6:2345/s/6:2345/#6:2345/' /etc/inittab
/sbin/init q
echo "tty set OK!"
#set ulimit
echo "ulimit -HSn 65535" >> /etc/profile
echo "ulimit -SHn 65535" >> /etc/rc.local
echo "* soft nofile 65535" >> /etc/security/limits.conf
echo "* hard nofile 65535" >> /etc/security/limits.conf
echo "ulimit set OK!"
#set sysctl
cat >> /etc/sysctl.conf <
net.ipv4.tcp_tw_reuse &#61; 1
net.ipv4.tcp_fin_timeout &#61; 30
net.ipv4.tcp_keepalive_time &#61; 1800
net.ipv4.tcp_max_syn_backlog &#61; 4096
net.ipv4.tcp_synCOOKIEs &#61; 1
net.ipv4.icmp_echo_ignore_broadcasts &#61;1
net.ipv4.ip_conntrack_max &#61; 100000
EOF
/sbin/sysctl -p
echo "sysctl set OK!"
#set ssh
ssh_cf&#61;"/etc/ssh/sshd_config"
sed -i &#39;s/#GSSAPIAuthentication no/GSSAPIAuthentication no/&#39; $ssh_ch
sed -i &#39;s/GSSAPIAuthentication yes/#GSSAPIAuthentication yes/&#39; $ssh_ch
sed -i "s/#UseDNS yes/UseDNS no/" $ssh_cf
service sshd restart
echo "ssh set OK!"
#set LANG
true > /etc/sysconfig/i18n
cat >>/etc/sysconfig/i18n<
SYSFONT&#61;"latarcyrheb-sun16"
EOF
echo "LANG set OK!"
#set ntp
echo "* 1 * * * /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1" >> /etc/crontab
chkconfig --level 3 ntpd on
service crond restart
echo "LANG set OK!"
#set dns
echo &#39;nameserver 192.168.30.35&#39; > /etc/resolv.conf
echo &#39;search localdomain&#39; >> /etc/resolv.conf
echo "DNS set OK!"
#set selinux
sed -i &#39;/SELINUX/s/enforcing/disabled/&#39; /etc/selinux/config
echo "selinux set OK!"
#disable ipv6
echo "alias net-pf-10 off" >> /etc/modprobe.conf
echo "alias ipv6 off" >> /etc/modprobe.conf
echo "ipv6 set OK!"