如何设置全局无文件限制以避免“许多打开的文件"错误? [英] How to set a global nofile limit to avoid "many open files" error?

查看:14
本文介绍了如何设置全局无文件限制以避免“许多打开的文件"错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 websocket 服务.有错误是很奇怪的:打开的文件太多",但我已经设置了系统配置:

I have a websocket service. it's strage that have error:"too many open files", but i have set the system configure:

/etc/security/limits.conf
*               soft    nofile          65000
*               hard    nofile          65000

/etc/sysctl.conf
net.ipv4.ip_local_port_range = 1024 65000

ulimit -n
//output 6500

所以我认为我的系统配置是正确的.

So i think my system configure it's right.

我的服务由主管管理,可能有主管限制吗?

My service is manage by supervisor, it's possible supervisor limits?

检查进程由主管启动:

cat /proc/815/limits
Max open files            1024                 4096                 files 

检查进程手动启动:

cat /proc/900/limits
Max open files            65000                 65000                 files 

原因是使用了主管管理服务.如果我重新启动主管并重新启动子进程,则最大打开文件"正常(65000)但在重新启动系统主管时会自动启动错误(1024).

The reason is used supervisor manage serivce. if i restart supervisor and restart child process, it's "max open files" ok(65000) but wrong(1024) when reboot system supervisor automatically start.

可能是supervisor启动级别太高导致supervisor启动时系统配置不工作?

May be supervisor start level is too high and system configure does not work when supervisor start?

系统:ubuntu 12.04 64位

system: ubuntu 12.04 64bit

不是supervisor的问题,系统重启后自动启动的所有进程都没有使用system configure(max open files=1024),但是重启就可以了.

It's not supervisor problem, all process auto start after system reboot are not use system configure(max open files=1024), but restart it's ok.

更新

也许问题是:

现在的问题是,如何设置全局 nofile 限制,因为我不想在我需要的每个 upstart 脚本中设置 nofile 限制.

Now the question is, how to set a global nofile limit because i don't want to set nofile limit in every upstart script which i need.

推荐答案

通过为文件中的所有用户设置限制来修复此问题:

Fixed this issue by setting the limits for all users in the file :

$ cat /etc/security/limits.d/custom.conf
* hard nofile 550000
* soft nofile 550000

设置限制后重新启动服务器.

REBOOT THE SERVER after setting the limits.

非常重要:/etc/security/limits.d/ 文件夹包含用户特定的限制.就我而言,hadoop 2 (cloudera) 相关限制.这些用户特定限制将覆盖全局限制,因此如果您的限制没有被应用,请务必检查文件夹 /etc/security/limits.d/ 和文件中的用户特定限制代码>/etc/security/limits.conf.

VERY IMPORTANT: The /etc/security/limits.d/ folder contains user specific limits. In my case hadoop 2 (cloudera) related limits. These user specific limits would override the global limits so if your limits are not being applied, be sure to check the user specific limits in the folder /etc/security/limits.d/ and in the file /etc/security/limits.conf.

注意:设置用户特定的限制是所有情况下的方法.应避免设置全局 (*) 限制.在我的情况下,它是一个孤立的环境,只需要从我的实验中消除文件限制问题.

CAUTION: Setting user specific limits is the way to go in all cases. Setting the global (*) limit should be avoided. In my case it was an isolated environment and just needed to eliminate file limits issue from my experiment.

希望这可以为某人节省一些头发 - 因为我花了太多时间将头发一块一块地拉出来!

Hope this saves someone some hair - as I spent too much time pulling my hair out chunk by chunk!

这篇关于如何设置全局无文件限制以避免“许多打开的文件"错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆