基础优化:1、规范目录mkdir -p /server/toolsmkdir -p /server/scripts2、配置所有主机域名解析cat >/etc/hosts<<EOF127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6172.16.1.5 lb01172.16.1.6 lb02172.16.1.7 web01172.16.1.8 web02172.16.1.9 web03172.16.1.31 nfs01172.16.1.41 backup172.16.1.51 db01 db01.etiantian.org172.16.1.61 m01EOF[root@oldboyedu ~]# cat /etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6172.16.1.5 lb01172.16.1.6 lb02172.16.1.7 web01172.16.1.8 web02172.16.1.9 web03172.16.1.31 nfs01172.16.1.41 backup172.16.1.51 db01 db01.etiantian.org172.16.1.61 m01[root@oldboyedu ~]# ping lb01PING lb01 (172.16.1.5) 56(84) bytes of data.3.基础优化操作项:更新yum源信息第一个:就近使用yum源地址,安装软件更快。curl -s -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo第二个:安装RHEL/CentOS官方源不提供的软件包curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo4、安全优化# 1、关闭selinuxsed -i 's#SELINUX=.*#SELINUX=disabled#g' /etc/selinux/configsed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/configgrep SELINUX=disabled /etc/selinux/configsetenforce 0getenforce# 2、关闭firewalld防火墙服务systemctl stop firewalldsystemctl disable firewalld5.基础优化操作项:设置普通用户提权操作(可选优化)# 提权oldboy可以利用sudouseradd oldboyecho 123456|passwd --stdin oldboy\cp /etc/sudoers /etc/sudoers.oriecho "oldboy ALL=(ALL) NOPASSWD: ALL " >>/etc/sudoerstail -1 /etc/sudoersvisudo -c6.设置系统中文UTF8字符集[root@oldboyedu ~]# cat /etc/locale.confLANG="en_US.UTF-8"修改命令如下:cp /etc/locale.conf /etc/locale.conf.oriecho 'LANG="zh_CN.UTF-8"' >/etc/locale.conf source /etc/locale.confecho $LANGcp /etc/locale.conf /etc/locale.conf.orilocalectl set-locale LANG="zh_CN.UTF-8"cat /etc/locale.conf7.基础优化操作项:时间同步设置# 设置系统时间同步yum install ntpdate -y/usr/sbin/ntpdate ntp3.aliyun.comecho '#crond-id-001:time sync by oldboy' >>/var/spool/cron/rootecho "*/5 * * * * /usr/sbin/ntpdate ntp3.aliyun.com >/dev/null 2>&1">>/var/spool/cron/rootcrontab -l8.基础优化操作项:提升命令行操作安全性(可选优化)# 提升命令行安全(可选配置)echo 'export TMOUT=300' >>/etc/profileecho 'export HISTSIZE=5' >>/etc/profileecho 'export HISTFILESIZE=5' >>/etc/profiletail -3 /etc/profile. /etc/profile9.基础优化操作项:加大文件描述符# 实例演示:加大文件描述echo '* - nofile 65535 ' >>/etc/security/limits.conftail -1 /etc/security/limits.confulimit -SHn 65535ulimit -n #<==命令方式查看配置结果10.基础优化操作项:优化系统内核cat >>/etc/sysctl.conf<<EOFnet.ipv4.tcp_fin_timeout = 2net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_syncookies = 1net.ipv4.tcp_keepalive_time = 600net.ipv4.ip_local_port_range = 4000 65000net.ipv4.tcp_max_syn_backlog = 16384net.ipv4.tcp_max_tw_buckets = 36000net.ipv4.route.gc_timeout = 100net.ipv4.tcp_syn_retries = 1net.ipv4.tcp_synack_retries = 1net.core.somaxconn = 16384net.core.netdev_max_backlog = 16384net.ipv4.tcp_max_orphans = 16384#以下参数是对iptables防火墙的优化,防火墙不开会提示,可以忽略不理。net.nf_conntrack_max = 25000000net.netfilter.nf_conntrack_max = 25000000net.netfilter.nf_conntrack_tcp_timeout_established = 180net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120net.core.wmem_default = 8388608net.core.rmem_default = 8388608net.core.wmem_max = 16777216net.core.rmem_max = 16777216EOFsysctl -p11.基础优化操作项:安装系统常用软件CentOS6和CentOS7都要安装的企业运维常用基础工具包yum install tree nmap dos2unix lrzsz nc lsof wget tcpdump htop iftop iotop sysstat nethogs -yCentOS7要安装的企业运维常用基础工具包yum install psmisc net-tools bash-completion vim-enhanced -y独行快,众行远。——老男孩12.基础优化操作项:优化SSH远程连接效率禁止root远程连接修改默认22端口,改为52113监听内网服务器IP练习不动。13.扩展优化操作项-修改yum.conf文件配置信息保留yum安装的软件包将/etc/yum.conf中的keepcache=0改为keepcache=1,为日后一键安装网站集群留好rpm及依赖工具包。14. 锁定关键系统文件如/etc/passwd、/etc/shadow、/etc/group、/etc/gshadow、/etc/inittab,处理以上内容后把chattr、lsattr改名为oldboy,转移走,这样就安全多了。15. 清空/etc/issue、/etc/issue.net,去除系统及内核版本登录前的屏幕显示。16. 清除多余的系统虚拟用户账号。17. 为grub引导菜单加密码(自学)。18. 禁止主机被ping(内核参数)。19. 打补丁并升级有已知漏洞的软件。 yum update20.精简开机自启动服务systemctl list-unit-files |grep enable|egrep -v "sshd.service|crond.service|sysstat|rsyslog|^NetworkManager.service|irqbalance.service"|awk '{print "systemctl disable",$1}'|bashsystemctl list-unit-files |grep enable保留服务:sshd|crond|sysstat|rsyslog|NetworkManager|irqbalance企业生产最小化原则:1、安装软件包最小化。2、用户权限最小化。3、目录文件权限最小化。4、自启动服务最小化。5、服务运行用户最小化。[root@oldboyedu ~]# netstat -lntupActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 7072/sshd tcp6 0 0 :::22 :::* LISTEN 7072/sshd