在 CentOS 上测试 Apache(通常是 httpd,而不是 apache2,apache2 是 Debian/Ubuntu 的叫法) 的性能,常用方法和工具如下:
# CentOS 上一般为 httpd
systemctl status httpd
# 若未安装
yum install httpd -y
systemctl start httpd
Apache 自带压力测试工具
# 安装(一般已随 httpd 安装)
yum install httpd-tools -y
# 测试示例
ab -n 1000 -c 100 http://localhost/
参数说明:
-n 1000:总请求数-c 100:并发数-k 启用 keep-alive结果关注:
yum install wrk -y
wrk -t4 -c100 -d30s http://localhost/
参数:
-t 线程数-c 连接数-d 测试时间yum install siege -y
siege -c100 -t30s http://localhost/
适合复杂场景:
# 下载并运行
java -jar jmeter.jar
httpd -V
apachectl -S
top
htop
vmstat 1
iostat -x 1
tail -f /var/log/httpd/access_log
tail -f /var/log/httpd/error_log
KeepAlive OnMaxKeepAliveRequestsStartServers / MaxClients / MaxRequestsPerChildmpm.event 或 mpm.workermod_deflate、mod_cache# 1. 启动 Apache
systemctl start httpd
# 2. 压测
ab -n 5000 -c 200 http://localhost/index.html
# 3. 监控资源
top
如果你愿意,我可以:
你目前的 CentOS 版本和 Apache 是哪种?