Centos 6 一键优化
centos6_optimiz.sh
#!/bin/bash
#author Brandyn(thank you suzezhi)
#this script is only for CentOS 6
#Centos 6 optimization onkey
platform=`uname -i`
if [ $platform != "x86_64" ];then
echo "this script is only for 64bit Operating System !"
exit 1
fi
echo "the platform is ok"
#create base dir
mkdir /app /data/ /app/scripts
#clean OS default repo
mkdir /etc/yum.repos.d/old && mv /etc/yum.repos.d/C* /etc/yum.repos.d/old/
#add local repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
#rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
#rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm</a>
#update the system and set the ntp
yum clean all
#yum -y update glibc\*
#yum -y update yum\* rpm\* python\*
yum -y update
yum -y install ntp lrzsz tree telnet dos2unix sysstat sysstat iptraf ncurses-devel openssl-devel zlib-devel OpenIPMI-tools nmap screen
echo "* 4 * * * /usr/sbin/ntpdate 202.120.2.101 > /dev/null 2>&1" >> /var/spool/cron/root
service crond restart
#crond clean mail file
echo "find /var/spool/clientmqueue/ -type f -mtime +30 |xargs rm -f" > /app/scripts/del_clientmqueue.sh
chmod +x /app/scripts/del_clientmqueue.sh
echo "00 00 * * 6 /bin/sh /server/scripts/del_clientmqueue.sh >/dev/null 2>&1" >> /var/spool/cron/root
#update system character
cp /etc/sysconfig/i18n /etc/sysconfig/i18n.Brandyn
echo 'LANG="en_US.UTF-8"' >/etc/sysconfig/i18n
source /etc/sysconfig/i18n
#add default user
useradd ding -u 2017
echo 'ding@)!&' | passwd --stdin ding && history -c
#set sudo authority
echo "" >> /etc/sudoers
echo "#set sudo authority" >> /etc/sudoers
echo "ding ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
#set the file limit
echo "ulimit -SHn 102400" >> /etc/rc.local
cat >> /etc/security/limits.conf << EOF
* soft nofile 65535
* hard nofile 65535
EOF
#set the control-alt-delete to guard against the miSUSE
mv /etc/init/control-alt-delete.conf /etc/init/control-alt-delete.conf.bak
#disable selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
#set
LANG=en
for chkoff in `chkconfig --list|grep 3:on|awk '{print $1}'`;do chkconfig --level 3 $chkoff off;done
for chkoff in crond network rsyslog sshd;do chkconfig --level 3 $chkoff on;done
#set ssh
\cp /etc/ssh/sshd_config /etc/ssh/sshd_config.`date +"%Y-%m-%d_%H-%M-%S"`
sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
sed -i 's%#PermitRootLogin yes%PermitRootLogin no%g' /etc/ssh/sshd_config
sed -i 's%#PermitEmptyPasswords no%PermitEmptyPasswords no%g' /etc/ssh/sshd_config
#sed -i 's%#Port 22%Port 52020%g' /etc/ssh/sshd_config
service sshd restart
#tune kernel parametres
cat >> /etc/sysctl.conf << EOF
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
EOF
/sbin/sysctl -p
#disable the ipv6
#cat > /etc/modprobe.d/ipv6.conf << EOF
#alias net-pf-10 off
#options ipv6 disable=1
#EOF
#echo "NETWORKING_IPV6=off" >> /etc/sysconfig/network
#modify PS1
echo 'export PS1="[ \033[01;33m\u\033[0;36m@\033[01;34m\h \033[01;31m\w\033[0m ]\033[0m \n#"' >> /etc/profile
echo "the platform is ok"