Apache Benchmark 简称ab,是apache里一个压力测试工具。安装ab一种直接安装apache server即可里面自带ab服务;另外一种不安装apache server 直接安装ab;
这里是通过安装apache server 环境是centos7
1:先安装基础依赖环境:
1.1:依赖基础环境
yum install -y gcc gcc-c++
yum install -y openssl-devel expat-devel
1.2:安装 pcre tar下载地址ftp://ftp.pcre.org/pub/pcre/
##安装基础依赖包
# yum -y install openssl-devel
##安装pcre 这里使用版本是8.43
tar -vxf pcre-8.43.tar.gz
cd pcre-8.43
##配置
./configure --prefix=/usr/local/pcre-8.43
##编译安装
make && make install
1.3:安装apr tar包下载地址http://archive.apache.org/dist/apr/
##先安装APR 这里使用apr版本为1.7.0
tar -vxf apr-1.7.0.tar.gz
cd apr-1.7.0
##配置
./configure --prefix=/usr/local/apr-1.7.0
##编译安装
make && make install
##安装
##这里使用apr-utils版本为1.6.1
tar -vxf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
##配置
./configure --prefix=/usr/local/apr-util-1.6.1 --with-apr=/usr/local/apr-1.7.0/
##编译安装
make && make install
1.4:安装 apache server
直接在官网中下载最新版的tar包路径为:http://httpd.apache.org/download.cgi#apache24
##apache 版本为httpd-2.4.41
tar -vxf httpd-2.4.41.tar.gz
cd httpd-2.4.41
###配置 参数--prefix指定安装路径,--enable-mods-shared启用所有支持的动态加载模块,--with-apr指定APR路径,--with-apr-util指定APR-util路径 --with-pcre指定pcre路径
./configure --prefix=/usr/local/apache --enable-mods-shared=all --with-apr=/usr/local/apr-1.7.0/ --with-apr-util=/usr/local/apr-util-1.6.1/ --with-pcre=/usr/local/pcre-8.43
##安装
make && make install
2:使用apache ab模块
2.1:ab 基础设置参数说明:
-n requests 要执行的请求总数
-c concurrency 并发数
-t timelimit 所有请求数共花最大时间
-s timeout 最大超时时间 默认30s
-T Content Type 设置Content Type 例如 -T‘application/json’
-p postfile POST请求时请求参数可以放在文件中由postfile指定路径. Remember also to set -T
ab命令支持所有参数
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