inotify监听的配置
来源:互联网 发布:手机朗读软件 编辑:程序博客网 时间:2024/06/05 05:12
原文: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。
三、下载安装
四、查看inotify默认参数
五、修改inotify参数
1、命令修改
2、文件修改
3、参数说明
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
使用方法和参数说明:
0 0
- inotify监听的配置
- ubuntu rsync inotify 配置
- rsync+inotify配置
- inotify参数配置
- inotify+rsync安装配置
- inotify+rsync安装配置
- inotify+rsync安装配置
- rsync+inotify配置
- inotify配置使用详解
- rsync+inotify同步的编译安装与配置
- 【实时文件同步】rsync+inotify-tools的安装与配置
- 安装inotify-tools,用inotifywait命令监听文件或目录的访问信息
- 安装inotify-tools,用inotifywait命令监听文件或目录的访问信息
- 安装inotify-tools,用inotifywait命令监听文件或目录的访问信息
- CentOS下(rsync+inotify)监听式实现服务器间的备份实时同步
- 事务监听的配置
- Oracle的监听配置
- oracle监听的配置
- 在Jeston TX1上进行ROS配置和导航包测试
- 安装 Apache 出现 <OS 10013> 以一种访问权限不允许的方式做了一个访问套接字的尝试
- Android Studio 新建或者导入项目一直卡在 building “name” gradle project info解决思路
- (转)黄金交易革命即将到来?区块链技术让你像刷卡一样“刷黄金”
- 日常实用oracle SQL
- inotify监听的配置
- 平衡二叉树(AVL)各种操作详细分析
- Jupyter Notebook 的快捷键
- NYOJ--2--括号配对问题
- POJ
- Mysql索引介绍及常见索引类别(主键索引、唯一索引、普通索引、全文索引、组合索引)的区别
- CSU 1030 素数槽
- HDU 1195 Open the Lock
- 获得训练集和XML通过opencv自带程序opencv_createsamples.exe&opencv_traincascade.exe的问题