二:安装unison unison各种版本下载地址: http://www.seas.upenn.edu/~bcpierce/unison//download.html unison编译器下载地址: http://caml.inria.fr/pub/distrib/ocaml-3.10 其它有用链接; http://worldhello.net/doc/bcp/unison.html http://www.seas.upenn.edu/~bcpierce/unison//contrib.html http://www.cis.upenn.edu/~bcpierce/unison/download/releases/stable/unison-manual.html#rshmeth http://linux.chinaunix.net/bbs/viewthread.php?tid=888250&extra=page%3D1%26amp%3Bfilter%3Dreward 从以上地址可以下载各种平台,各种版本的unison,有基于源码安装的,有二进制的,我下载的是二进制的,可以直接使用.这里介绍源码安装: 源码安装unison Linux下从源码包编译安装,需要一个叫做Objective Caml compiler的工具,版本至少3.0.7,可以从这里下载:http://caml.inria.fr/ 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
三:配置双机ssh信任
由于unison在远程同步文件夹要登陆远程服务器,因此要配置两机互相信任 本例假设本地机为:10.178.1.132(linux) 远程机:10.178.1.110(solaris) 1. 在两台机器上创建 RSA密钥 以下操作要在本地机和远程机上都执行一遍 (1)以 root 用户登录 (2)在 root 用户的 主目录内创建.ssh 目录并设置正确的权限 [root@gsgatzhapp1 ~]# mkdir ~/.ssh [root@gsgatzhapp1 ~]# chmod 700 ~/.ssh (3)使用 ssh-keygen 命令生成第 2 版本的 SSH 协议的 RSA 密钥 [root@gsgatzhapp1 ~]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: 17:e4:7c:79:8d:a0:00:3b:d9:f7:7a:56:f3:ac:54:4d oracle@gsgatzhapp1 在提示保存私钥(key)和公钥(public key)的位置时,使用默认值。 如果需要私钥密码(passphrase),则输入一个私钥密码(如果使用私钥密码,使用 ssh 执行远程命令时需要输入私钥密码,因此,本案例中未使用私钥密码),因此,直接回车即可。 2. 添加密钥到授权密钥文件(authorized key file)中 (1)以 root 用户登录 (2)在本地机上执行 [root@gsgatzhapp1 ~] # cd ~/.ssh [root@gsgatzhapp1.ssh]#ssh 10.178.1.132 cat /root/.ssh/id_rsa.pub >> authorized_keys [oracle@gsgatzhapp1.ssh]#ssh 10.178.1.110 cat /root/.ssh/id_rsa.pub >> authorized_keys [oracle@gsgatzhapp1.ssh]#scp authorized_keys 10.178.1.110:/root/.ssh/ [oracle@gsgatzhapp1 .ssh]# chmod 600 /root/.ssh/authorized_keys (3)在远程机10.178.1.110 上: bash-2.05# chmod 600 /root/.ssh/authorized_keys (4)测试 完成后,在 gsgatzhapp1 上执行: [root@gsgatzhapp1 ~]# ssh 10.178.1.132 date [root@gsgatzhapp1 ~]#ssh 10.178.1.110 date 如果不需要输入密码就出现系统日期,说明 SSH 配置成功。
四:unison的使用
Unison可以在一台主机上使用,同步两个文件夹,也可以在网络上是用。 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.[<spc>] Reconciling changes 111 222
<---- file aaaaaaaaaaaaa [f] ? Commands: <ret> or f or <spc> 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
如何在和远程服务器同步大量数据,上传一部分数据后,超时: 9% 559:15 ETARead from remote host bluehost: Connection reset by peer Fatal error: Lost connection with the server 实际操作中,最好的方法是,第一次先把要上传的文件打成包,用 ftp 上传,然后展开到服务器中,之后执行一次 unison 同步即可。