inotify监听的配置
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
免费下载资源
·
原文:http://blog.csdn.net/god_wot/article/details/50448814
Linux内核从2.6.13开始,引入了inotify机制。通过intofity机制,能够对文件系统的变化进行监控,如对文件进行创建、删除、修改等操作,可以及时通知应用程序进行相关事件的处理。这种响应处理机制,避免了频繁的文件轮询任务,提高了任务的处理效率。
一、检查系统内核版本
[root@iZ25w1kdi5zZ ~]# uname -a
Linux iZ25w1kdi5zZ 2.6.32-431.23.3.el6.x86_64 #1 SMP Thu Jul 31 17:20:51 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
二、检查系统是否支持inotify
[root@iZ25w1kdi5zZ ~]# ls -lsart /proc/sys/fs/inotify
total 0
0 dr-xr-xr-x 0 root root 0 Sep 19 09:38 ..
0 -rw-r--r-- 1 root root 0 Jan 1 13:51 max_user_watches
0 -rw-r--r-- 1 root root 0 Jan 1 13:51 max_user_instances
0 -rw-r--r-- 1 root root 0 Jan 1 13:51 max_queued_events
0 dr-xr-xr-x 0 root root 0 Jan 1 13:51 .
如果出现上面结果说明系统支持inotify。
三、下载安装
1、命令修改
max_user_instances:每个用户创建inotify实例最大值
max_queued_events:inotify队列最大长度,如果值太小,会出现错误,导致监控文件不准确
max_user_watches:要知道同步的文件包含的目录数,可以用:[root@iZ25w1kdi5zZhome]# find /home/rain -type d|wc -l 统计,必须保证参数值大于统计结果(/home/rain为同步文件目录)。
六、创建实时监控脚本
[root@iZ25w1kdi5zZ scripts]# vi ffile
/home/rain/
@/home/rain/cache
[root@iZ25w1kdi5zZ scripts]# chmod a+x ./inotify_start.sh启动:
[root@iZ25w1kdi5zZ scripts]# ./inotify_start.sh
[root@iZ25w1kdi5zZ rain]# cat /tmp/rsync.log
16-01-02 16:21 yy CREATE,ISDIR
七、附录
1、inotifywait
使用方法和参数说明:
[root@iZ25w1kdi5zZ bin]# ./inotifywait -h
inotifywait 3.14
Wait for a particular event on a file or set of files.
Usage: inotifywait [ options ] file1 [ file2 ] [ file3 ] [ ... ]
Options:
-h|--help Show this help text.
@<file> Exclude the specified file from being watched.
--exclude <pattern>
Exclude all events on files matching the
extended regular expression <pattern>.
--excludei <pattern>
Like --exclude but case insensitive.
-m|--monitor Keep listening for events forever. Without
this option, inotifywait will exit after one
event is received.
-d|--daemon Same as --monitor, except run in the background
logging events to a file specified by --outfile.
Implies --syslog.
-r|--recursive Watch directories recursively.
--fromfile <file>
Read files to watch from <file> or `-' for stdin.
-o|--outfile <file>
Print events to <file> rather than stdout.
-s|--syslog Send errors to syslog rather than stderr.
-q|--quiet Print less (only print events).
-qq Print nothing (not even events).
--format <fmt> Print using a specified printf-like format
string; read the man page for more details.
--timefmt <fmt> strftime-compatible format string for use with
%T in --format string.
-c|--csv Print events in CSV format.
-t|--timeout <seconds>
When listening for a single event, time out after
waiting for an event for <seconds> seconds.
If <seconds> is 0, inotifywait will never time out.
-e|--event <event1> [ -e|--event <event2> ... ]
Listen for specific event(s). If omitted, all events are
listened for.
Exit status:
0 - An event you asked to watch for was received.
1 - An event you did not ask to watch for was received
(usually delete_self or unmount), or some error occurred.
2 - The --timeout option was given and no events occurred
in the specified interval of time.
Events:
access file or directory contents were read
modify file or directory contents were written
attrib file or directory attributes changed
close_write file or directory closed, after being opened in
writeable mode
close_nowrite file or directory closed, after being opened in
read-only mode
close file or directory closed, regardless of read/write mode
open file or directory opened
moved_to file or directory moved to watched directory
moved_from file or directory moved from watched directory
move file or directory moved to or from watched directory
create file or directory created within watched directory
delete file or directory deleted within watched directory
delete_self file or directory was deleted
unmount file system containing file or directory unmounted
2、inotifywatch
使用方法和参数说明:
GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
已为社区贡献2条内容
所有评论(0)