tail:inotify 无法使用,恢复为轮询:打开的文件太多

use*_*577 4 ubuntu ssh tail top

tail: inotify cannot be used, reverting to polling: Too many open files
Run Code Online (Sandbox Code Playgroud)

我在 Ubuntu (AWS ec2) 上运行 apache 和 tomcat 服务器。每当我尝试catalina.out跟踪 tomcat 时,我都会收到太多打开的文件。但是我可以使用 vi 查看它。

在互联网上搜索后,我尝试了以下命令:

lsof | awk '{ print $2; }' | sort -rn | uniq -c | sort -rn | head
Run Code Online (Sandbox Code Playgroud)

结果如下

 17 5650
 17 5178
 13 5972
 10 5976
 10 5974
  9 5977
  9 5975
  9 5973
  8 5978
  4 9
Run Code Online (Sandbox Code Playgroud)

当我运行 lsof 进程 ids 时:5650 是 bash,5178 又是 bash,其他人是 sshd、top 和 apache2。

为什么会有大量 bash、top、sshd 打开文件?如何关闭这些文件?杀死这些进程有什么好处吗?数字会自行减少还是我必须做任何事情?现在一切都按预期工作,只是 tail -f 给了我太多打开的文件。

我经常使用 top 和 ssh 作为服务器。但是他们为什么不发布文件呢?或者我连接了错误的点。

Mic*_*ton 6

可能你的 inotify 手表用完了。默认情况下,它是一个低得离谱的 8192。

通过以下方式检查您的当前值:

sysctl fs.inotify.max_user_watches
Run Code Online (Sandbox Code Playgroud)

然后通过编辑/etc/sysctl.conf或它包含的文件将其更改为更合理的内容,并添加:

fs.inotify.max_user_watches = 524288
Run Code Online (Sandbox Code Playgroud)

(或任何值),然后运行sysctl -p使其生效。

  • 但是,如果我将 max_user_instances 从 128 更改为 256 ,它会起作用。想知道有没有副作用。以及是什么导致它达到极限。 (3认同)