Linux生产服务器在部署应用程序前,都要对系统进行优化,没用的进程服务该关的关掉,一些基本的开发软件都要装上,避免在安装程序的时候因缺少必要的包而不能编译通过,很是麻烦。以下脚本是作者平常工作中积累的一些优化集合,写的很龊,请大家多多包涵。。
#!/bin/bash
lang=`expr substr "$LANG" 1 5`
if [ $lang = "zh_CN" ]; then
status='启用'
else
status='on'
fi
array=(acpid anacron cpuspeed crond network sshd syslog yum-updatesd)
for shname in `chkconfig --list |grep "3:$status" |awk '{print $1}'`
do
if [[ !("${array[@]}" =~ "$shname") ]]; then
echo chkconfig $shname off
echo `service $shname stop`
echo `chkconfig $shname off`
fi
done
#Set timezone
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yum install -y ntp
ntpdate -u pool.ntp.org
date
#Disable SeLinux
if [ -s /etc/selinux/config ]; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
fi
for packages in patch make gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal nano fonts-chinese gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap;
do yum -y install $packages; done
cat >>/etc/security/limits.conf<<eof
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
eof
cat >>/etc/sysctl.conf<<eof
fs.file-max=65535
eof