Chinaunix首页 | 论坛 | 博客
  • 博客访问: 698270
  • 博文数量: 108
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 1436
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-31 09:49
文章分类
文章存档

2019年(16)

2015年(2)

2014年(20)

2013年(70)

我的朋友

分类: LINUX

2013-10-23 14:19:27

一、安装前准备工作

unison各种版本下载地址:
~bcpierce/unison//download.html
unison编译器下载地址:

其它有用链接;(这些链接具体是干嘛的我木有看)

~bcpierce/unison//contrib.html
~bcpierce/unison/download/releases/stable/unison-manual.html#rshmeth
%3D1%26amp%3Bfilter%3Dreward
从以上地址可以下载各种平台,各种版本的unison,有基于源码安装的,有二进制的,我下载的是二进制的,可以直接使用.这里介绍源码安装:
源码安装unison
Linux下从源码包编译安装,需要一个叫做Objective Caml compiler的工具,版本至少3.0.7,可以从这里下载:
Ocaml安装脚本如下:
# tar -zxf ocaml-3.09.3.tar.gz
# cd ocaml-3.09.3
# ./configure
# make world opt
# make install
Unison对版本要求很高,进行同步的两台主机需要相同版本的unison,所以这里使用和windows一致的版本2.13.16,unison-2.13.16.tar.gz
安装脚本如下:
# tar -zxf unison-2.13.16.tar.gz
# cd unison-2.13.16
# make UISTYLE=text
# make install
之后将生成可执行文件unison,将其cp到系统PATH即可。
# cp ./unison /usr/local/bin
二、开始配置双机信任
实验的环境为192.168.156.190和192.168.156.192
在两台机器上都要执行以下操作
在/root目录下建立.ssh文件夹
并将.ssh文件夹的权限改为700
mkdir -p /root/.ssh

chmod 700 /root/.ssh/
建立RSA
在192.168.156.190执行,建立公钥
ssh-keygen -t rsa

ssh-keygen -t dsa
cat id_rsa.pub >> authorized_keys
cat id_dsa.pub >> authorized_keys
然后将authorized_keys
scp 到156.192的/root/.ssh下面

之后再192.168.156.192上进行如下操作
创建公钥
ssh-keygen -t rsa

ssh-keygen -t dsa
cat id_rsa.pub >> authorized_keys
cat id_dsa.pub >> authorized_keys

这个时候在156.192的authorized_keys中包含了所有的公钥信息

回到156.190上删除/root/.ssh中的authorized_keys
再回到156.192上将完整的公钥信息authorized_keys
利用scp命令传到156.190的/rro/.ssh下


然后进行测试
如果在156.190执行
ssh 192.168.156.192 date不用输入密码且有结果返回,就是配置成功了
在156.192执行对190的时间采集即可进行双向测试了。

1:本地使用
使用方法:
#unison  111 222  #同步本地的111和222文件夹
Contacting server...
Looking for changes
Warning: No archive files were found for these roots.  This can happen either
because this is the first time you have synchronized these roots,
or because you have upgraded Unison to a new version with a different
archive format. 
Update detection may take a while on this run if the replicas are
large.
Unison will assume that the 'last synchronized state' of both replicas
was completely empty.  This means that any files that are different
will be reported as conflicts, and any files that exist only on one
replica will be judged as new and propagated to the other replica.
If the two replicas are identical, then no changes will be reported.
Press return to continue.[] Reconciling changes
111          222             
         <---- file       aaaaaaaaaaaaa  [f] ?
Commands:
  or f or    follow unison's recommendation (if any)
  I                     ignore this path permanently
  E                     permanently ignore files with this extension
  N                     permanently ignore paths ending with this name
  m                     merge the versions
  d                     show differences
  x                     show details
  l                     list all suggested changes
  p or b                go back to previous item
  g                     proceed immediately to propagating changes
  q                     exit unison without propagating any changes
  /                     skip
  > or .                propagate from left to right
  < or ,                propagate from right to left
 
<---- file       aaaaaaaaaaaaa  [f] f
 
Proceed with propagating updates? [] y
Propagating updates
 
UNISON started propagating changes at 15:06:08 on 27 Aug 2007
[BGN] Copying aaaaaaaaaaaaa
  from /222
  to /111
[END] Copying aaaaaaaaaaaaa
UNISON finished propagating changes at 15:06:08 on 27 Aug 2007
Saving synchronizer state
Synchronization complete  (1 item transferred, 0 skipped, 0 failures)
如果检测到两个文件夹有所不同,unison会提示,让你选择相应的操作。如上例所示.
表示右边222的文件夹有新的文件,是否同步到左边的111文件夹,f表示force,然后将确认,进行更新,如果输入?会有更详细的介绍。

2: unison远程使用
使用方法:
# unison <本地目录> ssh://remotehostname(IP)/<远程目录的绝对路径>
例如:
# unison /home/AAA ssh://username@remotehostname(ip)//DB/path/BBB
表示将本机的目录/home/AAA和远端主机的/DB/path/BBB进行同步。一般的,需要两台机能ssh连接。
注意 在主机和目录间又多加了一个 "/"

3:unison参数说明
Unison有很多参数,这里只介绍经常使用的几个,详细的请参看unison手册:
"     -testserver
测试连通性,连接到服务器即退出。示例:
$ unison / ssh://opensou1@bluehost/    -servercmd=~/bin/unison -testserver
如果服务器端 unison 可执行文件不在默认目录下,甚至没有 unison 命令(需要你编译一个上传到服务器),则需要使用 -servercmd 参数告诉要执行的服务器 unison 命令位置。
使用 -testserver 参数,则成功链接即退出,也不会去执行目录的比较等后续操作。
"     -servercmd xxx
告诉 unison, 服务器端的 unison 命令是什么。参见上面的示例。
"     -auto
接受缺省的动作,然后等待用户确认是否执行。
"     -batch
batch mode, 全自动模式,接受缺省动作,并执行。
"     -ignore xxx
增加 xxx 到忽略列表中
"     -ignorecase [true|false|default]
是否忽略文件名大小写
"     -follow xxx
是否支持对符号连接指向内容的同步
"     owner = true (保持同步过来的文件属主)
"     group = true (保持同步过来的文件组信息)
"     perms = -1   (保持同步过来的文件读写权限)
"     repeat = 1   (间隔1秒后,开始新的一次同步检查)
"     retry = 3    (失败重试)
"     sshargs = -C (使用ssh的压缩传输方式)
"     xferbycopying = true
 
"     -immutable xxx
不变目录,扫描时可以忽略
"     -silent
安静模式
"     -times
同步修改时间
"     -path xxx 参数
只同步 -path 参数指定的子目录以及文件,而非整个目录。-path 可以多次出现,例如
  unison /home/username ssh://remotehost//home/username \
      -path shared \
      -path pub \
      -path .netscape/bookmarks.html

4:通过配置文件来使用unison
尽管可以完全通过命令行的方式来指定unison运行所需要的参数,但我们还是推荐使用配置文件来进行配置使用unison,原因很简单,看配置文件比看命令行容易理解,而且可管理性更强。
默认的配置文件夹位于~currentuser/.unison,即当前用户的home目录下,windows则位于C:\Documents and Settings\currentuser\.unison,默认的配置文件名是default.prf.
运行这样的命令:
#unison exitgogo
Unison将默认读取~currentuser/.unison/exitgogo.prf文件里的配置信息.我的配置信息在/root/.unison/exitgogo.prf,因此我们可以根据上面参数的介绍,把所有的参数配置信息写入到一个.prf的文件中.
下面是我的一个web应用中两个文件夹同步的配置信息:
root = /sina/webdata
root = ssh://root@192.168.60.121//sina/webdata
#force =/sina/webdata
ignore = Path as/*
#prefer = ssh://root@192.168.60.121//sina/webdata
batch = true
#repeat = 1
#retry = 3
owner = true
group = true
perms = -1
fastcheck=false
rsync =false
#debug=verbose
sshargs = -C
xferbycopying = true
log = true
logfile = /root/.unison/sina_122.1547.log
说明如下:
两个root表示需要同步的文件夹
force表示以本地的/var/www/bbsnew文件夹为标准,将该目录同步到远端。注意,如果指定了force参数,那么unison就变成了单项同步了,也就是说会以force指定的文件夹为准进行同步.
Unison本身是可以双向同步的,但是要做到双向同步,就不要设置force参数,如果设置了force参数,就成了单项同步了,此时unison类似与sync.
Unison双向同步基本原理是:假如有A B两个文件夹,A文件夹把自己的改动同步到B,B文件夹也把自己的改动同步到A,最后A B两文件夹的内容相同,是 A B文件夹的合集.
Unison双向同步的一个缺点是,对于一个文件在两个同步文件夹中都被修改时,unison是不会去同步的,因为unison无法判断以那个为准.
ignore = Path表示忽略/sina/webdata下面的WEB-INF/tmp目录,即同步时不同步它。
batch = true,表示全自动模式,接受缺省动作,并执行
-fastcheck  true表示同步时使用文件的创建时间来比较两地文件,如果这个选项为false,unison则将比较两地文件的内容.建议设置为true
log = true表示在终端输出运行信息。
logfile则指定了同时将输出写入log文件。

五:unison FAQ
如何在和远程服务器同步大量数据,上传一部分数据后,超时:
9%  559:15 ETARead from remote host bluehost: Connection reset by peer
Fatal error: Lost connection with the server
实际操作中,最好的方法是,第一次先把要上传的文件打成包,用 ftp 上传,然后展开到服务器中,之后执行一次 unison


阅读(1151) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~