在 Debian(以及大多数 Linux 发行版)里,ulimit 设置重启后是否会重置,取决于你是怎么设置的。
ulimit 命令设置ulimit -n 65535
✅ 重启后一定会重置
原因:
ulimit 是 shell 级别的进程限制~/.bashrc / ~/.profileulimit -n 65535
✅ 重启后“不会自动全局生效”,但登录后会生效
限制:
/etc/security/limits.conf* soft nofile 65535
* hard nofile 65535
✅ 重启后仍然有效(推荐方式)
前提:
示例:
# 修改后重新登录
ulimit -n
如果你的程序是 systemd 服务:
[Service]
LimitNOFILE=65535
❗ limits.conf 对 systemd 服务无效
需要:
# /etc/systemd/system.conf
DefaultLimitNOFILE=65535
然后:
systemctl daemon-reexec
sysctl -w fs.file-max=100000
✅ 重启会失效
✅ 写入 /etc/sysctl.conf 后重启仍生效
| 设置方式 | 重启是否保留 | 生效范围 |
|---|---|---|
ulimit 命令 |
❌ 否 | 当前 shell |
.bashrc |
⚠️ 登录后 | 当前用户 |
limits.conf |
✅ 是 | 登录用户 |
| systemd Limit | ✅ 是 | 服务 |
| sysctl | ❌(不写文件) | 系统级 |
/etc/security/limits.confLimit*ulimit 命令持久化如果你愿意,可以告诉我:
我可以给你精确配置示例。