Linux Too many open files
查看系统资源限制信息:
sudo -s -u root -H id
sudo -s lsof | awk '{ print $2 " " $1; }' | sort -rn | uniq -c | sort -rn | head -20
sudo -s ulimit -Sn
sudo -s ulimit -Hn
sudo cat /proc/sys/fs/file-max
sudo -s cat /etc/security/limits.conf
最后当我们尝试$ cat /proc/<processId>/limits
; 我们注意到“打开文件数”仍显示为4096,这是旧值; 虽然对于root来说它显示了更高的值。
最后,我们可以通过修改 /etc/default/tomcat7 [或与您的进程相对应的任何其他文件]并添加以下行来解决此问题:
ulimit -Hn 10000
ulimit -Sn 10000
无需重启系统; 只需重新启动进程,然后检查 cat /proc/<processId>/limits
在ubuntu 16.04下,tomcat的最大文件数受systemd限制,并自动设置为4096.您可以通过运行更改此值
systemctl edit tomcat7
添加以下行:
[Service]
LimitNOFILE=8192
或者你可以自己创建配置:
mkdir /etc/systemd/system/tomcat7.service.d/
nano /etc/systemd/system/tomcat7.service.d/override.conf
之后重新加载tomcat:
服务tomcat7重启
并仔细检查是否正确设置了限制
ps ax | grep tomcat
cat /proc/<processId>/limits
1. 使用以下行修改/etc/systemd/user.conf和/etc/systemd/system.conf(这将负责图形登录):
DefaultLimitNOFILE=65535
2. 使用以下行修改/etc/security/limits.conf(这将负责非GUI登录):
* hard nofile 65535
* soft nofile 65535
root hard nofile 65535
root soft nofile 65535
3. 可选操作,编辑 /etc/pam.d/common-session和/etc/pam.d/common-session-noninteractive 文件并添加以下行到最后:
session required pam_limits.so
4. 重新启动计算机以使更改生效。
No need to change anything in the /etc/security/limits.conf
file, it is ignored if you are using systemd.
(reproducing a modified answer to another question on the network...)
An alternative for those who prefer not to edit the default /etc/systemd/system.conf
and /etc/systemd/user/conf
files:
-
create a new file
/etc/systemd/system.conf.d/limits.conf
with these contents:[Manager] DefaultLimitNOFILE=65535
-
run
systemctl daemon-reexec
as root -
logout and login again
-
check your new limit with
ulimit -n
.
Refer to the systemd-system.conf
manpage for details.
System.IO.IOException: Too Many Open Files (Mono .NET on Ubuntu)
sudo ps -waux | grep mono | grep -v grep | awk '{print $2}' | xargs kill -9
export MONO_MANAGED_WATCHER=disabled
================ End