1.更換yum源(這裏使用的阿里源)linux
cd /etc/yum.repos.d tar cf repo_bak_$(date +%Y%m%d).tar.gz ./* rm -rf *.repo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo curl -o /etc/yum.repos.d/epel.repo yum clean all yum makecache
2.安裝必要的安裝包c++
yum install -y gcc cmake gcc-c++ tree lrzsz vim openssl ntpdate sysstat lsof nload wget
3.基本設置vim
時間同步bash
ntpdate cn.ntp.org.cn echo "00 03 * * * root ntpdate cn.ntp.org.cn >> /dev/null 2>&1" >> /etc/crontab
時區設置
cookie
rm -f /etc/localtime cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
系統默認語言
app
cat > /etc/sysconfig/i18n <<EFO LANG="en_US.UTF-8" EFO
啓動級別ssh
sed -i 's/^id:5:/id:3:/' /etc/inittab
開機啓動項curl
LANG=en_US-UTF-8 for sun in `chkconfig --list|grep 3:on|awk '{print $1}'`;do chkconfig --level 3 $sun off;done for sun in crond rsyslog sshd network;do chkconfig --level 3 $sun on;done
打開文件數設置tcp
echo "ulimit -SHn 102400" >> /etc/rc.local cat >> /etc/security/limits.conf <<EFO * soft nofile 65536 * hard nofile 65536 * soft nproc 65536 * hard nproc 65536 EFO
sshd 基礎設置(這裏不設置root禁止登錄以及更換端口,請自行選擇)
ide
sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
vim 基礎設置
echo "syntax on" >> /root/.vimrc echo "set nu" >> /root/.vimrc echo "set ts=4" >> /root/.vimrc
其餘設置
sed -i 's#exec /sbin/shutdown -r now#\#exec /sbin/shutdown -r now#' /etc/init/control-alt-delete.conf sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config cat > /etc/modprobe.d/ipv6.conf << EOFI alias net-pf-10 off options ipv6 disable=1 EOFI
4. kernel優化設置
modprobe ip_conntrack echo "modprobe ip_conntrack" >> /etc/rc.local cp /etc/sysctl.conf{,_bak$(date +%Y%m%d)} cat > /etc/sysctl.conf << EOF net.ipv4.ip_forward = 0 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 kernel.sysrq = 0 kernel.core_uses_pid = 1 kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 68719476736 kernel.shmall = 4294967296 net.ipv4.tcp_max_tw_buckets = 60000 net.ipv4.tcp_sack = 1 net.ipv4.tcp_window_scaling = 1 net.ipv4.tcp_rmem = 4096 87380 4194304 net.ipv4.tcp_wmem = 4096 16384 4194304 net.core.wmem_default = 8388608 net.core.rmem_default = 8388608 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.core.netdev_max_backlog = 500000 net.core.somaxconn = 262144 net.ipv4.tcp_max_orphans = 3276800 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_max_syn_backlog = 262144 net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_synack_retries = 1 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_mem = 94500000 915000000 927000000 net.ipv4.tcp_fin_timeout = 1 net.ipv4.tcp_keepalive_time = 1200 net.ipv4.ip_local_port_range = 1024 65535 net.nf_conntrack_max = 25000000 net.netfilter.nf_conntrack_max = 25000000 net.netfilter.nf_conntrack_tcp_timeout_established = 180 net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120 net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60 net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120 vm.swappiness = 0 EOF /sbin/sysctl -p
5. 刪除沒必要要的用戶和組(可選)
userdel adm userdel lp userdel sync userdel shutdown userdel halt userdel uucp userdel operator userdel games userdel gopher groupdel adm groupdel lp groupdel uucp groupdel games groupdel dip groupdel pppusers groupdel popusers groupdel slipuser
6.設置history 以時間格式顯示,並更改儲存目錄(可選)
將下面內容放在 /etc/profile 文件中,而後從新使用root登錄一次便可。會生成/var/log/.hist目錄/登錄用戶名/登錄源ip.hist.登日期,並只有root可以查看裏面的文件。
#history export HISTTIMEFORMAT="[%Y.%m.%d %H:%M:%S] " USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'` HISTDIR=/var/log/.hist if [ -z $USER_IP ] then USER_IP=`hostname` fi flat=$(who -u am i |grep -c tty) if [ $flat -eq 1 ];then USER_IP="console" fi if [ ! -d $HISTDIR ] then mkdir -p $HISTDIR chmod 777 $HISTDIR fi if [ ! -d $HISTDIR/${LOGNAME} ] then mkdir -p $HISTDIR/${LOGNAME} chmod 300 $HISTDIR/${LOGNAME} fi export HISTSIZE=4096 #DT=`date +%Y%m%d_%H%M%S` DT=$(date +%Y%m%d) export HISTFILE="$HISTDIR/${LOGNAME}/${USER_IP}.hist.$DT" chmod 600 $HISTDIR/${LOGNAME}/*.hist* 2>/dev/null