远程同步二:rsync+inotify实时同步

续远程同步一:

http://crushlinux.blog.51cto.com/2663646/1272990


A机器上的操作:192.168.200.101:

[root@crushlinux1 ~]# cat /proc/sys/fs/inotify/max_queued_events
16384
[root@crushlinux1 ~]# cat /proc/sys/fs/inotify/max_user_instances
128
[root@crushlinux1 ~]# cat /proc/sys/fs/inotify/max_user_watches
8192
[root@crushlinux1 ~]# vi /etc/sysctl.conf
fs.inotify.max_queued_events = 16384
fs.inotify.max_user_instances = 1024             
fs.inotify.max_user_watches = 1048576
[root@crushlinux1 ~]# sysctl -p
[root@crushlinux1 ~]# tar zxvf inotify-tools-3.14.tar.gz
root@crushlinux1 ~]# cd inotify-tools-3.14
[root@crushlinux1 inotify-tools-3.14]# ./configure
[root@crushlinux1 inotify-tools-3.14]# make && make install
[root@crushlinux1 inotify-tools-3.14]# inotifywait -mrq -e modify,create,move,delete /var/www/html/
/var/www/html/
/var/www/html/ CREATE,ISDIR a
/var/www/html/ CREATE,ISDIR b
另一个终端:
[root@crushlinux1 ~]# mkdir /var/www/html/a
[root@crushlinux1 ~]# mkdir /var/www/html/b
[root@crushlinux1 ~]# vi inotify_rsync.sh
#!/bin/bash
INOTIFY_CMD="inotifywait -mrq -e modify,create,attrib,move,delete /var/www/html/"
RSYNC_CMD="rsync -azH --delete /var/www/html/ [email protected]:/var/www/html"
$INOTIFY_CMD | while read DIRECTORY EVENT FILE
do
        if [ $(pgrep rsync | wc -l) -le 0 ]
        then
                $RSYNC_CMD
        fi
done
[root@crushlinux1 ~]# chmod +x inotify_rsync.sh
[root@crushlinux1 ~]# echo "/bin/bash /root/inotify_rsync.sh" /etc/rc.local
[root@crushlinux1 ~]# cat /etc/rc.local


本文出自 “Crushlinux” 博客,转载请与作者联系!

你可能感兴趣的:(远程同步)