服务器端配置:
修改/etc/xinetd.d/rsync
Disable = no
手动创建配置文件/etc/rsyncd.conf
uid=nobody
gid=nobody
userchroot=no
max connections=200
timeout=600
pid file=/var/run/rsyncd.pid
log file=/var/log/rsyncd.log
lock file=/var/run/rsyncd.lock
[backup]
path=/backup/
ignore errors
read only=no
list=no
hosts allow=192.168.2.0/255.255.255.0
auth users=test
secrets file=/etc/rsyncd.password
生成密码文件:
Echo “test:test”>> /etc/rsyncd.password
客户端配置:
生成密码文件:
Echo “test”>>/etc/rsyncd.password
同步命令:在客户端输入
rsync -vzrtopg --delete /abc test@192.168.2.208::backup --password-file=/etc/rsyncd.password
二、rsync+Inotify实现数据实时同步更新
客户端安装inotify
编写监控文件变化的脚本,内容如下:
#!/bin/bash
src=/abc
des=backup
ip=192.168.2.208
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y/ %H:%M' --format '%T %w %f' -e modify,delete,create,attrib $src | while read file
do
rsync -vzrtopg --delete --progress $src test@$ip::$des --password-file=/etc/rsyncd.password && echo "$src was rsynced"
done
将该脚本放入后台运行进行实时更新!
Nohup /root/rsync.sh &