rsync + inotify 实现单向数据同步

单向实时同步,主节点做的同步,备节点实时同步,但备节点的有变更的话主节点不会变
主节点:
10.0.0.10    controller
备节点:
10.0.0.31    compute1

在compute1上面,安装rsync,配置rsync.conf
在controller上面,安装rsync+inotify,启动rsync.sh这个脚本


1.配置compute1节点,
yum -y install rsync
vim /etc/rsyncd.conf
在写入下面的内容

uid = root
gid = root
read only = no
use chroot = no
max connections = 512
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
log format = %t %a %m %f %b

[rsync]
path = /home/
list = no
ignore errors
auth users = rsync_user
hosts allow = 10.0.0.10
hosts deny = *
secrets file = /etc/rsyncd.pwd

vim /etc/rsyncd.pwd
写入下面的内容

rsync_user:rsync@2010

chmod 600 /etc/rsyncd.conf
chmod 600 /etc/rsyncd.pwd
rsync --daemon
echo "rsync --daemon" >> /etc/rc.local

2.配置controller节点,

yum -y install inotify-tools rsync
vim /usr/local/sbin/rsync.sh
写入下面的内容

#!/bin/bash
src=/home/rsync
[email protected]::rsync
inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src |while read files
do
rsync -vzrtopg --delete --progress --password-file=/etc/rsyncd.pwd $src $dst  >/dev/null 2>&1
done

chmod 700 /usr/local/sbin/rsync.sh
sh /usr/local/sbin/rsync.sh &
echo "/usr/local/sbin/rsync.sh" >> /etc/rc.local

你可能感兴趣的:(rsync + inotify 实现单向数据同步)