#!/bin/bash
# Program: 对CentOS 6.x的优化配置脚本
# Date: 2016-2-25
# Author: uangianlap
# Version: 1.0
. /etc/init.d/functions

# 关闭selinux
setenforce 0 && sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
action "关闭selinux成功" /bin/true

# 关闭防火墙
iptables -F &> /dev/null  && /etc/init.d/iptables stop &> /dev/null && chkconfig iptables off
action "关闭防火墙成功" /bin/true

# 设置中文显示
cp /etc/sysconfig/i18n{,.ori}
echo 'LANG="zh_CN.UTF-8"' > /etc/sysconfig/i18n
source /etc/sysconfig/i18n
action "设置中文显示成功" /bin/true

# 只保留有限几个开机自启动服务
for name in sshd network rsyslog crond sysstat;do chkconfig --add $name && chkconfig $name on;done

for name in `chkconfig --list| awk '{print $1}' | grep -Ev "sshd|network|rsyslog|crond|sysstat"`;do chkconfig $name off;done
action "开机自启动服务优化成功" /bin/true

# 增大文件描述符
ulimit -SHn 65535
echo "ulimit -SHn 65535" >> /etc/rc.local
action "增大文件描述符成功" /bin/true

# 修改history记录个数及显示格式
sed -i "s/HISTSIZE=1000/HISTSIZE=100/" /etc/profile
source /etc/profile

echo 'export HISTTIMEFORMAT="%F %T `whoami`  "' >> /etc/rc.local
source /etc/rc.local
action "History优化成功" /bin/true

# 同步时间
if (yum list installed | grep ntpdate &> /dev/null) && ! (crontab -l | grep "sync time" &> /dev/null);then
    echo "#sync time via internet" >> /var/spool/cron/root
    echo "00 06 * * * /usr/sbin/ntpdate 202.120.2.101 &> /dev/null" >> /var/spool/cron/root
fi
action "时间同步添加成功" /bin/true

https://www.jianshu.com/p/bd8f115fe347