防火墙:
开启端口 如3306
firewall-cmd--zone=public --add-port=3306/tcp –permanent
重启防火墙
systemctlrestart firewalld.service
停止防火墙:
sudo systemctl stop firewalld.service
操作系统优化
1.连接网络优化
通过命令:netstat -an 查看当前的连接信息
ESTABLISHED:正在通讯
TIME_WAIT: 主动关闭
CLOSE_WAIT:被动关闭
过多的TIME_WAIT 产生 error:Too Many Open files 默认文件打开数量是1024,腾讯云Centos7 默认1W个
优化思路:
让服务器能够自动快速回收和重复利用Time_Wait资源
vi /etc/sysctl.conf 也可能是 sysctl.conf.first
加入的内容:
开启重用:冗余讲TIME_WAIT socket资源重新用于新的TCP连接,默认是0,关闭
net.ipv4.tcp_tw_reuse=1
开启回收:
net.ipv4.tcp_tw_recycle=1
使配置生效:
sysctl –p
2.设置Openfiles
查看打开文件数量
ulimit -a
ulimit -n
修改打开文件数:
1. vi /etc/profile
在文件最后一行后面加入如下内容:
ulimit –n 65535
:wq
使配置生效
source /etc/profile
2. vi /etc/security/limits.conf
在末尾加入如下内容:
* soft nofile65535
* hard nofile65535
* soft nproc65535
*hard nproc 65535