在 Debian(以及大多数 Linux 发行版)上,ulimit 不够通常是指:
open files)太小(默认常是 1024)max user processes)不够too many open files 或 fork: retry: Resource temporarily unavailable下面从原因 → 查看方式 → 解决方法系统说明。
Debian 很多版本默认:
* soft nofile 1024
* hard nofile 1024
这是从 UNIX 时代遗留下来的安全/兼容值,不适合现代高并发服务(Nginx、Redis、Java、Docker 等)。
这是最容易踩坑的地方:
/etc/security/limits.conf结果:
su - user
ulimit -n # 可能是 65535
systemctl start nginx
# 实际仍是 1024
如果登录方式不走 PAM:
crondocker exec就不会应用 limits.conf。
在 Docker / Kubernetes 中:
--ulimit)ulimit -a
cat /proc/<pid>/limits
systemctl show nginx | grep Limit
编辑:
/etc/security/limits.conf
示例:
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
并确保:
/etc/pam.d/common-session
/etc/pam.d/common-session-noninteractive
包含:
session required pam_limits.so
⚠️ 只对 登录 shell 生效
编辑 service:
/etc/systemd/system/nginx.service.d/limits.conf
[Service]
LimitNOFILE=65535
LimitNPROC=65535
然后:
systemctl daemon-reload
systemctl restart nginx
✅ 这是 Debian 10+ 的正确方式
/etc/systemd/system.conf
DefaultLimitNOFILE=65535
DefaultLimitNPROC=65535
重启后对所有服务生效。
docker run --ulimit nofile=65535:65535
或 daemon.json:
{
"default-ulimits": {
"nofile": { "Hard": 65535, "Name": "nofile", "Soft": 65535 }
}
}
❌ 只在 limits.conf 改,但服务是 systemd
❌ 用 ulimit -n 65535 临时改(重启失效)
❌ 在容器里改宿主 ulimit
❌ 以为 root 不受限制(其实也受 Limit 控制)
✅ ulimit -n
✅ /proc/<pid>/limits
✅ systemctl show <service> | grep Limit
✅ 是否 systemd 启动
✅ 是否在容器中
如果你愿意,可以告诉我:
cat /etc/debian_version)我可以直接给你精确配置。