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

小碼code發表於2021-10-25

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

下載

進入 apache ab官網 下載頁面。

安裝

brew 安裝

  • 因為筆者的作業系統是mac系統,所以需要先安裝brew。進入brew網站。執行下方命令
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

執行命令後報錯:
Failed to connect to raw.githubusercontent.com port 443: Connection refused
解決方案:
開啟 https://www.ipaddress.com/ 查詢 raw.githubusercontent.com 對應的 ip 地址。

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

185.199.108.133 raw.githubusercontent.com
185.199.109.133 raw.githubusercontent.com
185.199.110.133 raw.githubusercontent.com
185.199.111.133 raw.githubusercontent.com

再執行

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

執行成功後,使用brew安裝apr、apr-util和prce

brew install apr
brew install apr-util
brew inatll prce

apache ab安裝

解壓下載後壓縮包,進入 httpd-2.4.51 目錄。
執行以下命令:

./configure
make
make install

執行 ./configure 命令時報錯:

jeremy@jeremydeMacBook-Pro 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:
configure: Configuring Apache Portable Runtime library...
configure:
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

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.
                    '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

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

執行 ab

主要引數

  • -n 請求樹
  • -c 併發數(訪問人數)
  • -t 請求時間最大數
ab -n 1000 -c 100 http://www.baidu.com

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

總結

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

相關文章