如何在Linux中监视整个目录树的更改? [英] How to monitor a complete directory tree for changes in Linux?

查看:130
本文介绍了如何在Linux中监视整个目录树的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何监控整个目录树中Linux( ext3 文件系统)的变化?

How can I monitor a whole directory tree for changes in Linux (ext3 file system)?

当前目录在大约 3,000个子目录中包含大约半百万个文件,分为三个目录级别.

Currently the directory contains about half a million files in about 3,000 subdirectories, organized in three directory levels.

这些文件大多是小文件(<1kb,有的则是100 kb以下的文件).这是一种队列,我需要知道在发生这种情况的5-10秒内何时创建,删除文件或修改其内容.

Those are mostly small files (< 1kb, some few up to 100 kb). It's a sort of queue and I need to know when files are being created, deleted or their content modified within 5-10 seconds of that happening.

我知道有 intify 并进行排序,但是AFAIK它们仅监视单个目录,这意味着我需要3000个inotify句柄-比单个进程允许的通常1024个句柄更多.还是我错了?

I know there is inotify and sorts, but AFAIK they only monitor a single directory, which means I would need 3,000 inotify handles in my case - more than the usual 1024 handles allowed for a single process. Or am I wrong?

以防Linux系统无法告诉我我需要什么:也许有一个 FUSE 项目可以模拟一个文件系统(在真实文件系统上复制所有文件访问权限)并分别记录所有修改(无法进行修改)?

In case the Linux system can't tell me what I need: perhaps there is a FUSE project that simulates a file system (replicating all file accesses on a real file system) and separately logs all modifications (couldn't fine one)?

推荐答案

据我所知,除了在每个目录上递归设置inotify监视外,没有其他方法.

To my knowledge, there's no other way than recursively setting an inotify watch on each directory.

也就是说,您不会用完文件描述符,因为inotify不必保留fd来监视文件或目录(其前身dnotify确实受到此限制). inotify改为使用监视描述符".

That said, you won't run out of file descriptors because inotify does not have to reserve an fd to watch a file or a directory (its predecessor, dnotify, did suffer from this limitation). inotify uses "watch descriptors" instead.

根据 inotifywatch 的文档,默认限制为8192个监视描述符,您可以将其增加将新值写入/proc/sys/fs/inotify/max_user_watches.

According to the documentation for inotifywatch, the default limit is 8192 watch descriptors, and you can increase it by writing the new value to /proc/sys/fs/inotify/max_user_watches.

这篇关于如何在Linux中监视整个目录树的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆