a.在所有要同步服务器上安装ocaml,unison源码包
b.使用ssh-keygen -t rsa创建ssh信任。将id_rsa.pub拷贝到对方主机/root/.ssh/下,并改名为authorized_keys
c.同步要同步的文件测试,unison /root/test/ ssh://172.16.100.144//root/test
host1:172.16.100.142
host2:172.16.100.144
一:unison,ocaml源码包下载
http://www.seas.upenn.edu/~bcpierce/unison//download.html
http://caml.inria.fr/pub/distrib/ocaml-3.10
二:安装unison,两台服务器均安装
[root@localhost ~]# tar zxvf ocaml-3.10.2.tar.gz
[root@localhost ~]# cd ocaml-3.10.2
[root@localhost ocaml-3.10.2]# ./configure
[root@localhost ocaml-3.10.2]# make world && make opt && make install
[root@localhost ~]# tar zxvf unison-2.40.102.tar.gz
[root@localhost unison-2.40.102]# make UISTYLE=text
[root@localhost unison-2.40.102]# make install
安装过程中,可能出现如下错误。解决方法是将unison拷贝至/usr/local/bin下
mv: cannot stat '/root/bin//unison': No such file or directory
make: [doinstall] Error 1 (ignored)
cp unison /root/bin/
cp: cannot create regular file '/root/bin/': Is a directory
make: *** [doinstall] Error 1
[root@localhost unison-2.40.102]# cp ./unison /usr/local/bin/
三:配置双击ssh信任
在host1上创建key并配置host2的信任
[root@localhost ~]# ssh-keygen -t rsa
全部按回车确定,会在/root/.ssh下生成一对密钥。id_rsa(私钥)和id_rsa.pub(公钥)
将公钥添加到host2的authorized_keys文件中
[root@localhost ~]#cd /root/.ssh/
[root@localhost ~]#scp id_rsa.pub 172.16.100.144:/root/
ssh登录到host2中
[root@lo144 ~]# mkdir /root/.ssh
[root@lo144 ~]# chmod 700 /root/.ssh/
[root@lo144 ~]# mv id_rsa.pub /root/.ssh/authorized_keys
[root@lo144 ~]# chmod 600 /root/.ssh/authorized_keys
在host2上创建key并配置host1的信任
[root@lo144 ~]# ssh-keygen -t rsa
[root@lo144 .ssh]# scp id_rsa.pub 172.16.100.142:/root/.ssh/
[root@lo144 .ssh]#mv id_rsa.pub authorized_keys
重启ssh服务
[root@localhost ~]#/etc/init.d/sshd restart
[root@lo144 .ssh]#/etc/init.d/sshd restart
四:unison的配置与使用
两台服务器分别执行一次unison
[root@localhost ~]#unison /root/test/ ssh://172.16.100.144//root/test
正常情况下,142机器上test目录下的文件,会同步到144机器上的test目录下
修改两台服务器的unison配置文件,输入以下内容:
#vi /root/.unison/default.prf
root = /root/test
root = ssh://172.16.100.142//root/test
#force =
#ignore =
batch = true
#repeat = 1
#retry = 3
owner = true
group = true
perms = -1
fastcheck = false
rsync = false
sshargs = -C
xferbycopying = true
log = true
logfile = /root/.unison/unison.log
添加完成,保存。再执行同步,就可以只输入unison了
[root@localhost ~]#unison