搜 索

AB测压命令详细讲解

  • 460阅读
  • 2022年08月20日
  • 0评论
首页 / 分享 / 正文

相信大家一定经常遇到攻击吧?

像我这样的贫穷学生用的是114/年的阿里云学生机

虽然便宜 但是防御做的挺不错的

如果想给自己服务器 测试一下防御 很简单

自己电脑 安装一个Linux系统 然后 使用AB命令 来对服务器经行测试

AB命令在centos系统可以用yum安装
yum install ab
如果这个命令不可以 试试下面的
yum -y install httpd-tools

其他系统 apt也可以安装 就不一一教大家了 这些百度有安装教程 自己系统 + ab命令如何安装 就好

-n requests Number of requests to perform

-c concurrency Number of multiple requests to make at a time
-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 File containing data to POST. Remember also to set -T
-u putfile File containing data to PUT. Remember also to set -T
-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)...

讲解ac命令
{1}
如果看不懂不要慌 我来给大家讲一下什么意思
-n

即requests,用于指定压力测试总共的执行次数。

-c

即concurrency,用于指定压力测试的并发数。

-t

即timelimit,等待响应的最大时间(单位:秒)。

-b

即windowsize,TCP发送/接收的缓冲大小(单位:字节)。

-p

即postfile,发送POST请求时需要上传的文件,此外还必须设置-T参数。

-u

即putfile,发送PUT请求时需要上传的文件,此外还必须设置-T参数。

-T

即content-type,用于设置Content-Type请求头信息,例如:application/x-www-form-urlencoded,默认值为text/plain。

-v

即verbosity,指定打印帮助信息的冗余级别。

-w

以HTML表格形式打印结果。

-i

使用HEAD请求代替GET请求。

-x

插入字符串作为table标签的属性。

-y

插入字符串作为tr标签的属性。

-z

插入字符串作为td标签的属性。

-C

添加cookie信息,例如:"Apache=1234"(可以重复该参数选项以添加多个)。

-H

添加任意的请求头,例如:"Accept-Encoding: gzip",请求头将会添加在现有的多个请求头之后(可以重复该参数选项以添加多个)。

-A

添加一个基本的网络认证信息,用户名和密码之间用英文冒号隔开。

-P

添加一个基本的代理认证信息,用户名和密码之间用英文冒号隔开。

-X

指定使用的代理服务器和端口号,例如:"126.10.10.3:88"。

-V

打印版本号并退出。

-k

使用HTTP的KeepAlive特性。

-k

使用HTTP的KeepAlive特性。

-d

不显示百分比。

-S

不显示预估和警告信息。

-g

输出结果信息到gnuplot格式的文件中。

-e

输出结果信息到CSV格式的文件中。

-r

指定接收到错误信息时不退出程序。

-h

显示用法信息,其实就是ab -help。
举个例子 就比如我们正常给自己服务器测压

(切记一定要加http(s)然后网址结尾要加/)或者https://bk.liuzeqi.com/index.php

ab -n 1000 -c 100 https://bk.liuzeqi.com/
这段命令是什么意思呢 相信大家看到上面说的应该明白了吧 -n压力测试总共的执行次数 -c 指定压力测试的并发数 后面是网址 就是压力测试的目标

测试图
这样大家就对自己服务器经行测试了 !!!

然后我们会发现结束了

他会给我们一段话 这也就是告诉我们压力测试的结果

Server Software:
Server Hostname: bk.liuzeqi.com
Server Port: 443

Document Path: /index.php
Document Length: 0 bytes

Concurrency Level: 100
Time taken for tests: 3.159 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 0 bytes
HTML transferred: 0 bytes
Requests per second: 316.56 #/sec
Time per request: 315.896 ms
Time per request: 3.159 [ms] (mean, across all concurrent requests)
Transfer rate: 0.00 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 1 3 2.1 3 27
Waiting: 0 0 0.0 0 0
Total: 1 3 2.1 3 27

Percentage of the requests served within a certain time (ms)
50% 3
66% 3
75% 3
80% 4
90% 5
95% 6
98% 10
99% 12
100% 27 (longest request)

给大家翻译一下

服务器软件:
服务器主机名:bk.liuzeqi.com
服务器端口:443

文件路径:/index.php
文件长度:0个位元组

并发级别:100
测试时间:3.159秒
完成要求:1000
请求失败:0
写入错误:0
传输总数:0字节
传输的HTML:0个字节
每秒请求数:316.56 [#/ sec](平均)
每个请求的时间:315.896 [ms](平均)
每个请求的时间:3.159 [ms](所有并发请求中的平均值)
传输速率:接收到0.00 [Kbytes / sec]

连接时间(毫秒)
最小平均值[+/- sd]中位数最大值
连接:0 0 0.0 0 0
处理中:1 3 2.1 3 27
等待中:0 0 0.0 0 0
总计:1 3 2.1 3 27

在一定时间内服务的请求百分比(毫秒)
50%3
66%3
75%3
80%4
90%5
95%6
98%10
99%12
100%27(最长要求)

博主 希望大家不要用ab命令对别人服务器经行恶意的cc攻击哦!

虽然ab不算cc攻击 但是如果多台服务器一起并发 可能会对别人服务器产生超负载 导致别人服务器无法正常运行!!!

希望大家只是用这个ab命令经行学习和帮助自己服务器测试压力

无标签
打 赏
  • 支付宝
  • 微信
  • QQ
Alipay
WeChatPay
QQPay
评论区
评论已关闭