实验环境:

rhel6.0x86_64 

rsync client ip 192.168.0.100

rsync server WEB1 ip 192.168.0.101

rsync server WEB2 ip 192.168.0.102

当rsync client web数据发生变化时, 能自动同步到两台web ser 

--------------------------------------------------------------------------

rsync server install rsync package 

# yum -y install rsync 

rsync client install rsync and inotify-tools 

#yum -y install rsync 

#tar xzf inotify-tools-3.14.tar -C /usr/src 

#cd /usr/src/inotify

#./configure && make && make install      ---- install done 

 

--------------------------------------------------------------------------

WEB1 rsync configure

#vim /etc/rsyncd.com 

uid = nobody 

pid = nobody 

use chroot = no 

max connection = 10 

strict modes = yes 

pid file = /var/run/rsyncd.pid 

log file = /var/run/rsyncd.log

lock file = /var/run/rsyncd.lock

[web1]

path = /var/www/html

comment = web1 file 

ignore errors 

read only = no 

write only = no 

hosts allow = 192.168.0.100

hosts deny = *

list = false 

auth users = root 

secrets file = /etc/rsyncd.pass

#vim /etc/rsyncd.pass

root:lucky

#chmod 600 /etc/rsyncd.pass

 

#/etc/init.d/httpd start 

#rsync --daemon 

-------------------------------------------------------------------------

WEB2 rsync configure

#vim /etc/rsyncd.com 

uid = nobody 

pid = nobody 

use chroot = no 

max connection = 10 

strict modes = yes 

pid file = /var/run/rsyncd.pid 

log file = /var/run/rsyncd.log

lock file = /var/run/rsyncd.lock

[web2]

path = /var/www/html

comment = web1 file 

ignore errors 

read only = no 

write only = no 

hosts allow = 192.168.0.100

hosts deny = *

list = false 

auth users = root 

secrets file = /etc/rsyncd.pass

#vim /etc/rsyncd.pass

root:lucky

#chmod 600 /etc/rsyncd.pass

#/etc/init.d/httpd start 

#rsync --daemon 

-------------------------------------------------------------------------

rsync client 

vim rsyncd.sh

#!/bin/bash 

host1=192.168.0.101

host2=192.168.0.102

user=root

src=/var/www/html/

dst1=web1

dst2=web2

 

/usr/local/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 -vzrtopg --delete --progress --password-file=/etc/rsyncd.pass ${src} ${user}@${host1}::${dst1} > /dev/null

       /usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/rsyncd.pass ${src} ${user}@${host2}::${dst2} > /dev/null

        echo "${files} was rsync done " >> /tmp/rsyncd.log

        done

#vim /etc/rsyncd.pass

lucky

#chmod 600 /etc/rsyncd.pass

#bash rsyncd.sh &

--------------------------------------------------------------------------

 

 

done !