参考:http://moqiang02.iteye.com/blog/2107473
IP:120.77.244.96
IP:47.92.27.140
客户端A安装rsync+inotify-tools
主服务器
1)安装rsync
1、apt-get install[remove] rsync
2、touch /etc/rsync/rsyncd.conf
uid = root
gid = root
port = 873
hosts allow = 47.92.27.140
use chroot = true
max connections = 200
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[default]
path = /home/default
comment = default
ignore errors
read only = no
list = no
auth users = suicy
secrets file = /etc/rsyncd.passwd
3、touch rsyncd.passwd
suicy:suicy
chmod 600 /etc/rsyncd.passwd
4、rsync --daemon; 启动成功
出现以上结果,表明rsync服务器端已经启动。
2)安装inotify
1、wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
2、tar zxvf inotify-tools-3.14.tar.gz
3、cd inotify-tools-3.14
4、./configure -prefix=/usr/local/inotify
make
make install
3)创建rsync复制脚本
将server端的目录/tmp里的内容,如果修改了(无论是添加、修改、删除文件)能够通过inotify监控到,并通过rsync实时的同步给client的/home/default里,下面是通过shell脚本实现的
rsync -vzrtopg --delete --progress --password-file=/usr/local/rsync/rsync.passwd $src $user@$host::$des
inotify_back.sh
#!/bin/bash
src=/home/default/
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,delete,create,attrib $src | while read file
do
/usr/bin/rsync -auvrtzopgP --progress --password-file=/etc/rsyncd.pwd /home/default/
[email protected]::default
echo "${file} was rsynced">>/usr/log/rsync.log 2>&1
done
3)创建rsync密码文件
touch /etc/rsyncd.pwd
4)启动
rsync --daemon
sh inotify_back.sh &
配置文件错误:error starting client-server protocol (code 5) at main.c(1653) [sender=3.1.1]
启动错误:failed to create pid file /var/run/rsyncd.pid: File exists
解决方案:rm -rf /var/run/rsyncd.pid 再重新启动Rsync服务(rsync --daemon)
同步错误:Unknown module 'default'
解决方案:inotify_back.sh url错误
连接拒绝:failed to connect to 120.77.244.96 (120.77.244.96): Connection refused
解决方案:对方rsync没有开启
@ERROR: auth failed on module default
解决方案:验证配置文件密码问题
报错:connection unexpectedly closed (0 bytes received so far) [sender]
rsycnd.conf
readonly=no