Ult*_*der 247 linux kernel inotify
我目前在 linux 机器上遇到问题,作为 root 我有命令返回错误,因为已达到 inotify 监视限制。
# tail -f /var/log/messages
[...]
tail: cannot watch '/var/log/messages': No space left on device
# inotifywatch -v /var/log/messages
Establishing watches...
Failed to watch /var/log/messages; upper limit on inotify watches reached!
Please increase the amount of inotify watches allowed per user via '/proc/sys/fs/inotify/max_user_watches'.`
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索了一下,我发现的每个解决方案都是通过以下方式增加限制:
sudo sysctl fs.inotify.max_user_watches=<some random high number>
Run Code Online (Sandbox Code Playgroud)
但我无法找到任何有关提高该价值的后果的信息。我猜默认内核值的设置是有原因的,但它似乎不适用于特定用途。(例如,当使用带有大量文件夹的 Dropbox 或监控大量文件的软件时)
所以这里是我的问题:
tsh*_*ang 345
提高该值是否安全,过高的值会产生什么后果?
是的,提高该价值是安全的,以下是可能的成本 [来源]:
要检查 inotify 手表的最大数量:
cat /proc/sys/fs/inotify/max_user_watches
Run Code Online (Sandbox Code Playgroud)
设置 inotify 手表的最大数量
暂时地:
sudo sysctl fs.inotify.max_user_watches=以您的首选值运行。永久(更详细的信息):
fs.inotify.max_user_watches=524288您的 sysctl 设置。根据您的系统,它们可能位于以下位置之一:
/etc/sysctl.conf/etc/sysctl.d/,例如/etc/sysctl.d/40-max-user-watches.confsysctl -p(Debian/RedHat) 或sysctl --system(Arch)检查是否已达到 inotify 手表的最大数量:
在任何旧文件上tail与-f(follow) 选项一起使用,例如tail -f /var/log/dmesg: - 如果一切正常,它将显示最后 10 行并暂停;使用 Ctrl-C 中止 - 如果您不在手表中,它将因这个有点神秘的错误而失败:
尾巴:无法观看“/var/log/dmsg”:设备上没有剩余空间
查看什么用完了 inotify 手表
find /proc/*/fd -lname anon_inode:inotify |
cut -d/ -f3 |
xargs -I '{}' -- ps --no-headers -o '%p %U %c' -p '{}' |
uniq -c |
sort -nr
Run Code Online (Sandbox Code Playgroud)
第一列表示的inotify FDS的数目(未虽然手表的数量)和第二个显示的该过程的PID [来源:1,2 ]。
| 归档时间: |
|
| 查看次数: |
167375 次 |
| 最近记录: |