1.做好ssh 互信
2.安装inotify
查看是否支持inotify ls -lsart /proc/sys/fs/inotify
yum install -y inotify-tools --enablerepo=epel
检测是否成功安装 inotifywait -h
3.配置同步脚本
#!/bin/bash host=10.xxx src=/data/test/ log_file=/var/log/rsync_client.log inotify_fun(){ /usr/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src | while read files do /usr/bin/rsync -auvrtzopgP --delete --progress ${src} ${host}:${src} done } inotify_fun >> ${log_file} 2>&1 &4.脚本开机启动
echo "/scripts/rsync.sh" >> /etc/rc.local
两台机器都安装inotify+rsync,修改下脚本里的host地址即可
参考:
http://blog.csdn.net/hyh9401/article/details/52043134
http://blog.51cto.com/nmshuishui/1387048
https://www.cnblogs.com/mauricechans/p/6225737.html