2.1给/etc/rc.local添加执行权限
[root@localhost ~]# chmod +x /etc/rc.d/rc.local #为rc.local添加可执行权限
2.2禁用selinux
[root@localhost ~]# sed -i ‘/^SELINUX/s/enforcing/disabled/g’ /etc/selinux/config
[root@localhost ~]# grep -i ^selinux /etc/selinux/config SELINUX=disabled SELINUXTYPE=targeted [root@localhost ~]# setenforce 0
2.3查看并管理服务
[root@hequan ~]# systemctl -t service
[root@hequan ~]# systemctl list-unit-files -t service yum install -y bash-completion #补全服务名称,退出bash再进就可以
2.4 yum 安装常用组件包
[root@localhost ~]#yum install gcc cmake bzip2-devel curl-devel db4-devel libjpeg-devel libpng-devel freetype-devel libXpm-devel gmp-devel libc-client-devel openldap-devel unixODBC-devel postgresql-devel sqlite-devel aspell-devel net-snmp-devel libxslt-devel libxml2-devel pcre-devel mysql-devel pspell-devel libmemcached libmemcached-devel zlib-devel vim wget lrzsz tree
2.5配置sshd
[root@localhost ~]#sed -i -e ‘49s/^#//g’ /etc/ssh/sshd_config ##启用49行配置
[root@localhost ~]#sed -i -e ‘129s/#/ /g’ /etc/ssh/sshd_config ##禁止UseDNS
[root@localhost ~]#sed -i ‘/^GSS/s/yes/no/g’ /etc/ssh/sshd_config ##禁用GSSAPI认证加快登录速度
[root@localhost ~]#systemctl restart sshd ##重新启动服务
[root@localhost ~]#systemctl enable sshd ##设置为开机启动
[root@localhost ~]#systemctl status sshd ##查看状态
2.6加大打开文件数的限制(open files)
[root@localhost ~]#vi /etc/security/limits.conf #在文件末尾添加
- soft nofile 1024000
- hard nofile 1024000 hive
- nofile 1024000 hive
- nproc 1024000
2.7加大普通用户进程数限制
[root@hequan ~]# sed -i ‘s#4096#65535#g’ /etc/security/limits.d/20-nproc.conf
2.8优化系统内核
[root@hequan ~]#vi /etc/sysctl.conf #CTCDN系统优化参数在文件末尾添加
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536 kernel.msgmax = 65536
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
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 = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 1800
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
[root@hequan ~]#sysctl -p #生效
[root@hequan ~]#reboot #重启系统使上述优化生效