Ubuntu 永久修改 ulimit -n

本文主要参考 Increase Open Files Limit 和若干 Stack Overflow 的回答,并经过反复实践整理。

设置文件最大打开数

# 系统
echo 'fs.file-max = 65535' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

# 用户
sudo tee -a /etc/security/limits.conf << EOF
*               hard    nofile          65535
*               soft    nofile          65535
root            hard    nofile          65535
root            soft    nofile          65535
EOF

# Systemd
sudo sed -i '/DefaultLimitNOFILE/c DefaultLimitNOFILE=65535' /etc/systemd/*.conf
sudo 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

参考资料

本作品采用《CC 协议》,转载必须注明作者和本文链接
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 1

设置的值需要调整

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!