1. 不用root,添加普通用户,通过sudo授权管理
visudo
输入内容:tangyong ALL=(ALL) /usr/sbin/useradd

2.优化SSH服务
vim /etc/ssh/sshd_config

Port 52113                              
ListenAddress 0.0.0.0          
PermitRootLogin no              
PermitEmptyPasswords no     
UseDNS no                    <- 是否进行DNS反向解析(提升ssh远程连接效率)    
GSSAPIAuthentication no      <- 是否进行远程GSSAPI认证(提升ssh远程连接效率)

/etc/init.d/sshd restart
3.定时更新服务器时间
echo '#time sync by tangyong at 2017-03-08' >>/var/spool/cron/root
echo '/5 * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1' >>/var/spool/cron/root
crontab -l
4.配置yum更新源,从国内更新源下载安装ypm包
备份: mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
下载:
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

最后一步生产缓存: yum makecache
5.关闭selinux及iptables(iptables工作场景如果有wan ip一般要打开,高并发除外)
临时关闭selinux setenforce 0
永久关闭selinux sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
/etc/init.d/iptables stop
chkconfig iptables off
6.调整文件描述符的数量,进程及打开文件会消耗文件描述符
临时调整 ulimit -HSn 65535
永久调整 echo '* - nofile 65535'>>/etc/security/limits.conf
7.定时自动清理/var/spool/clientmquene/目录垃圾文件,防止inodes节点被占满(c6.4没有sendmail,因此可以不配置)
8.精简开机自启动服务(crond,sshd,network,rsyslog,sysstat)(注:c5.8 syslog)
chkconfig|egrep -v "crond|sshd|network|rsyslog|sysstat"|awk '{print "chkconfig",$1,"off"}'|bash
chkconfig --list|grep 3:on
9.linux内核参数优化/etc/sysctl.conf,sysctl -p 生效
#内核优化
cat >>/etc/sysctl.conf<net.ipv4.tcp_fin_timeout = 2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_keepalive_time = 600
net.ipv4.ip_local_port_range = 4000 65000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.route.gc_timeout = 100
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.core.somaxconn = 16384
net.core.netdev_max_backlog = 16384
net.ipv4.tcp_max_orphans = 16384
#以下参数是对iptables防火墙的优化,防火墙不开会提示,可以忽略不理。
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
EOF
sysctl -p
10.更换字符集,支持中文,但建议用英文字符集,防止乱码问题
cp /etc/sysconfig/i18n /etc/sysconfig/i18n.ori
echo 'LANG="en_US.UTF-8"' >/etc/sysconfig/i18n
source /etc/sysconfig/i18n
echo $LANG
11.锁定关键系统文件
chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/inittable
12.清空/etc/issue,去除系统内核版本登录前的屏幕显示
\>/etc/issue
13.安装其他小软件
yum install lrzsz nmap tree dos2unix nc telnet sl -y