`
caiying0504
  • 浏览: 334045 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

linux下Too many open files的解决方案

阅读更多
比较流行的发行版本,比如Debian/Ubuntu/Arch Linux/Gentoo的shell session限制都是1024。

大多数Linux发行版本中,正常情况下session中max open files数限制为1024,对于Weblogic Server部署过程来说太小了,必须增大。

临时解决方法:
只对某个Terminal中的session起作用,用以下命令增加该数值。
ulimit -n 2048
继续在此session中启动obpmadmcenter来配置directory和创建新的WLS domain用于部署bpm。如果选择修改一个已经存在的WLS domain的话,在执行启动脚本的Terminal session中需要用同样的方法增加该数值,否则多数会得到同样的错误。
ulimit -a
可以用来查看当前session user的各种限制,当然包括修改过的数值。


永久性解决方法:
1. 修改/etc/security/limits.conf (root)
增加如下
$user hard nofile 2048
$user是用来启动WLS的用户。
2048是建议的数值,若遇到同样问题可能需要再次增加。

或者干脆用*表示所有用户:

* soft nofile 2048
* hard nofile 4096


2. 其他来自Debian GNU/Linux官方文档和Oracle Technology Network的解决方法,直接修改内核参数,无须重启系统。
sysctl -w fs.file-max 65536
或者
echo "65536" > /proc/sys/fs/file-max
两者作用是相同的,前者改内核参数,后者直接作用于参数对应的虚拟文件系统(procfs, psuedo file system)上对应的文件而已。
可以用以下的命令查看新的限制
sysctl -a | grep fs.file-max
或者
cat /proc/sys/fs/file-max

修改内核参数
/etc/sysctl.conf
echo "fs.file-max=65536" >> /etc/sysctl.conf
sysctl -p

查看当前file handles使用情况:

sysctl -a | grep fs.file-nr

或者

cat /proc/sys/fs/file-nr
825 0 65536


另外一个命令:
lsof | wc -l
有点让我困惑的是,以上两个命令获得的结果总是不相同的;-(

此外,用sysctl来修改内核参数fs.file-max和用ulimit的区别,我花了不少时间研究,讨教了Linux/FreeBSD/Solaris/OpenSolaris老鸟Jockey同学,得到点拨之后终于基本弄清楚原委了。

基本上优先级:
soft limit < hard limit < kernel < 实现最大file descriptor数采用的数据结构所导致的限制

The Linux kernel provides the getrlimit and setrlimit system calls to get and set resource limits per process. Each resource has an associated soft and hard limit. The soft limit is the value that the kernel enforces for the corresponding resource. The hard limit acts as a ceiling for the soft limit: an unprivileged process may only set its soft limit to a value in the range from 0 up to the hard limit, and (irreversibly) lower its hard limit. A privileged process (one with the CAP_SYS_RESOURCE capability) may make arbitrary changes to either limit value.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics