CentOS 6.5 部署Unison双向同步服务@H_301_1@
环境介绍:@H_301_1@
服务器 | IP |
Server1 | 192.168.30.131 |
Server2 | 192.168.30.132 |
@H_301_1@
@H_301_1@
@H_301_1@
a、添加host文件(在Server1、Server2分别操作):@H_301_1@
[root@localhost ~]#echo -e "192.168.30.131 Server1\n192.168.30.132 Server2" >> /etc/hosts@H_301_1@
b、更改主机名(在Server1、Server2分别操作):@H_301_1@
[root@localhost ~]# sed -i "s/HOSTNAME=.*/HOSTNAME=Server1/g" /etc/sysconfig/network@H_301_1@
[root@localhost ~]# hostname Server1@H_301_1@
d1、在主机Server1上操作:@H_301_1@
[root@Server1 ~]# ssh-keygen -t rsa@H_301_1@
[root@Server1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@Server2@H_301_1@
d2、在主机Server2上操作:@H_301_1@
[root@Server2 ~]# ssh-keygen -t rsa@H_301_1@
[root@Server2 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@Server1@H_301_1@
@H_301_1@
2、Unison安装@H_301_1@
unison各种版本下载地址:
http://www.seas.upenn.edu/~bcpierce/unison//download.html
unison编译器下载地址:
http://caml.inria.fr/pub/distrib/ocaml-3.10@H_301_1@
@H_301_1@
2.1、安装编译工具:Objective Caml compiler@H_301_1@
[root@Server1 soft]# cd ocaml-3.10.2+rc1/@H_301_1@
[root@Server1 ocaml-3.10.2+rc1]# ./configure@H_301_1@
[root@Server1 ocaml-3.10.2+rc1]# make world opt@H_301_1@
[root@Server1 ocaml-3.10.2+rc1]# make install && echo OK@H_301_1@
@H_301_1@
2.2、安装Unison:@H_301_1@
[root@Server1 unison-2.13.16]# cd ../unison-2.13.16@H_301_1@
[root@Server1 unison-2.13.16]# make UISTYLE=text THREADS=true@H_301_1@
/bin/sh: etags: command not found@H_301_1@
make[1]: [tags] Error 127 (ignored)
make[1]: Leaving directory `/soft/unison-2.13.16'@H_301_1@
yum -y install ctags-etags@H_301_1@
重新编译:@H_301_1@
[root@Server1 unison-2.13.16]# make UISTYLE=text THREADS=true@H_301_1@
[root@Server1 unison-2.13.16]# make install && echo OK@H_301_1@
此时如果报错:@H_301_1@
mv /root/bin//unison /tmp/unison-10301@H_301_1@
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@H_301_1@
[root@Server2 unison-2.13.16]# mkdir /root/bin@H_301_1@
[root@Server2 unison-2.13.16]# cp unison /root/bin/@H_301_1@
@H_301_1@
重新编译:
@H_301_1@
[root@Server1 unison-2.13.16]# make install && echo OK@H_301_1@
@H_301_1@
[root@Server1 data]# cat /root/.unison/default.prf@H_301_1@
# Unison preferences file
root = /data
root = ssh://root@Server2//data
#path = www
#ignore = Path wp-content/tmp
ignore = Path wp-config.php #忽略wp-config.php文件 相当于rsync的exclude
#nodeletion = /data
batch = true
maxthreads = 300
#repeat = 1
owner = true
group = true
perms = -1
fastcheck = false
sshargs = -C
xferbycopying = true
log = true
logfile = /tmp/unison.log@H_301_1@
@H_301_1@
2.4、创建同步目录/data@H_301_1@
[root@Server1 ~]# mkdir /data@H_301_1@
[root@Server1 ~]# echo "aa" >> aa.txt@H_301_1@
@H_301_1@
2.5、在Server2上同样操作之上步骤,此处略过@H_301_1@
@H_301_1@
2.6、测试同步@H_301_1@
[root@Server1 ~]# unison -servercmd@H_301_1@
[root@Server1 data]# unison -servercmd=/root/bin/unison
Contacting server...
Looking for changes
Waiting for changes from server
Reconciling changes@H_301_1@
local Server2
new file ----> bb.txt
local : new file modified on 2015-08-19 at 14:42:45 size 5 rw-r--r-- user=0 group=0
Server2 : absent
Propagating updates@H_301_1@
UNISON started propagating changes at 14:43:10 on 19 Aug 2015
[BGN] Copying bb.txt
from /data
to //Server2//data
[END] Copying bb.txt
UNISON finished propagating changes at 14:43:10 on 19 Aug 2015@H_301_1@
Saving synchronizer state
Synchronization complete (1 item transferred,0 skipped,0 failures)
[root@Server1 data]#@H_301_1@
@H_301_1@
本贴来源:http://www.cnblogs.com/zlyang/articles/5885037.html@H_301_1@