本文共 1508 字,大约阅读时间需要 5 分钟。
源主机: 192.168.1.111
目的主机: 192.168.1.28(rsync服务端)实时监控源主机的某个目录,有更新则立即同步到目标主机1.在目的主机192.168.1.28安装配置Rsync服务端
yum install rsync -y创建配置文件 /etc/rsyncd.conf
log file = /var/log/rsyncd.log pidfile = /var/run/rsyncd.pid lock file = /var/run/rsync.lock uid = rootgid = root port=873 use chroot = no read only = no list = no max connections = 200 timeout = 600 secrets file = /etc/rsync.pass[yunwei]
path = /data/www/ comment = yunweiauth users = rsync_userhosts allow = 192.168.1.111服务端的密码文件保存 用户名:密码
客户端的密码文件只需要保存密码启动rsync服务
rsync --config=/etc/rsyncd.conf --daemon2.在源主机192.168.1.111上安装inotify和rsync客户端
下载地址yum install make gcc gcc-c++ cd /usr/local/srctar zxvf inotify-tools-3.14.tar.gz cd inotify-tools-3.14 ./configure --prefix=/usr/local/inotify make make installyum install rsync -y
配置密码文件
同步脚本如下,后台运行
#!/bin/bashsrc=/data/website/iworker2/dst=yunweiexcludedir=/data/scripts/exclude.listrsyncuser=rsync_userrsyncpass=/etc/rsync.passdstIP='192.168.1.28'for ip in $dstIP
do rsync -avP --port=873 --delete --exclude-from=$excludedir $src $rsyncuser@$ip::$dst --password-file=$rsyncpassdoneinotifywait -mrq --timefmt '%d/%m/%y/%H:%M' --format '%T %w %f' -e
modify,delete,create,attrib /data/website/iworker2|while read filedo for ip in $dstIPdo rsync -avP --port=873 --delete --exclude-from=$excludedir $src$rsyncuser@$ip::$dst --password-file=$rsyncpassdone doneexcludedir=/usr/local/inotify/exclude.list 不需要同步的文件,目录,如果有多个,每一行写一个目录,使用相对于同步模块的路径
转载于:https://blog.51cto.com/13666027/2090238