当前位置: 首页 > 工具软件 > inotify-tools > 使用案例 >

linux_6.5_install_inotify-tools-3.13

劳英华
2023-12-01

–=安装的前提是rsync服务已经安装完成,客户端可以拉取和推送数据成功==

一、安装前检查
–==============从内核和目录里面查看是否支持inotify

[root@rsync_client ~]# uname -r
2.6.32-431.el6.x86_64 //要求2.6.13以上的内核

[root@rsync_client ~]# ll /proc/sys/fs/inotify/
total 0
-rw-r–r-- 1 root root 0 Jul 7 14:24 max_queued_events //监控时间队列
-rw-r–r-- 1 root root 0 Jul 7 14:24 max_user_instances //最多监控实例数
-rw-r–r-- 1 root root 0 Jul 7 14:24 max_user_watches //每个实例最多监控的文件数

[root@rsync_client ~]# vim /etc/sysctl.conf //末尾添加三行内容

[root@rsync_client ~]# cat >>/etc/sysctl.conf<< EOF

fs.inotify.max_queued_events = 32768
fs.inotify.user_instances = 1024
fs.inotify.max_user_watches = 900000000
EOF

[root@rsync_client ~]# sysctl -p //使配置生效

–================检查是否有安装inotify 如果没有就安装
rpm -qa inotify-tools

二、安装
–==inotify工具下载,源码包inotify-tools-3.13.tar.gz=
https://sourceforge.net/projects/inotify-tools/files/latest/download
[root@rsync_client software]# tar -zxf inotify-tools-3.13.tar.gz
[root@rsync_client software]# echo $?
0
[root@rsync_client software]# ls
inotify-tools-3.13 inotify-tools-3.13.tar.gz
[root@rsync_client software]# cd inotify-tools-3.13
[root@rsync_client inotify-tools-3.13]# ls
aclocal.m4 ChangeLog config.h.in configure COPYING INSTALL libinotifytools Makefile.am man NEWS src
AUTHORS config.guess config.sub configure.ac depcomp install-sh ltmain.sh Makefile.in missing README
[root@rsync_client inotify-tools-3.13]# ./configure --prefix=/usr/local/inotify-tools
[root@rsync_client inotify-tools-3.13]# echo $?
0
[root@rsync_client inotify-tools-3.13]# make && make install
[root@rsync_client inotify-tools-3.13]# echo $?
0

[root@rsync_client inotify-tools-3.13]# ln -s /usr/local/inotify-tools/ /usr/local/inotify
[root@rsync_client inotify-tools-3.13]# ll /usr/local
total 44
drwxr-xr-x. 2 root root 4096 Sep 3 2018 bin
drwxr-xr-x. 2 root root 4096 Jun 28 2011 etc
drwxr-xr-x. 2 root root 4096 Jun 28 2011 games
drwxr-xr-x. 2 root root 4096 Jun 28 2011 include
lrwxrwxrwx. 1 root root 25 Jul 7 15:24 inotify -> /usr/local/inotify-tools/

三、inotify测试

–==========监控目录并进行同步
[root@rsync_client script]# cat inotify1.sh
#!/bin/bash
host=192.168.16.66
src=/data
dest=lbw
user=rsync_backup
rsync_passfile=/etc/rsync.password
inotify_home=/usr/local/inotify/

#judge
if [ ! -e “KaTeX parse error: Expected 'EOF', got '\ ' at position 8: src" ] \̲ ̲|| [ ! -e "rsync_passfile” ]
|| [ ! -e “${inotify_home}/bin/inotifywait” ]
|| [ ! -e “/usr/bin/rsync” ];
then
echo “check file and folder”
exit 9
fi

${inotify_home}/bin/inotifywait -mrq --timefmt ‘%d/%m/%y %H:%M’ --format ‘%T %w%f’ -e create,close_write,delete,attrib $src
| while read file
do
cd $src && rsync -aruz -R --delete ./ --timeout=100 $user@$host::$dest --password-file=${rsync_passfile}
done
exit 0

[root@rsync_client data]# touch {a…z}
[root@rsync_client data]# ls
a b c d e f g h i j k l m n o p q r s t u v w x y z
[root@rsync_server data]# ls
a b c d e f g h i j k l m n o p q r s t u v w x y z

 类似资料: