服務器最小化安裝後的優化腳本,此腳本在CentOS[5.5-5.8] x86_64系統下測試均順利通過, 由於現在Linux服務器系統都是採用Kickstart批量安裝的方式,此腳本可以由Puppet服務器推送執行,腳本內容如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #/bin/bash #添加epel和rpmforge的外部yum擴展源 cd /usr/local/src wget http: //mirrors .ustc.edu.cn /fedora/epel//5/x86_64/epel-release-5-4 .noarch.rpm rpm -ivh epel-release-5-4.noarch.rpm wget http: //packages .sw.be /rpmforge-release/rpmforge-release-0 .5.2-2.el5.rf.x86_64.rpm rpm -ivh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm #安裝gcc基礎庫文件以及sysstat工具 yum -y install gcc gcc-c++ vim-enhanced unzip unrar sysstat #配置ntpdate自動對時 yum -y install ntp echo "01 01 * * * /usr/sbin/ntpdate ntp.api.bz >> /dev/null 2>&1" >> /etc/crontab ntpdate ntp.api.bz service crond restart #配置文件的ulimit值 ulimit -SHn 65535 echo "ulimit -SHn 65535" >> /etc/rc . local cat >> /etc/security/limits .conf << EOF * soft nofile 60000 * hard nofile 65535 EOF #tune kernel parametres(基礎系統內核優化) cat >> /etc/sysctl .conf << EOF net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_fin_timeout = 1 net.ipv4.tcp_keepalive_time = 1200 net.ipv4.ip_local_port_range = 1024 65535 EOF /sbin/sysctl -p #禁用control-alt-delete組合鍵以防止誤操作 sed -i 's@ca::ctrlaltdel:/sbin/shutdown -t3 -r now@#ca::ctrlaltdel:/sbin/shutdown -t3 -r now@' /etc/inittab #關閉SElinux sed -i 's@SELINUX=enforcing@SELINUX=disabled@' /etc/selinux/config #ssh服務配置優化 sed -i -e '74 s/^/#/' -i -e '76 s/^/#/' /etc/ssh/sshd_config sed -i 's@#UseDNS yes@UseDNS no@' /etc/ssh/sshd_config service sshd restart #禁用ipv6地址 echo "alias net-pf-10 off" >> /etc/modprobe .conf echo "alias ipv6 off" >> /etc/modprobe .conf echo "install ipv6 /bin/true" >> /etc/modprobe .conf echo "IPV6INIT=no" >> /etc/sysconfig/network sed -i 's@NETWORKING_IPV6=yes@NETWORKING_IPV6=no@' /etc/sysconfig/network chkconfig ip6tables off #vim基礎語法優化 echo "syntax on" >> /root/ .vimrc echo "set nohlsearch" >> /root/ .vimrc #停用系統中不必要的服務 chkconfig bluetooth off chkconfig sendmail off chkconfig kudzu off chkconfig nfslock off chkconfig portmap off chkconfig iptables off chkconfig autofs off chkconfig yum-updatesd off #重啓服務器 reboot |
腳本重點部分說明:
tune kernel parametres爲系統內核優化部分,在這裏我只做了基礎處理,大家有需求可以自行修改,記住:一切以系統穩定爲原則。
vim優化部分爲vim的個性化配置,如果想vim語法高亮,則必須安裝vim-enhanced包,另外,vim在使用搜索功能,搜索選中內容爲高亮,感覺不是特別舒服,所以我這裏用了set nohlsearch選項,如果大家不介意此項功能,則不需要添加此語句;
disable ipv6選項我在測試時發現,在CentOS5.8 x86_64系統下,如果不添加install ipv6 /bin/true此語句到/etc/modprobe.conf文件裏,是關閉不了ipv6選項的,而測試的CentOS{5.5,5,6} x86_64系統不添加此句均可以順利關閉ipv6,這點請大家注意下。
本文出自 “撫琴煮酒” 博客,請務必保留此出處http://andrewyu.blog.51cto.com/1604432/1305257