需求把192.168.150.21上 /apache-tomcat-7.0.37 实时同步到192.168.150.20 的 /home/tgss/apache-tomcat-7.0.37 中
配置192.168.150.20
rpm –ivh rsync-3.0.9-1.el6.rfx.x86_64.rpm
cat /etc/xinetd.d/rsync
可以看到rsync服务是关闭的 disable=yes 把它开启 disable=no
创建配置文件 /etc/rsyncd.conf
uid = root
gid = root
hosts allow = 192.168.150.21
use chroot = no
max connection = 4
timeout = 50
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
port = 873
[test]
path = /home/tgss
comment = web file
ignore errors
read only = no
list = yes
auth users = webuser
secrets file = /etc/rsync.passwd
transfer logging = yes
log format ="%a %f %l"
创建配置文件 /etc/rsync.passwd密码文件
chmod 600 /etc/rsync.passwd
启动rsync进程
rsync –daemon –config=/etc/rsyncd.conf
配置192.168.150.21
安装inotify
rpm –ivh rsync-3.0.9-1.el6.rfx.x86_64.rpm
cat /etc/xinetd.d/rsync
可以看到rsync服务是关闭的 disable=yes 把它开启 disable=no
tar xvf inotify-tools-3.14.tar.gz –C /usr/local
cd inotify-tools-3.14
./configure –prefix=/usr/local && make && make install
创建/etc/rsyncd.conf
启动rsync 服务
rsync –daemon
vim inofity.sh
#!/bin/bash
host=192.168.150.20
src=/apache-tomcat-7.0.37/
dst=test
user=webuser
/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 --password-file=/etc/rsync.passwd /apache-tomcat-7.0.37 $user@$host::$dst >/dev/null
echo "${files} was rsynced" >>/tmp/rsync.log 2>&1
done
chmod a+x inofity.sh
sh inofity.sh &
测试 在
Inofity+rsync详细安装 实现实时同步,布布扣,bubuko.com
原文:http://www.cnblogs.com/hmyyj/p/3571279.html