一:Unison简介
Unison是windows和unix平台下都可以使用的文件同步工具,它能使两个文件夹(本地或网络上的)保持内容的一致。Unison有文字界面和图形界面,这里只介绍如何在文字界面下使用. unison拥有其它一些同步工具或文件系统的相同特性,但也有自己的特点:
跨平台使用;
对内核和用户权限没有特别要求;
unison是双向的,它能自动处理两分拷贝中更新没有冲突的部分,有冲突的部分将会显示出来让用户选择更新策略;
只要是能连通的两台主机,就可以运行unison,可以直接使用socket连接或安全的ssh连接方式,对带宽的要求不高,使用类似rsync的压缩传输协议。
二:Unison的安装
unison各种版本下载地址:
http://www.seas.upenn.edu/~bcpierce/unison//download.html
unison 编译器下载地址:
http://caml.inria.fr/pub/distrib/ocaml-3.10
从以上地址可以下载各种平台,各种版本的unison,有基于源码安装的,有二进制的,我下载的是二进制的,可以直接使用.这里介绍源码安装:
源码安装unison
1.ocaml-3.10.0的安装(安装unsion所需要的依赖包,两台服务器都需要安装)
1. #wget http://caml.inria.fr/pub/distrib/ocaml-3.10/ocaml-3.10.0.tar.gz
2. #tar -zxvf ocaml-3.10.0.tar.gz
3. #cd ocaml-3.10.0
4. #./configure
5. #make world && make bootstrap && make opt && make opt.opt && make install
2.unison-2.13.16的安装 (两台服务器都需要安装)
1. #wget http://www.seas.upenn.edu/~bcpierce/unison//download/releases/stable/unison-2.13.16.tar.gz
2. #tar -zxvf unison-2.13.16.tar.gz
3. #cd unison-2.13.16
4. # make UISTYLE=text THREADS=true STATIC=true && make install
(使用命令行方式,加入线程支持,编译为静态模式)
三:Unsion的配置
/root/.ssh/authorized_keys && rm /root/id_rsa.pub"
4)重启sshd
#service sshd restart
2.配置unison
1)创建链接
#ln -s /root/bin/unison /bin
2)创建/root/.unison/default.prf
注意:root = ssh://192.168.0.163//turbomail/accounts 在另一台服务器上这里写上对方服务器的ip地址
#vi /root/.unison/default.prf
2. root = /turbomail/accounts
3. root = ssh://192.168.0.163//turbomail/accounts/
4. log = true
5. auto = true
6. batch = true
7. maxthreads = 500
8. owner = true
9. group = true
10.perms = -1
11.repeat = 1
12.retry = 3
13.sshargs = -C
14.xferbycopying = true
3.测试
1.建同步目录
1. #mkdir /root/test
2. #touch /root/test/i-am-no-empty
2.测试脚本test.bash
1. #!/bin/bash
2. for i in `seq 1 20000` ; do
3. cp -f /root/test/rhel-ld-en.pdf /root/test/${i}.pdf;
4. done
3.启动unison
#unison
Contacting server...
Looking for changes
Waiting for changes from server
Reconciling changes
Nothing to do: replicas have not changed since last sync.
Sleeping for 1 seconds...