文章目录

1.1 原理1.2 部署1.3 语法和参数解释1.4 示例

1.1 原理

  ab命令会创建多个并发访问线程,模拟多个访问者同时对某一URL地址进行访问。它的测试目标是基于URL,因此可以用来测试apache、nginx、lighthttp、tomcat、IIS等Web服务器的压力。   ab命令对发出负载的计算机要求很低,它既不会占用很高CPU,也不会占用很多内存。但却会给目标服务器造成巨大的负载,其原理类似CC攻击(攻击者控制某些主机不停地发送大量数据包给对方服务器造成服务器资源耗尽,一直到宕机崩溃)。一次上太多的负载。可能造成目标服务器资源耗完,严重时甚至导致死机

1.2 部署

(1) CentOS6 默认安装

(2) CentOS7需要手动安装 联网:

yum install httpd-tools

查看安装版本:

ab -V

1.3 语法和参数解释

语法:

ab [options] [http[s]://]hostname[:port]/path

-n requests 发送请求数量

-c concurrency 并发数量,同时发送请求的个数

-t timelimit Seconds to max. to spend on benchmarking

This implies -n 50000

-s timeout Seconds to max. wait for each response

Default is 30 seconds

-b windowsize Size of TCP send/receive buffer, in bytes

-B address Address to bind to when making outgoing connections

-p postfile 指定包含post请求数据的文件,必须和-T连用指定content-type

-u putfile 指定包含put请求数据的文件,必须和-T连用指定content-type

-T content-type Content-type header to use for POST/PUT data, eg.

'application/x-www-form-urlencoded'

Default is 'text/plain'

-v verbosity How much troubleshooting info to print

-w Print out results in HTML tables

-i Use HEAD instead of GET

-x attributes String to insert as table attributes

-y attributes String to insert as tr attributes

-z attributes String to insert as td or th attributes

-C attribute Add cookie, eg. 'Apache=1234'. (repeatable)

-H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'

Inserted after all normal header lines. (repeatable)

-A attribute Add Basic WWW Authentication, the attributes

are a colon separated username and password.

-P attribute Add Basic Proxy Authentication, the attributes

are a colon separated username and password.

-X proxy:port Proxyserver and port number to use

-V Print version number and exit

-k Use HTTP KeepAlive feature

-d Do not show percentiles served table.

-S Do not show confidence estimators and warnings.

-q Do not show progress when doing more than 150 requests

-g filename Output collected data to gnuplot format file.

-e filename Output CSV file with percentages served

-r Don't exit on socket receive errors.

-h Display usage information (this message)

-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)

-f protocol Specify SSL/TLS protocol

(SSL3, TLS1, TLS1.1, TLS1.2 or ALL)

1.4 示例

ab -n 2000 -c 200 -k -p ./postfile -T application/x-www-form-urlencoded http://192.168.0.109:8080/redisTest/secKill

-p 指定请求数据 发送请求后,可看到压测信息

推荐阅读

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。