为了提升服务器并发访问能力,有时我们需要修改最大支持打开文件的数量,
使用 ulimit 工具将很容易实现这点
首先,查看当前能够打开文件的数量
# ulimit -a
![](https://i-blog.csdnimg.cn/blog_migrate/d64842e8842f3076e99a6a7434989068.png)
可以看到,open files 为1024, 而且提示了参数为 -n,下面我们修改该值
# ulimit -n 65536
# ulimit -a
![](https://i-blog.csdnimg.cn/blog_migrate/66d6c69e9f4a35e9e9e513d897a5fdc1.png)
可以看到,open files 已经变成我们需要的 65536 啦! 是不是很简单呢!
不过上述修改方法只是当前生效,如果要永久生效,还是要修改配置文件
1. /etc/pam.d/login 添加pam_limits.so (有时候系统默认添加)
首先要通过find / -name pam_limits.so 查找文件的具体的位置
session required /lib/security/pam_limits.so
2. /etc/security/limits.conf 添加 (* 代表所有用户有效,你也可以配置具体的用户名)
* soft nofile 65536
* hard nofile 65536