查看 Apache 负载情况,通常可以从 连接数、进程/线程、请求速率、系统资源 几个维度来看。下面按常用方式给你总结一下:
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
可以看到:
ps -ef | grep httpd
# 或
ps -ef | grep apache2
netstat -an | grep :80 | wc -l
# 或
ss -ant | grep :80 | wc -l
ss -ant | grep :80 | grep ESTAB | wc -l
apachectl -V | grep -i mpm
常见模式:
preforkworkereventgrep -i maxrequestworkers /etc/httpd/conf/httpd.conf
grep -i maxclients /etc/httpd/conf/httpd.conf
top
htop
uptime
free -h
iostat -x 1
重点关注:
tail -f access.log
awk '{print $1}' access.log | sort | uniq -c | sort -nr | head
如果你愿意,可以告诉我:
prefork 还是 event我可以帮你具体分析当前负载是否正常,甚至给优化建议。