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