温馨提示×

怎么看apache负载情况

小樊
43
2026-10-03 14:38:49
栏目: 编程语言

查看 Apache 负载情况,通常可以从 连接数、进程/线程、请求速率、系统资源 几个维度来看。下面按常用方式给你总结一下:


一、使用 Apache 自带状态页(最推荐)

1. 开启 mod_status

编辑 Apache 配置(如 httpd.conf 或 apache2.conf):

<Location /server-status>
    SetHandler server-status
    Require local
    # 或允许指定 IP
    # Require ip 192.168.1.100
</Location>

ExtendedStatus On

重启 Apache:

systemctl restart apache2   # Debian/Ubuntu
systemctl restart httpd     # CentOS/RHEL

访问:

http://你的IP/server-status

或实时刷新:

http://你的IP/server-status?auto

可以看到:

  • 当前连接数(Total Accesses)
  • 正在处理的请求(BusyWorkers)
  • 空闲进程(IdleWorkers)
  • 每个请求的状态(reading / sending / waiting)

二、命令行查看连接数

1. 查看 Apache 进程

ps -ef | grep httpd
# 或
ps -ef | grep apache2

2. 统计当前连接数

netstat -an | grep :80 | wc -l
# 或
ss -ant | grep :80 | wc -l

3. 查看 ESTABLISHED 连接

ss -ant | grep :80 | grep ESTAB | wc -l

三、查看 Apache 工作模式与限制

1. 查看 MPM 模式

apachectl -V | grep -i mpm

常见模式:

  • prefork
  • worker
  • event

2. 查看最大连接数配置

grep -i maxrequestworkers /etc/httpd/conf/httpd.conf
grep -i maxclients /etc/httpd/conf/httpd.conf

四、系统层面看负载

top
htop
uptime
free -h
iostat -x 1

重点关注:

  • CPU 使用率
  • 内存是否吃满
  • IO 等待(%iowait)

五、日志分析(看请求压力)

1. 统计 QPS

tail -f access.log

2. 统计访问 IP

awk '{print $1}' access.log | sort | uniq -c | sort -nr | head

六、常用判断标准

  • BusyWorkers 长期接近 MaxRequestWorkers → Apache 满载
  • ESTABLISHED 连接持续增长 → 可能被压或慢请求
  • CPU / IO 高 + 响应慢 → 后端或资源瓶颈

如果你愿意,可以告诉我:

  • 系统(CentOS / Ubuntu)
  • Apache 版本
  • 是用 prefork 还是 event

我可以帮你具体分析当前负载是否正常,甚至给优化建议。

0 踩