Centos 安装ab工具

来源:互联网 发布:软件直销网 编辑:程序博客网 时间:2024/05/20 11:24

ab运行需要apr-util和yum-utils依赖包,如果还没有安装,需要下载最新版本安装

一、检测依赖包是否安装

输入下面两个命令,检测依赖包是否安装

[root@localhost abtmp]# rpm -qa|grep apr-utilapr-util-1.5.2-6.el7.x86_64[root@localhost abtmp]# rpm -qa|grep yum-utilsyum-utils-1.1.31-40.el7.noarch

输入以上两个命令,如果没有出现下面信息,则表示没有安装

如果没有安装,请使用以下命令安装

[root@localhost abtmp]# yum -y install apr-util[root@localhost abtmp]# yum -y install yum-utils

二、安装ab工具

新建一个目录,下载解压用:

[root@localhost abtmp] cd /opt[root@localhost opt] mkdir abtmp[root@localhost opt] cd abtmp[root@localhost abtmp] yum install yum-utils.noarch[root@localhost abtmp] yumdownloader httpd-tools*[root@localhost abtmp] rpm2cpio httpd-tools*.rpm | cpio -idmv

将./user/bin/ab复制到系统bin下即可:

[root@localhost abtmp] cp /opt/abtmp/usr/bin/ab /usr/bin

三、测试

模拟100个并发,执行1000次请求,结果如下:

[root@localhost abtmp] ab -n 1000 -c 100 http://localhost/index.phpThis is ApacheBench, Version 2.3 <$Revision: 1430300 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking localhost (be patient)Completed 100 requestsCompleted 200 requestsCompleted 300 requestsCompleted 400 requestsCompleted 500 requestsCompleted 600 requestsCompleted 700 requestsCompleted 800 requestsCompleted 900 requestsCompleted 1000 requestsFinished 1000 requestsServer Software:        nginx/1.9.9Server Hostname:        localhostServer Port:            80Document Path:          /index.phpDocument Length:        92249 bytesConcurrency Level:      100Time taken for tests:   4.545 secondsComplete requests:      1000Failed requests:        100   (Connect: 0, Receive: 0, Length: 100, Exceptions: 0)Write errors:           0Total transferred:      92409886 bytesHTML transferred:       92248886 bytesRequests per second:    220.02 [#/sec] (mean)Time per request:       454.505 [ms] (mean)Time per request:       4.545 [ms] (mean, across all concurrent requests)Transfer rate:          19855.44 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        0    1   6.3      0     139Processing:    12  435  92.7    468     573Waiting:        5  435  92.6    468     572Total:         12  436  91.8    468     573Percentage of the requests served within a certain time (ms)  50%    468  66%    478  75%    489  80%    494  90%    502  95%    507  98%    521  99%    531 100%    573 (longest request)