unison 双向镜像同步

unison 双向镜像同步   需要 ocaml 依赖工具(3.0.7)

而且需要机器ssh双向互信

ssh 开启互信 # vi in.sh  直接执行 in.sh 就可以了

mkdir ~/.ssh
chmod 700 .ssh/
/usr/bin/ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

 然后拷贝  .ssh/authorized_keys 中秘钥到各自的 .ssh/authorized_keys 文件中。

这样都可以进行无密码验证登陆。

示例:
ssh -p 2233 root@172.16.2.26
测试文件传输:
scp -P 2233 /data/in.sh root@172.16.2.16:/data

下载安装

wget http://www.seas.upenn.edu/~bcpierce/unison//download/releases/unison-2.32.52/unison-2.32.52.tar.gz
wget http://caml.inria.fr/pub/distrib/ocaml-3.10/ocaml-3.10.2.tar.gz
解压缩 编译
tar -xf ocaml-3.10.2.tar.gz 
mv ocaml-3.10.2 /usr/local/ocaml
/usr/local/ocaml/
./configure 
make world opt
make install

tar
-xf unison-2.32.52.tar.gz mv unison-2.32.52 /usr/local/unison cd ../unison/ make UISTYLE=text cp unison /usr/local/bin 拷贝执行文件到 系统默认执行目录 cp unison /usr/local/bin

配置同步策略文件 test.prf 测试;

default.prf   默认在 /root/.unison/default.prf 

(默认同步策略文件是 default.prf  ;直接执行 unison 命令 默认是加载 default.prf 

[root@localhost ~]# vi test.prf

root = /data/wwwroot/img
root = ssh://root@172.16.2.26//data/wwwroot/upload
# path = upload
# 指定同步目录
# path = log
# igonre = 
# 排除目录
batch = true
owner = true
group = true
perms = -1
maxthreads = 100
# 最大线程
fastcheck = true
# true 是通过时间同步
fastcheck = false
# false 通过内容
rsync = false
sshargs = -C
xferbycopying = true
confirmbigdel = false
log = true
logfile = /var/log/unison/unison.log
# 日记记录文件

同步执行 

直接执行  unison test  本机16和同步机器26 便可以进行目录同步

注意如果单方服务进行新增删除,则也会进行同步删除。

定时同步:


cat 1
.sh #!/bin/bash # unison /root/.unison/test.prf /usr/local/bin/unison 添加定时任务 每5秒进行同步 crontab -e # * * * * * sleep 5; sh /opt/1.sh &> /dev/null

 

posted @ 2019-07-06 10:15  01234567  阅读(364)  评论(0编辑  收藏  举报