1 | ab
|
2 | ===
|
3 |
|
4 | Apache服务器的性能测试工具
|
5 |
|
6 |
|
7 | ## 安装
|
8 |
|
9 | 若系统未安装,使用以下命令安装
|
10 |
|
11 | ```shell
|
12 | # Ubuntu
|
13 | sudo apt-get install apache2-utils
|
14 |
|
15 | # Centos
|
16 | yum install httpd-tools
|
17 |
|
18 | ```
|
19 |
|
20 |
|
21 | ## 补充说明
|
22 |
|
23 | **ab命令** 是一个测试你 Apache http 服务器的工具,你可以通过这个工具,指定一个单位时间内向 apache 发出的请求数量来看看你的 Apache 和机器配合的性能如何。
|
24 |
|
25 | ### 语法
|
26 |
|
27 | ```shell
|
28 | ab [ -A auth-username:password ] [ -c concurrency ] [ -C cookie-name=value
|
29 | ] [ -d ] [ -e csv-file ] [ -g gnuplot-file ] [ -h ] [ -H custom-header ] [
|
30 | -i ] [ -k ] [ -n requests ] [ -p POST-file ] [ -P proxy-auth-user‐
|
31 | name:password ] [ -q ] [ -s ] [ -S ] [ -t timelimit ] [ -T content-type ]
|
32 | [ -v verbosity] [ -V ] [ -w ] [ -x <table>-attributes ] [ -X proxy[:port]
|
33 | ] [ -y <tr>-attributes ] [ -z <td>-attributes ] [http://]host‐
|
34 | name[:port]/path
|
35 | ```
|
36 |
|
37 | ### 选项
|
38 |
|
39 | ```shell
|
40 | -A auth-username:password
|
41 | # 支持基本的验证证书,用户名和密码之间使用"冒号" :
|
42 | # 分隔开,ab将以明文方式传送过去.不管服务器是不是需要
|
43 | # ,也就是说你的服务器需要支持401认证.
|
44 |
|
45 | -c concurrency
|
46 | # 同时向服务器端发送的请求数目,默认状态下是一次 只执行一个http请求.
|
47 |
|
48 | -C cookie-name=value
|
49 | # Add a Cookie: line to the request. The argument is typically in the
|
50 | # form of a name=value pair. This field is repeatable.
|
51 |
|
52 | -d # Do not display the "percentage served within XX [ms] table".
|
53 | # (legacy support).
|
54 |
|
55 | -e csv-file
|
56 | # Write a Comma separated value (CSV) file which contains for each
|
57 | # percentage (from 1% to 100%) the time (in milli seconds) it took to
|
58 | # serve that percentage of the requests. This is usually more useful
|
59 | # than the 'gnuplot' file; as the results are already 'binned'.
|
60 |
|
61 | -g gnuplot-file
|
62 | # Write all measured values out as a 'gnuplot' or TSV (Tab separate
|
63 | # values) file. This file can easily be imported into packages like
|
64 | # Gnuplot, IDL, Mathematica, Igor or even Excel. The labels are on
|
65 | # the first line of the file.
|
66 | -h # 显示使用说明
|
67 | -H custom-header
|
68 | # 向请求包追加附加的标题字串.此参数应该是有效的标题 行(header
|
69 | # line)形式,通常使用冒号":"来分隔有效配对 (valid pair)例如 'Accept-
|
70 | # Encoding: zip/zop;8 bit';
|
71 |
|
72 | -i # 使用一个 http 头(HEAD) 来替换 GET方法.不可以掺入POST 方法
|
73 |
|
74 | -k # 允许http KeepAlive ;也就是说执行多个请求在一个 http
|
75 | # 会话当中,默认是不允许的也就是no KeepAlive啦;)
|
76 |
|
77 | -n requests
|
78 | # 执行一次测试会话的时候所发出的请求数目,默认是执行一个单一的请求
|
79 | # 当然了这样的测试结果也就没什么意义了
|
80 |
|
81 | -p POST-file
|
82 | # 测试程序也就是ab,将向Apache server发送带有HTTP POST 的请求.
|
83 |
|
84 | -P proxy-auth-username:password
|
85 | # 当需要通过代理测试一台 HTTP 服务器的时候而你的代理
|
86 | # 又需要用户名密码验证,这时你可以使用这个选项,同样
|
87 | # 用户名与密码之间使用冒号":"分隔开,ab将之以明文的方式
|
88 | # 发送出去,当然,前提是你的代理是处于407认证状态的
|
89 |
|
90 | -q # When processing more than 150 requests, ab outputs a progress count
|
91 | # on stderr every 10% or 100 requests or so. The -q flag will sup‐
|
92 | # press these messages.
|
93 |
|
94 | -s # When compiled in (ab -h will show you) use the SSL protected https
|
95 | # rather than the http protocol. This feature is experimental and
|
96 | # very rudimentary. You probably do not want to use it.
|
97 |
|
98 | -S # Do not display the median and standard deviation values, nor dis‐
|
99 | # play the warning/error messages when the average and median are
|
100 | # more than one or two times the standard deviation apart. And de‐
|
101 | # fault to the min/avg/max values. (legacy support).
|
102 |
|
103 | -t timelimit
|
104 | # 设置测试的时间的长短,使用这个选项ab将自动设置
|
105 | # 测试请求会话数目为50000,然后以你设置的时间为
|
106 | # 固定周期.默认状态下是没有时限的,也就是直到完成
|
107 | # 你所设置的请求数目为止.
|
108 |
|
109 | -T content-type
|
110 | # 内容类型标头,使用在POST数据的时候.
|
111 |
|
112 | -v verbosity
|
113 | # 设置冗余级别,4级打印出每个请求标头的详细信息,
|
114 | # 3级打印出回应代码(例如,404,200),2级打印出警告 信息和指示消息
|
115 |
|
116 | -V # 显示版本号并且退出
|
117 | -w # 打印输出结果到HTML表中. 默认的表是两列n行白底黑框
|
118 |
|
119 | -x <table>-attributes
|
120 | # 使用字串来描述表的属性,该属性字串应该插入到<table 这里 >
|
121 |
|
122 | -X proxy[:port]
|
123 | # Use a proxy server for the requests.
|
124 |
|
125 | -y <tr>-attributes
|
126 | # 用于生成html表格每行的属性名 (<tr>)
|
127 |
|
128 | -z <td>-attributes
|
129 | # 用于生成html表格每列的属性名 (<td>)
|
130 | ```
|
131 |
|
132 | ### 参数
|
133 |
|
134 | 主机:被测试主机。
|
135 |
|
136 |
|
137 | ### 实例
|
138 |
|
139 | ```shell
|
140 | # 10个并发, 请求500次
|
141 | ab -c 10 -n 500 https://www.qq.com/
|
142 | ```
|