Apache 在 CentOS 上出现“卡顿”(响应慢、连接堆积、CPU/内存占用高、偶发卡死)通常不是单一原因,下面按最常见 → 较少见的顺序给你一个系统性的排查思路。
CentOS 默认可能使用:
prefork(老、稳定,但耗内存)worker / event(高并发更好)现象
scoreboard 全是 Waiting / Busy排查
httpd -V | grep -i mpm
建议
eventpreforkworker / event如果你用:
mod_php现象
排查
top
ps -ef | grep httpd
解决
php-fpmpm.max_childrenCentOS 默认限制较低。
现象
Too many open files
检查
ulimit -n
cat /proc/sys/fs/file-max
解决
/etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
现象
排查
getenforce
tail /var/log/audit/audit.log
临时验证
setenforce 0
现象
排查
iostat -x 1
常见原因
现象
si/so 不为 0free -m
vmstat 1
解决
HostnameLookups)关闭
HostnameLookups Off
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5 # 别设太大
ls -lh /var/log/httpd/
建议
logrotate# 当前连接状态
ss -ant | awk '{print $1}' | sort | uniq -c
# Apache 状态
httpd status
# 慢请求
tail -f /var/log/httpd/access_log
你可以补充:
top / free / ss 的输出我可以直接帮你定位到具体配置或命令。