环境如下:
vm1 ip
vm2 ip
.........................................................
编译安装Unison
[root@vm1 ~]# tar -xzvf ocaml-4.02.0.tar.gz
[root@vm1 ~]# cd ocaml-4.02.0
[root@vm1 ocaml-4.02.0]# ./configure
[ro[root@vm1 ocaml-4.02.0]# make world opt
[root@vm1 ocaml-4.02.0]# make install
[root@v编译安装Unison
[root@vm1 ~]# tar -xzvf unison-2.48.3.tar.gz
[root@vm1 ~]# cd unison-2.48.3
[root@vm1 unison-2.48.3]# make UISTYLE=text
[root@vm1 unison-2.48.3]# make install
在执行make install的过程中,可能会出现以下错误提示:
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
出现错误的原因在与Unison默认是将文件Copy到/root/bin目录,但Linux默认是没有该目录的,因此我们需要将生成的可执行文件unison复制到系统的PATH目录。
[root@vm1 unison-2.48.3]# cp unison /usr/local/bin
将可执行文件unison上传到远程主机ip
[root@vm1 unison-2.48.3]# scp unison root@192.168.30.65:/root/
通过SSH登陆到远程主机,再将unison复制到vm2的PATH目录
[root@vm2 ~]#cp unison /usr/local/bin
m1 ocaml-4.02.0]# make install
配置ssh key信任
vim1:ssh-keygen
ssh-copy-id -i root@ip(远程主机)
Vim2:ssh-keygen
ssh-copy-id -i root@ip(远程主机)
重启SSH服务
[root@vm1 ~]# service sshd restart
[root@vm2 ~]# service sshd restart
root@vm1~]$ unison-batch /aa/ssh://root@ip(远程ip)//aa/
[root@vm2 ~]$unison-batch /aa/ssh://root@ip(远程ip)//aa/
如果上述执行顺利,说明双向同步的环境已经搭建起来了,下面就是做一些配置使文件同步常态化。
修改两台服务器的unison配置文件,输入以下内容
[root@vm1 ~]$ vi/root/.unison/default.prf
#Unison preferences file
root = /aa/
root = ssh://root@ip(远程)//aa/
batch = true
owner = true
group = true
perms = -1
sshargs = -C
xferbycopying = true
log = true
#logfile = /home/unison/.unison/unison.log
[root@vm2 ~]$ vi/root/.unison/default.prf
#Unison preferences file
root = /aa/
root = ssh://root@ip(远程)//aa/
batch = true
owner = true
group = true
perms = -1
sshargs = -C
xferbycopying = true
log = true
#logfile = /home/unison/.unison/unison.log
分别在俩台server上创建文件或目录,看是否同步(在其中一台server上执行命令unison)
crontab -e
*/5 * * * * /usr/local/bin/unison