打开的文件太多 - 初始化inotify失败:已达到总inotify实例数量的用户限制

35

我该如何解决以下问题?我正在使用Compass。

   Too many open files - Failed to initialize inotify: the user limit on the total number of inotify instances has been reached.
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/rb-inotify-0.9.5/lib/rb-inotify/notifier.rb:64:in `initialize'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/adapters/linux.rb:66:in `initialize_worker'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/adapter.rb:87:in `initialize'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/adapters/linux.rb:31:in `initialize'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/adapter.rb:226:in `works?'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/adapter.rb:190:in `usable_and_works?'
org/jruby/RubyEnumerable.java:1425:in `all?'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/adapter.rb:190:in `usable_and_works?'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/adapter.rb:57:in `select_and_initialize'
org/jruby/RubyArray.java:1613:in `each'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/adapter.rb:55:in `select_and_initialize'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/listener.rb:291:in `initialize_adapter'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/listener.rb:283:in `setup'
    /home/rmack/Downloads/compass.app/lib/ruby/jruby/listen-1.3.1-patched/lib/listen/listener.rb:65:in `start!'
    /home/rmack/Downloads/compass.app/lib/ruby/compass_1.0/sass-3.4.13/lib/sass/plugin/compiler.rb:405:in `listen_to'
    /home/rmack/Downloads/compass.app/lib/ruby/compass_1.0/sass-3.4.13/lib/sass/plugin/compiler.rb:338:in `watch'
    /home/rmack/Downloads/compass.app/lib/ruby/compass_1.0/compass-1.0.3/lib/compass/sass_compiler.rb:46:in `watch!'
    /home/rmack/Downloads/compass.app/lib/ruby/compass_1.0/compass-1.0.3/lib/compass/commands/watch_project.rb:41:in `perform'
file:/home/rmack/Downloads/compass.app/compass-app.jar!/app_watcher.rb:12:in `watch!'
file:/home/rmack/Downloads/compass.app/compass-app.jar!/ui/tray.rb:447:in `watch'
6个回答

70
对于Linux系统

检查当前的max_user_instances值:

$ cat /proc/sys/fs/inotify/max_user_instances

增加该值:

$ echo 256 | sudo tee /proc/sys/fs/inotify/max_user_instances

为了使这个改变永久生效,你可以随时在/etc/sysctl.conf中添加一行。
fs.inotify.max_user_instances = 256

如果您的系统有一个/etc/sysctl.d目录,您最好将自定义设置放在一个单独的文件中,例如/etc/sysctl.d/60-local.conf

即使在Debian上运行sudo echo 256 > /proc/sys/fs/inotify/max_user_instances,我仍然收到“权限被拒绝”的错误。@gcs_dev的解决方案对我有用(sudo sh -c ...)。 - 0__
2
很奇怪,该命令只能从当前的 shell(例如 bash)切换到 sh。在 Debian 上,您可以尝试使用 sudo sysctl fs.inotify.max_user_instances=256 - Tombart
嘿,@0__,你的sudo不起作用是因为你正在以root身份运行“echo 256”,然后尝试将重定向作为当前用户执行,但该用户无法写入目标。 - Bill McGonigle
我也遇到了“permission denied”错误,但是我使用了“sudo su”命令并成功执行了它。 - Merey Nurlan
1
要以root身份向文件写入内容,您需要在实际执行写入的命令的第二部分使用sudo。 可以使用tee代替>,并使用以下方式调用它:echo 256 | sudo tee /proc/sys/fs/inotify/max_user_instances - Dave Yarwood
运行得非常好。谢谢。我在使用IntelliJ进行sbt构建时遇到了这个问题。 - Dinesh Raj

6
通常这是 Linux 配置问题。在 `/etc/security/limits.conf` 中增加打开文件数的限制:增加打开文件数的限制
如果你使用的是 Mac OS,那么你应该使用 sysctl。在 `/etc/sysctl.conf` 中添加如下内容:设置最大文件数
kern.maxfiles=your new value kern.maxfilesperproc=your new value

2
这对我有帮助,但增加这个的任何缺点吗? - Henkie85

4

2

在Ubuntu 22.04上,它无法正常工作:

sudo sh -c 'echo 256 > /proc/sys/fs/inotify/max_user_instances'

如果想要临时更改它,必须使用以下方法:

sudo sysctl fs.inotify.max_user_instances=8192

之前的评论是正确的:

获取当前值:

cat /proc/sys/fs/inotify/max_user_instances

为了永久保存它,请添加这行代码:
fs.inotify.max_user_instances = 256

使用该命令:

sudo vi /etc/sysctl.conf

0
解决方案: 我增加了max_user_watches、max_queued_events和max_user_instances。
echo 999999 | sudo tee -a /proc/sys/fs/inotify/max_user_watches

echo 999999 | sudo tee -a /proc/sys/fs/inotify/max_queued_events

echo 999999 | sudo tee -a /proc/sys/fs/inotify/max_user_instances

0

正如其他评论所述,您可以尝试查找与文件系统不正确工作的应用程序。

但在某些情况下,只有一些应用程序(在我的情况下是Felix OSGI缓存)打开了太多文件,而限制太低。

然后打开/etc/security/limits.conf并添加用户或组的限制行,例如:

dmatej          soft    nofile          10000

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接