gba*_*bag 21 bash tail apache2 tomcat sshd
When I try to tail -f catalina.out, I get the error:
tail: inotify cannot be used, reverting to polling: Too many open files
Run Code Online (Sandbox Code Playgroud)
I tried the answer in this post: Too many open files - how to find the culprit
lsof | awk '{ print $2; }' | sort -rn | uniq -c | sort -rn | head
Run Code Online (Sandbox Code Playgroud)
When I ran the above command, the output was
17 6115
13 6413
10 6417
10 6415
9 6418
9 6416
9 6414
8 6419
4 9
4 8
Run Code Online (Sandbox Code Playgroud)
I don't see any process having 1024 files open. Isn't the number of files open 17,13,10,10,9? Or am I understanding it wrong? And all these were bash,sshd,apache2, tomcat had number 4.
I also did lsof | grep tail | wc -l
which returned 20.
These numbers aren't huge, so why does tail -f catalina.out fail?
Ela*_*son 23
按照http://peter-butkovic.blogspot.com/2013/08/tail-inotify-resources-exhausted.html上的说明为我解决了这个问题
永久解决方案(在重新启动时保留)添加行:
fs.inotify.max_user_watches=1048576
Run Code Online (Sandbox Code Playgroud)
到:
/etc/sysctl.conf
Run Code Online (Sandbox Code Playgroud)
永久固定限制值(即使在重新启动之间)。
然后做一个
sysctl -p
Run Code Online (Sandbox Code Playgroud)
Rad*_*anu 10
我认为这个答案并不完整(它没有说明系统上打开的文件的最大限制)。
打开文件的最大数量有两个限制:
每个进程打开的文件的最大限制。
ulimit -nulimit -n new_limit_number 这是一个命令,用于获取打开多个文件的前 10 个进程:
lsof | awk '{ print $2; }' | sort -rn | uniq -c | sort -rn | head
Run Code Online (Sandbox Code Playgroud)每个系统打开文件的最大限制。
cat /proc/sys/fs/file-maxecho new_limit_number > /proc/sys/fs/file-maxlsof | wc -l小智 7
最有可能的是,你的inotify手表用完了。可能,您正在后台运行一些文件同步工具(例如 Dropbox)?
在 Linux 中,tail -fcommand的内部实现inotify默认使用该机制,以监控文件的变化。如果您已用完所有inotify监视(默认为 8192),则inotify -f必须切换到轮询以检测对该文件的更改。
当然,您可以修改inotify手表的最大数量。
参考:
http : //www.quora.com/How-is-tail-f-implemented
http://peter-butkovic.blogspot.com/2013/08/tail-inotify-resources-exhausted.html
https:// serverfault.com/questions/510708/tail-inotify-cannot-be-used-reverting-to-polling-too-many-open-files
小智 6
sysctl fs.inotify.max_user_instances将获得每个用户的限制inotify。
我经历过,系统范围内的所有限制都足够高,但是默认情况下用户设置通常相对较低,您可以增加它sysctl.conf并重新加载它sysctl -p。