增加Ubuntu/Upstart的最大打开文件(initctl)

All*_*n A 13 ubuntu file-descriptor upstart

这是在Ubuntu 12.04.3 LTS服务器上.

我已将以下内容添加到/etc/security/limits.conf(我的Golang进程以root身份运行):

*      hard   nofile   50000
*      soft   nofile   50000
root   hard   nofile   50000
root   soft   nofile   50000
Run Code Online (Sandbox Code Playgroud)

我在/etc/pam.d/common-session中添加了以下内容

session required pam_limits.so
Run Code Online (Sandbox Code Playgroud)

我已将以下内容添加到/etc/sysctl.conf中:

fs.file-max = 50000
Run Code Online (Sandbox Code Playgroud)

然而当我cat/proc/{PID} /限制时,我得到:

Limit                     Soft Limit           Hard Limit           Units     
Max open files            1024                 4096                 files     
Run Code Online (Sandbox Code Playgroud)

只有当我从Upstart通过sudo initctl start service_name启动进程才会发生这种情况.如果我自己开始这个过程,它会确认我的设置.

我该如何解决?

All*_*n A 18

这需要添加到您的Upstart脚本中才能工作:

limit nofile 50000 50000
Run Code Online (Sandbox Code Playgroud)

"根据设计,新贵不会在/etc/security/limits.conf中查看系统作业.PAM设置仅适用于用户会话,而不适用于系统服务." 来自 https://bugs.launchpad.net/ubuntu/+source/upstart/+bug/938669

资料来源:

https://github.com/saltstack/salt/issues/5323

http://bryanmarty.com/blog/2012/02/10/setting-nofile-limit-upstart/