以下是提升CentOS上Apache性能的关键措施:
优化Apache配置
KeepAlive On,MaxKeepAliveRequests 100,KeepAliveTimeout 5。MaxRequestWorkers(建议设置为CPU核心数×200),推荐使用mpm_event模块。mod_cache和mod_disk_cache缓存静态资源,或用mod_expires设置浏览器缓存。mod_deflate压缩文本类文件(如HTML/CSS/JS),减少传输量。系统内核优化
/etc/sysctl.conf:增加net.core.somaxconn(建议65535)、net.ipv4.tcp_max_syn_backlog,启用tcp_tw_reuse。/etc/security/limits.conf中设置nofile 65535。硬件与系统优化
noatime选项减少磁盘I/O。网络与日志优化
mod_http2提升传输效率。rotatelogs定期分割日志,降低日志级别为warn。安全与监控
httpd.conf中不需要的模块减少资源占用。top、htop、netstat等工具定期检查系统负载。操作前建议:备份配置文件,先在测试环境验证优化效果,避免影响生产环境稳定性。