MAC 安裝 apache ab 壓力測試工具以及遇到的坑

小碼code 發表於 2021-10-25

ab 是apache對 http伺服器進行壓力測試的工具,它可以測試出伺服器每秒可以處理多少請求。本文記錄mac版本安裝 ab 的步驟以及遇到的坑。


進入 apache ab官網 下載頁面。
MAC 安裝 apache ab 壓力測試工具以及遇到的坑


brew 安裝

  • 因為筆者的作業系統是mac系統,所以需要先安裝brew。進入brew網站。執行下方命令
/bin/bash -c "$(curl -fsSL"

Failed to connect to port 443: Connection refused
開啟 查詢 對應的 ip 地址。
MAC 安裝 apache ab 壓力測試工具以及遇到的坑

新增ip到 /etc/hosts,新增以下配置:


/bin/bash -c "$(curl -fsSL"


brew install apr
brew install apr-util
brew inatll prce

apache ab安裝

解壓下載後壓縮包,進入 httpd-2.4.51 目錄。

make install

執行 ./configure 命令時報錯:

[email protected] httpd-2.4.51 % ./configure
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-apple-darwin20.2.0
checking host system type... x86_64-apple-darwin20.2.0
checking target system type... x86_64-apple-darwin20.2.0
configure: Configuring Apache Portable Runtime library...
checking for APR... no
configure: error: APR not found.  Please read the documentation.

APR not found 沒找到
./configure 改成

 ./configure --with-apr=/usr/local/opt/apr --with-apr-util=/usr/local/opt/apr-util --with-pcre=/usr/local/Cellar/pcre/8.45

其中 pcre 的路徑可能不同,需要在 /usr/local/Cellar/pcre 裡面確定路徑。


ab: wrong number of arguments
Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
    -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.
                    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

出現以上介面,說明 ab 已經安裝成功。

執行 ab


  • -n 請求樹
  • -c 併發數(訪問人數)
  • -t 請求時間最大數
ab -n 1000 -c 100

表示請求 使用100請求數,請求1000次。


  • 需要在配置brew和檢測configure上花了比較多的時間。
  • 其餘的按照步驟即可。