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

 

转载于:https://www.cnblogs.com/sharesdk/p/11141783.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值