题记: 最近需要监控linux下某个目录下的文件变化,网友推荐了inotify.
目录
一 环境
系统环境
软件环境
二 安装
安装前检查
2.源码安装
三 验证
正文
一.环境
1.系统环境
CENTOS 6.6 内核 2.6.32
[root@scripts-1 usr]# lsb_release -a
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.6 (Final)
Release: 6.6
Codename: Final
[root@scripts-1 usr]# cat /proc/version
Linux version 2.6.32-504.el6.x86_64 (mockbuild@c6b9.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) ) #1 SMP Wed Oct 15 04:27:16 UTC 2014
[root@scripts-1 usr]#
2. 软件环境
inotify-tools-3.14
二 安装
2.1 安装前检查
据说内核版本 必须 大于等于2.6.13 (笔者 未验证内核版本小于2.6.13,也未找到官方资料 ,所以是据说)
2. 源码安装
tar -zxvf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
ll
./configure --prefix=/usr
make
make install
三验证
3.1 报错 inotifywait: error while loading shared libraries: libinotifytools.so.0: cannot open shared object file: No such file or directory
[root@scripts-2 inotify-tools-3.14]# inotifywait
inotifywait: error while loading shared libraries: libinotifytools.so.0: cannot open shared object file: No such file or directory
[root@scripts-2 inotify-tools-3.14]#
解决: 执行ldconfig
[root@scripts-2 inotify-tools-3.14]# inotifywait
inotifywait: error while loading shared libraries: libinotifytools.so.0: cannot open shared object file: No such file or directory
[root@scripts-2 inotify-tools-3.14]# ldconfig
[root@scripts-2 inotify-tools-3.14]# inotifywait
No files specified to watch!
[root@scripts-2 inotify-tools-3.14]#
参考资料:
https://github.com/rvoicilas/inotify-tools/wiki
http://www.ibm.com/developerworks/cn/linux/l-ubuntu-inotify/index.html
http://www.infoq.com/articles/inotify-linux-file-system-event-monitoring