以下是优化CentOS网络设置以提升Apache性能的关键措施:
/etc/sysctl.conf
,设置net.ipv4.tcp_tw_reuse=1
(允许重用TIME_WAIT连接)、net.ipv4.tcp_fin_timeout=30
(缩短FIN超时时间)、net.core.somaxconn=65535
(增大连接队列长度)等参数,优化连接管理。/etc/security/limits.conf
中设置* soft nofile 65535
和* hard nofile 65535
,提升并发连接能力。/etc/sysconfig/network-scripts/ifcfg-ens33
(网卡名需替换),设置MTU=1500
(或根据网络环境调整),启用tcp-segmentation-offload
(TSO)等硬件加速功能。firewall-cmd
开放HTTP(80)、HTTPS(443)端口,关闭不必要的服务端口。iptables
或firewalld
限制扫描、恶意IP的连接,避免资源占用。httpd.conf
中设置KeepAlive On
,并调整KeepAliveTimeout
(建议5-10秒)和MaxKeepAliveRequests
(如100),减少连接建立开销。event
/prefork
/worker
模块,在httpd.conf
中优化StartServers
、MaxRequestWorkers
等参数,平衡并发处理能力。iftop
、nload
等工具实时监控网络流量,及时发现瓶颈。注意:修改配置前需备份原文件,建议在测试环境验证后再应用到生产环境。