Rsync+unison双向文件同步
Posted MoStart
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Rsync+unison双向文件同步相关的知识,希望对你有一定的参考价值。
1.配置RSYNC服务器的同步源:
- 基于SSH同步源
- rsync -avz /server/rsyncd/* chen@172.16.23.204:/client/rsyncd
- 基于RSYNC同步源
- /etc/rsyncd.conf
-
address = 172.16.23.203 port 873 pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log read only = false auth users = chen secrets file = /etc/rsync_user.db [share] comment = soft path=/server/rsyncd
-
- /etc/rsyncd_user.db
- 文件的权限必须是600
chen:123456
上行同步的时候:nobody必须有权限(setfacl -m u:nobody:rwx /client/rsyncd)
- rsyncd -avz chen@172.16.23.203::share /client/rsyncd/
- rsyncd -avz rsyncd://chen@172.16.23.203/share /client/rsyncd
- 文件的权限必须是600
- /etc/rsyncd.conf
- 免验证登录
- 基于ssh秘钥对登录
- 密钥对ssh-keygen -t rsa
- 传到对端:ssh-copy-id 172.16.23.204
- 基于RSYNCD系统变量
- RSYNC_PASSWORD=123456
2.inotify+rsyncd
- 服务端建立脚本
-
#!/bin/bash
a="/usr/local/bin/inotifywait -mrq -e create,delete /server/rsyncd" b="/usr/bin/rsync -avz /server/rsyncd/* 172.16.23.204:/client/rsyncd" $a | while read diretory event file do $b done
-
执行 bash a.sh & 放到后台执行
3.inotify+unison
安装软件:inotify-tools-3.14.tar.gz ocaml-3.10.0.tar.gz unison-2.13.16.tar.gz
-
- tar zxvf inotify-tools-3.14.tar.gz
- ./configure && make && make install
- tar -zxvf ocaml-3.10.0.tar.gz
- ./configure
- make world opt
- make install
- tar zxvf unison-2.13.16.tar.gz
- cd unison-2.13
- make UISTYLE=text THREADS=true STATIC=true
- cp unison /usr/local/bin
- 建立脚本
-
#!/bin/bash a="/usr/local/bin/inotifywait -mrq -e create,delete /server1" b="/usr/bin/unison -batch /server1 ssh://172.16.23.204//server2" $a | while read diretory event file do $b done
-
- tar zxvf inotify-tools-3.14.tar.gz
以上是关于Rsync+unison双向文件同步的主要内容,如果未能解决你的问题,请参考以下文章