Linux 下 Apache 占用高(CPU / 内存 / 连接数高) 是比较常见的问题,通常不是 Apache 本身“坏了”,而是配置、业务、或系统环境导致的。下面按常见原因 → 排查方法 → 解决建议来说明。
Apache 有多种工作模式:
prefork(进程型,内存占用高)worker(线程+进程)event(高并发推荐)问题表现
httpd / apache2 一大堆)排查
httpd -V | grep -i mpm
# 或
apache2 -V | grep -i mpm
建议
event 或 workerMaxClients / MaxRequestWorkers排查
netstat -an | grep :80 | wc -l
ss -ant | grep :80 | wc -l
tail -f /var/log/httpd/access_log
# 或
tail -f /var/log/apache2/access.log
看什么
Apache 只是“ frontend ”,真正吃资源的是:
典型现象
Sending Reply排查
top -c
# 看 httpd 进程对应的 php 脚本
PHP 示例:
sleep(10); // 或慢 SQL
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15
问题
建议
KeepAlive Off
或
KeepAliveTimeout 2~5
排查
du -sh /var/log/httpd
iostat -x 1
如:
建议
mod_php# 1. 看 Apache 进程数
ps aux | grep apache | wc -l
# 2. 看 CPU / 内存
top
# 3. 看连接数
ss -ant | grep :80 | wc -l
# 4. 看慢请求
tail -n 100 /var/log/apache2/access.log
✅ 使用 Apache + PHP-FPM
✅ 使用 event MPM
✅ 限制并发
✅ 开启 mod_status 观察
✅ 前端加 Nginx 或 CDN
✅ 数据库慢查询优化
你可以补充:
top 截图或进程数我可以直接帮你 看配置、给优化方案。