CentOS壓力測試 ab 命令安裝與使用


Apache安裝包中自帶的壓力測試工具 Apache Benchmark(簡稱ab) 簡單易用,這里就采用 ab作為壓力測試工具了。

1.獨立安裝

ab運行需要依賴apr-util包,安裝命令為: 

 

yum install apr-util

 

 

安裝依賴 yum-utils中的yumdownload 工具

如果沒有找到 yumdownload 命令可以

 

yum install yum-utils

 

 

安裝完成后執行以下指令

 

cd /opt

mkdir abtmp

cd abtmp

yum install yum-utils.noarch

yumdownloader httpd-tools*

rpm2cpio httpd-*.rpm | cpio -idmv

  

解開后就能得到獨立的 ab可執行文件了。

操作完成后 將會產生一個 usr 目錄 ab文件就在這個usr 目錄中

 

上述命令成功后,可以在abtmp下的usr/bin中看到一個名為ab的文件,復制到系統PATH下就大功告成,例如。

簡單使用說明
1. 最基本的關心兩個選項 -c -n
例: ./ab -c 100 -n 10000 http://127.0.0.1/index.php

-c 100 即:每次並發100個
-n 10000 即: 共發送10000個請求

2.命令的參數、輸出結果的中文注解
格式: ./ab [options] [http://]hostname[:port]/path
參數:
-n requests Number of requests to perform
//在測試會話中所執行的請求個數。默認時,僅執行一個請求
-c concurrency Number of multiple requests to make
//一次產生的請求個數。默認是一次一個。
-t timelimit Seconds to max. wait for responses
//測試所進行的最大秒數。其內部隱含值是-n 50000。它可以使對服務器的測試限制在一個固定的總時間以內。默認時,沒有時間限制。
-p postfile File containing data to POST
//包含了需要POST的數據的文件.
-T content-type Content-type header for POSTing
//POST數據所使用的Content-type頭信息。
-v verbosity How much troubleshooting info to print
//設置顯示信息的詳細程度 - 4或更大值會顯示頭信息, 3或更大值可以顯示響應代碼(404, 200等), 2或更大值可以顯示警告和其他信息。 -V 顯示版本號並退出。
-w Print out results in HTML tables
//以HTML表的格式輸出結果。默認時,它是白色背景的兩列寬度的一張表。
-i Use HEAD instead of GET
// 執行HEAD請求,而不是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)
//-C cookie-name=value 對請求附加一個Cookie:行。 其典型形式是name=value的一個參數對。此參數可以重復。
-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.
//-P proxy-auth-username:password 對一個中轉代理提供BASIC認證信任。用戶名和密碼由一個:隔開,並以base64編碼形式發送。無論服務器是否需要(即, 是否發送了401認證需求代碼),此字符串都會被發送。
-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.
-g filename Output collected data to gnuplot format file.
-e filename Output CSV file with percentages served
-h Display usage information (this message)
//-attributes 設置 屬性的字符串. 缺陷程序中有各種靜態聲明的固定長度的緩沖區。另外,對命令行參數、服務器的響應頭和其他外部輸入的解析也很簡單,這可能會有不良后果。它沒有完整地實現 HTTP/1.x; 僅接受某些'預想'的響應格式。 strstr(3)的頻繁使用可能會帶來性能問題,即, 你可能是在測試ab而不是服務器的性能。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM