JUST DO IT ~

我只想当个程序员

too many open files

* too many open files 

层次上:
1.修改系统级限制. (/etc/sysctl.conf)
2.修改用户启动shell限制.( /etc/security/limits.conf )
3.修改当前回话限制. (有可能无效或者因为系统限制未修改.)(ulimited )
4.如果已经启动的程序,修复那么需要调用系统api RLIM_INFINITY.

如果1和2步骤都做的好,根本不需要3和4.

1,系统内核限制
vi /etc/sysctl.conf
添加:
fs.file-max = 102400
sysctl -p

临时方案:
sysctl -w fs.file-max=10240

2,针对用户的限制
cat /etc/security/limits.conf 
vi  /etc/security/limits.conf
*  soft nofile 102400
*  hard nofile 102400
查看某一个进程的限制
cat /proc/815/limits

bash_profile启动进程脚本中加入:
ulimit -f unlimited
ulimit -t unlimited
ulimit -v unlimited
ulimit -u 65535
ulimit -m unlimited
ulimit -u 65535
很可能会执行出结果:
ulimit: open files: cannot modify limit: Operation not permitted
ulimit: max locked memory: cannot modify limit: Operation not permitted

很可能 security-limits.conf 未设定或者设定的太小了.
大杀器:
sudo sh -c "ulimit -n 65535 && exec su $LOGNAME"   
这句话可能不会执行.bash_profile需要手工执行以下.
另外这句话还要exit 2次.

fork出的子进程,资源限制都是父进程那里继承来的.
ulimit 只是对会话有效.
如果不能关服务程序,只能动态需改.通过C程序.

ulimit 并不是一个命令,是一个shell内部的指令.
sudo 是一个命令.所以无法执行.sudo ulimit 
当前的shell被新shell覆盖掉了.新的shell含有ulimit.
要exit 2次.
http://stackoverflow.com/questions/17483723/command-not-found-when-using-sudo-ulimit


参考:

bash内建的功能.
http://www.gnu.org/software/bash/manual/bashref.html#Bourne-Shell-Builtins
一次「Too many open files」故障
http://huoding.com/2015/08/02/460   
动态修改运行中进程的 rlimit
http://xiezhenye.com/2013/02/%E5%8A%A8%E6%80%81%E4%BF%AE%E6%94%B9%E8%BF%90%E8%A1%8C%E4%B8%AD%E8%BF%9B%E7%A8%8B%E7%9A%84-rlimit.html

动态修改运行中进程的 ulimit
http://blog.chinaunix.net/uid-20662820-id-3928094.html

中文注释ulimit具体项目
http://man.linuxde.net/ulimit

linux的ulimit限制详解 --有测试系统代码
http://www.dbafree.net/?p=967

posted on 2015-12-10 10:39 小高 阅读(302) 评论(0)  编辑  收藏 所属分类: Linux


只有注册用户登录后才能发表评论。


网站导航:
 

导航

<2015年12月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

统计

常用链接

留言簿(3)

随笔分类(352)

收藏夹(19)

关注的blog

手册

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜