服务器测试工具之nginx(模拟成第三方服务)

用途

1.性能测试过程中使用到第三方服务时,可用nginx替代,先对模拟的服务进行压测,给出数据来说明模拟的服务器对本次业务性能测试影响较小。

2.功能测试过程中模拟第三方服务异常情况,或者更多种正常情况,验证被测系统的异常处理。

nginx安装(Linux)

1)下载tar包放在/usr/local下面下载地址:http://nginx.org/en/download.html

2)安装相关依赖和库文件

# yum -y install gcc gcc-c++ autoconf automake//gcc、gcc-c++的库文件

# yum -y install pcre pcre-devel//安装Nginx依赖包

# yum -y install zlib zlib-devel

解压nginx.tar.gz包

# tar -zxvf /home/veryyoung/nginx-1.12.0.tar.gz//解压tar包

在解压包中运行./configure并安装

# cd /home/veryyoung/nginx-1.12.0/

# ./configure  //确认执行之前有执行权限,没有的话执行命令  chmod 777 configure

# make

# make install                                  //安装

为nginx扩展echo(nginx本身不带echo的,必须自己下载)

从地址https://github.com/openresty/echo-nginx-module下载echo-nginx-module

下载之后安装按照普通模块安装即可:

./configure --prefix=/usr/local/nginx --add-module=/dir-to-echo-nginx-module  //执行的时候还是去nginx解压的地方,后者的dir-to-echo-nginx-module路径是下载的echo扩展解压所在的目录(我是在/home/veryyoung/echo-nginx-module-master)

安装之后,root权限执行:

make -j2 && make install

然后就可以在自定义模块中使用echo指令。

比如在配置文件nginx.conf中添加:

location /veryyoung{

echo '{"name":"veryyoung"}';

}

还可以修改返回类型:

将 default_type  application/octet-stream;  修改为  default_type  application/json;  //返回json类型


在nginx.conf文件中可添加多个location:

location /test {

echo '{"msg":"hello world!"}';

}


更多的nginx配置信息请看另一文:nginx之nginx.conf文件

你可能感兴趣的:(服务器测试工具之nginx(模拟成第三方服务))