Debian与其它Linux发行版(如CentOS、Ubuntu)在ulimit配置上的核心差异
Debian的/etc/security/limits.conf文件中,*通配符不匹配root用户,需为root单独设置ulimit值(如root soft nofile 65535);而CentOS等发行版的*通配符可匹配root用户,无需额外配置。
Debian使用systemd时,ulimit的全局默认值需通过/etc/systemd/system.conf(系统级)和/etc/systemd/user.conf(用户级)设置(如DefaultLimitNOFILE=65535);Ubuntu虽也使用systemd,但部分发行版(如Ubuntu 22.04+)可能在/etc/systemd/system.conf.d/下添加自定义配置文件,且默认值更倾向于满足桌面用户需求(如更高的文件打开数)。
Debian默认的ulimit值更保守(如nofile软限制为1024、硬限制为8192),目的是保障系统稳定性与安全性;Ubuntu作为Debian的衍生版,默认值更高(如nofile软限制为1024、硬限制为4096),更贴合桌面用户的多任务需求。
Debian需明确在/etc/pam.d/common-session和/etc/pam.d/common-session-noninteractive中添加session required pam_limits.so,确保limits.conf的设置生效;Ubuntu虽也依赖PAM,但部分版本(如Ubuntu 20.04+)可能默认已包含该配置,无需手动添加。
Debian在某些systemd版本中存在已知bug:即使将DefaultLimitNOFILE设置为infinity,1号进程及其子进程的max open file限制仍可能仅为65536(而非预期的fs.nr_open默认值1048576);而CentOS、Ubuntu等发行版虽也可能受此bug影响,但修复补丁的推送速度更快。
Debian需在/etc/pam.d/common-session-noninteractive中添加pam_limits.so,以确保非交互式登录(如ssh、cron)时ulimit设置生效;Ubuntu的部分版本(如Ubuntu 18.04+)可能将该配置合并到/etc/pam.d/sshd或/etc/pam.d/cron中,简化了非交互式会话的配置流程。