一、服务节点安装inotify-tools。
确保系统后以下输出=>
[root@xxxx]# ll /proc/sys/fs/inotify/total 0-rw-r--r-- 1 root root 0 Aug 23 20:02 max_queued_events-rw-r--r-- 1 root root 0 Aug 23 20:02 max_user_instances-rw-r--r-- 1 root root 0 Aug 23 20:02 max_user_watches
(1)yum -y install inotify-tools.x86_64
(2)配置server端的inotify监测脚本
<1>cat /opt/zkrsync/rsyncfile.sh
#!/bin/bashhost_pubbak=10.0.138.136src=/data/zookeeperdest_pubbak=zkpubuser=root/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,delete,create,attrib $src \| while read filedo/bin/rsync -vzrtopg --delete --progress $src $user@$host_pubbak::$dest_pubbakecho "${$(date +%Y%m%d_%H%M%S)} ${files} was rsynced" >> /tmp/rsync.log 2>&1done
sh /opt/zkrsync/rsyncfile.sh &
<2>supervisord配置
cat /etc/supervisord.d/rsync.ini
[program:rsync]command=/opt/zkrsync/rsyncfile.shstartsecs=3startretries=3stopsignal=QUITstopasgroup=truestopwaitsecs=10user=rootredirect_stderr=truestdout_logfile=/data/log/rsync/running.logstdout_logfile_maxbytes=50MBstdout_logfile_backups=10stderr_logfile=/data/log/rsync/error.logstderr_logfile_maxbytes=50MBstderr_logfile_backups=10
二、客户端
(1)rsync配置文件设置
cat /etc/rsyncd.confuid = rootgid = rootpid file = /var/run/rsyncd.pidlock file = /var/run/rsync.locklog file = /var/log/rsyncd.log[zkpub] path = /tmp comment = zk transaction log trans read only = no hosts allow = 10.0.138.152 #server端ip hosts deny = *
(2)启动rsync进程服务
rsync --daemon --config=/etc/rsyncd.conf -v
三、 测试
向这个目录"/tmp/test"进行文件的增删改查操作,日志样例如下:
sending incremental file listtest/deleting test/wuwusent 40 bytes received 12 bytes 104.00 bytes/sectotal size is 0 speedup is 0.00sending incremental file listtest/test/iiii5 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/2)
测试ok没有问题。