设置文件最大打开数
系统
nano /etc/sysctl.conf
添加
fs.file-max = 1048576
sysctl -p
用户
nano /etc/security/limits.conf
添加
* hard nofile 1048576
* soft nofile 1048576
root hard nofile 1048576
root soft nofile 1048576
Systemd
sed -i '/DefaultLimitNOFILE/c DefaultLimitNOFILE=1048576' /etc/systemd/*.conf
systemctl daemon-reexec
验证
打开新的终端
ssh remote_user@host
查看系统限制
cat /proc/sys/fs/file-max
查看用户硬限制
ulimit -Hn
查看用户软限制
ulimit -Sn
查看某进程的限制
cat /proc/PID/limits # 将 PID 替换为具体的进程 ID
查看其他用户限制
su - www -c 'ulimit -aHS' -s '/bin/bash'
备注
不需要在 /etc/pam.d/common-session
末尾添加 session required pam_limits.so。
参考资料:
Ubuntu 永久修改 ulimit -n | Laravel China 社区
https://learnku.com/articles/21457
Ubuntu 永久修改 ulimit -n
https://my.oschina.net/u/914655/blog/3067520