1 #!/bin/bash 2 #添加epel和rpmforge的外部yum扩展源 3 cd /usr/local/src 4 wget http://mirrors.ustc.edu.cn/fedora/epel//5/x86_64/epel-release-5-4.noarch.rpm 5 rpm -ivh epel-release-5-4.noarch.rpm 6 wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm 7 rpm -ivh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm 8 #安装gcc基础库文件以及sysstat工具 9 yum -y install gcc gcc-c++ vim-enhanced unzip unrar sysstat10 #配置ntpdate自动对时11 yum -y install ntp12 echo "01 01 * * * /usr/sbin/ntpdate ntp.api.bz >> /dev/null 2>&1" >> /etc/crontab13 ntpdate ntp.api.bz14 service crond restart15 #配置文件的ulimit值16 ulimit -SHn 6553517 echo "ulimit -SHn 65535" >> /etc/rc.local18 cat >> /etc/security/limits.conf << EOF19 * soft nofile 6000020 * hard nofile 6553521 EOF22 #tune kernel parametres(基础系统内核优化)23 cat >> /etc/sysctl.conf << EOF24 net.ipv4.tcp_syncookies = 125 net.ipv4.tcp_syn_retries = 126 net.ipv4.tcp_tw_recycle = 127 net.ipv4.tcp_tw_reuse = 128 net.ipv4.tcp_fin_timeout = 129 net.ipv4.tcp_keepalive_time = 120030 net.ipv4.ip_local_port_range = 1024 6553531 EOF32 /sbin/sysctl -p33 #禁用control-alt-delete组合键以防止误操作34 sed -i 's@ca::ctrlaltdel:/sbin/shutdown -t3 -r now@#ca::ctrlaltdel:/sbin/shutdown -t3 -r now@' /etc/inittab35 #关闭SElinux36 sed -i 's@SELINUX=enforcing@SELINUX=disabled@' /etc/selinux/config37 #ssh服务配置优化38 sed -i -e '74 s/^/#/' -i -e '76 s/^/#/' /etc/ssh/sshd_config39 sed -i 's@#UseDNS yes@UseDNS no@' /etc/ssh/sshd_config40 service sshd restart41 #禁用ipv6地址42 echo "alias net-pf-10 off" >> /etc/modprobe.conf43 echo "alias ipv6 off" >> /etc/modprobe.conf44 echo "install ipv6 /bin/true" >> /etc/modprobe.conf45 echo "IPV6INIT=no" >> /etc/sysconfig/network46 sed -i 's@NETWORKING_IPV6=yes@NETWORKING_IPV6=no@' /etc/sysconfig/network47 chkconfig ip6tables off48 #vim基础语法优化49 echo "syntax on" >> /root/.vimrc50 echo "set nohlsearch" >> /root/.vimrc51 #停用系统中不必要的服务52 chkconfig bluetooth off53 chkconfig sendmail off54 chkconfig kudzu off55 chkconfig nfslock off56 chkconfig portmap off57 chkconfig iptables off58 chkconfig autofs off59 chkconfig yum-updatesd off60 #重启服务器61 reboot