问题
ulimit 值过小,可能导致压力测试遇到瓶颈,比如通过nginx建立tcp长链接时,链接数量受限。需要修改ulimit值,Linux默认为1024。
解决
使用root或sudo权限,编辑文件/etc/security/limits.conf,新增以下内容:
# End of file
# open files (-n)
* soft nofile 20480
* hard nofile 20480
root soft nofile 20480
root hard nofile 20480
#
# # max user processes (-u)
* soft nproc 20480
* hard nproc 20480
root soft nproc 20480
root hard nproc 20480

修改完成后,重新登录Linux,执行ulimit -n 或ulimit -a验证修改结果。
注意
若是调整nginx服务器的ulimit值,应考虑是否会受DDOS共计影响(比如客户端建立了上万个tcp连接)。
修改后重新登录即刻,不用重启服务器。
另外,其它进程(如nginx)需要在修改ulimit后重启,否则仍会使用修改前的默认值1024。











![[黑马程序员SpringBoot2]——开发实用篇2](https://img-blog.csdnimg.cn/c40032139270428b875922c903517c31.png)







