服务端:backup_server 192.168.174.10
客户端:lamp 192.168.174.20
一、服务端部署
①生成配置文件
vim /etc/rsyncd.conf
#Rsync server#created by yupan 15:01 2016-02-23##rsyncd.conf start##uid = rootgid = rootuse chroot = nomax connections = 2000timeout = 600pid file = /var/run/rsyncd.pidlock file = /var/run/rsync.locklog file = /var/log/rsyncd.logignore errorsread only = falselist = falsehosts allow = 192.168.174.0/24hosts deny = 0.0.0.0/32auth users = rsync_backupsecrets file = /etc/rsync.password#####################################[www]comment = www by yupan 14:18 2016-02-23path = /data0/www/www/#####################################[bbs]comment = bbs by yupan 14:18 2016-02-23path = /data0/www/bbs/#####################################[blog]comment = blog by yupan 14:18 2016-02-23path = /data0/www/blog/#####################################[backup]comment = blog by yupan 14:18 2016-02-23path = /backup/#####################################[nfs]comment = blog by yupan 14:18 2016-02-23path = /backup/nfs/
②密码及权限设置
echo "rsync_backup:panda" > /etc/rsync.password
chmod 600 /etc/rsync.password
③启动Rsync
启动(daemon模式)
rsync --daemon
加入开机自启动
echo "/usr/bin/rsync --daemon" >> /etc/rc.local
检查开机启动
cat /etc/rc.local
检查Rsync进程(二选一)
ps -ef|grep rsync
netstat -lntup|grep rsync
重启服务
killall rsync
rsync --daemon
④创建共享目录
mkdir -p /data0/www/{bbs,www,blog}
二、客户端配置
①生成密码文件
echo "panda" > /etc/rsync.passwordchmod 600 /etc/rsync.password
②测试同步功能
rsync -avz a.txt rsync_backup@192.168.174.10::www/ --password-file=/etc/rsync.password
③服务端验证
服务端防火墙需rsync通行
④Inotify配置
创建tools、scripts文件夹集中管理软件包及脚本文件,编译安装Inotify-3.14
mkdir -p /home/toolsmkdir -p /home/scriptscd /home/tools/tar xf inotify-tools-3.14.tar.gz cd inotify-tools-3.14./configure --prefix=/usr/local/inotify-tools-3.14make && make installln -s /usr/local/inotify-tools-3.14/ /usr/local/inotify
Inotify简易脚本调试,后台运行
vim /home/scripts/inotify.sh
#!/bin/shdir="/usr/local/inotify-tools-3.14/bin/inotifywait"$dir -mrq --timefmt '%d/%m/%y %H:%M' --format '%w%f' -e delete,create,close_write /backup|while read linedo cd / rsync -az --delete /backup/ rsync_backup@192.168.174.10::nfs --password-file=/etc/rsync.passworddone
sh /home/scripts/inotify.sh &
⑤测试同步效果
服务端:
客户端:
客户端开始生成文件:
touch {a..z}
查看服务端文件夹:
三、Rsync+Inotify优缺点
1,rsync是单向传输。
2,可以互为服务端及客户端3,同步时不会陷入循环4,并发较小,不能适用大型集群优化版本: