nginx优化并发连接数

12 篇文章 0 订阅

优化前使用ab高并发工具测试

[root@web1 ~]# yum -y install httpd-tools
[root@web1 ~]# rpm -qa httpd-tools
httpd-tools-2.4.6-97.el7.centos.x86_64
[root@web1 ~]# ab -c 100 -n 100 http://192.168.2.100/	-c代表总人数,-n代表总访问量
[root@web1 ~]# ab -c 2000 -n 2000 http://192.168.2.100/
socket: Too many open files (24)               #提示打开文件数量过多

修改Nginx配置文件,增加并发量cpu处理器图形模式查看,改成2个

[root@web1 ~]# lscpu
[root@web1 ~ ]# vim /usr/local/nginx/conf/nginx.conf
.. ..
worker_processes  2;			#与CPU核心数量一致
events {
    worker_connections  50000;	#每个worker最大并发连接数
}
[root@web1 ~]# /usr/local/nginx/sbin/nginx -s reload
[root@web1 ~]#  ab -c 2000 -n 2000 http://192.168.2.100/		#再次测试,依旧报错
优化Linux内核参数(最大文件数量)
[root@web1 ~]# ulimit -a 						#查看所有属性值
open files                      (-n) 1024		#打开文件数量
[root@web1 ~]# ulimit -n 100000			#更改打开的文件数量,修改内核限制(临时)
[root@web1 ~]#  ab -c 2000 -n 2000 http://192.168.2.100/

永久修改

[root@web1 ~ ]# vim /etc/security/limits.conf
.. ..
*    soft    nofile		100000		#软限制
*    hard   nofile		100000		#硬限制,nofile用户最大文件打开数量

#该配置文件分4列,分别如下:
用户或组 硬限制或软限制 需要限制的项目 限制的值

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值