您的位置:首页 > 运维架构 > Linux

使用inotify-tools监控Linux下记录文件及目录访问

2016-06-04 17:16 671 查看
1、下载

wget --no-check-certificate http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz

 

2、环境预安装

yum install
gcc

 

3、编译

tar zxf inotify-tools-3.14.tar.gz

cd inotify-tools-3.14

./configure

make

make install

 

4、一些小处理

如果是32位系统

ln -s /usr/local/lib/libinotifytools.so.0 /usr/lib/libinotifytools.so.0

如果是64位系统

ln -s /usr/local/lib/libinotifytools.so.0 /usr/lib64/libinotifytools.so.0

 

5、无论32或者64位系统都执行
echo 104857600 > /proc/sys/fs/inotify/max_user_watches
echo 'echo 104857600 > /proc/sys/fs/inotify/max_user_watches' >> /etc/rc.local 
 
6、设置自启动
vi /etc/rc.local
加入下面的代码
/usr/local/bin/inotifywait -m -r -d -o/var/log/change.log --timefmt '%F %T' --format '%T %w%f %e'  -e close_write -e create /usr/local/test

其中/var/log/change.log是日志路径,/usr/local/test是监控的网站路径
reboot重启生效
 
 
7、直接使用方法

inotifywait -m -r -d -o/var/log/change.log --timefmt '%F %T' --format '%T %w%f %e'  -e close_write -e create /home/www

其中/var/log/change.log是日志路径,/home/www是监控的网站路径
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shell linux脚本