rsync+inotify文件实时同步

2020-06-23  本文已影响0人  e20d9310ced3

需求:

192.168.255.56:/opt目录下的文件变动,实时同步到192.168.255.57:/opt下

部署:

yum -y install rsync
uid = nobody
gid = nobody
use chroot = no
max connections = 10
pid file = /var/run/rsyncd.pid
exclude = lost+found/
log file = /var/log/rsync.log
log format = %t %a %m %f %b
motd file = /etc/rsyncd/rsyncd.motd
[data]
path = /opt/  # 同步数据目录,以/结尾,否则会在目录下再创建一个同步目录
transfer logging = yes
ignore errors
read only = no
list = no
hosts allow = 192.168.255.56/32  # ip白名单
uid = root
gid = root
auth users = backuser
secrets file = /etc/rsync.password
echo "backuser:123456" > /etc/rsync.password
chmod 600 /etc/rsync.password
rsync --daemon
echo "/usr/bin/rsync --daemon" >> /etc/rc.local
yum -y install rsync
uid = nobody
gid = nobody
use chroot = no
max connections = 10
pid file = /var/run/rsyncd.pid
exclude = lost+found/
log file = /var/log/rsync.log
log format = %t %a %m %f %b
motd file = /etc/rsyncd/rsyncd.motd
[data]
path = /opt/  # 同步数据目录
transfer logging = yes
ignore errors
read only = no
list = no
hosts allow = 192.168.255.57/32  # ip白名单
uid = root
gid = root
auth users = backuser
secrets file = /etc/rsync.password
echo "123456" > /etc/rsync.password
chmod 600 /etc/rsync.password
tar -zxf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure
make && make install
#!/bin/bash
src=/opt/
des=data
host="192.168.255.57"
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e modify,delete,create,attrib $src | while read files
do
for hostip in $host
do
rsync -vzrtopg --delete --progress --password-file=/etc/rsync.password $src backuser@$hostip::$des
done
echo "${files} was rsynced" >>/tmp/rsync.log 2>&1
done
nohup /bin/bash /root/rsync.sh &
上一篇 下一篇

猜你喜欢

热点阅读