使用apache 的 ab命令压力测试nginx服务器

时间:2023-03-09 21:30:21
使用apache 的 ab命令压力测试nginx服务器
 nginx压力测试方法:
#ab命令
#安装ab
#Centos系统
yum install apr-util
#Ubuntu系统
sudo apt-get install apache2-utils #ab命令的参数
-n //在测试会话中所执行的请求个数。默认为1
-c //一次产生的请求个数。默认为1
-t //测试所进行的最大秒数。默认值为50000
-p //包含了需要的POST的数据文件
-T //POST数据所使用的Content-type头信息 #实例
ab -c -n http://www.baidu.com/
每次发送1000并发的请求数,请求数总数为5000。 ------------------------------------------------------------------------------
#nginx防止被压力测试的设置方法:
#限制同一IP并发数最大为10
vim /etc/nginx/nginx.conf
http{}字段第一行添加:
limit_conn_zone $binary_remote_addr zone=one:10m;
vim /etc/nginx/conf.d/default
server{}字段添加:
limit_conn one ; #重启nginx
service nginx restart #如出现这种错误提示,表明nginx.conf中的limit_conn_zone $binary_remote_addr zone=one:10m;
#没有添加到正确的区域,最后添加在http字段的第一行。
the size of shared memory zone "one" conflicts with already declared size in /etc/nginx/nginx.conf: