CentOS 6.5 部署Unison雙向同步服務
環境介紹:
服務器IPServer1192.168.30.131Server2192.168.30.1321、添加主機互信:
a、添加host文件(在Server1、Server2分別操作):
[root@localhost ~]#echo -e "192.168.30.131 Server1\n192.168.30.132 Server2" >> /etc/hosts
b、更改主機名(在Server1、Server2分別操作):
[root@localhost ~]# sed -i "s/HOSTNAME=.*/HOSTNAME=Server1/g" /etc/sysconfig/network
[root@localhost ~]# hostname Server1
c、退出重新登錄就會顯示出主機名
d、添加互信
d1、在主機Server1上操作:
[root@Server1 ~]# ssh-keygen -t rsa
[root@Server1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@Server2
d2、在主機Server2上操作:
[root@Server2 ~]# ssh-keygen -t rsa
[root@Server2 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@Server1
2、Unison安裝
unison各種版本下載地址:
http://www.seas.upenn.edu/~bcpierce/unison//download.html
unison編譯器下載地址:
http://caml.inria.fr/pub/distrib/ocaml-3.10
2.1、安裝編譯工具:Objective Caml compiler
[root@Server1 soft]# cd ocaml-3.10.2+rc1/
[root@Server1 ocaml-3.10.2+rc1]# ./configure
[root@Server1 ocaml-3.10.2+rc1]# make world opt
[root@Server1 ocaml-3.10.2+rc1]# make install && echo OK
2.2、安裝Unison:
[root@Server1 unison-2.13.16]# cd ../unison-2.13.16
[root@Server1 unison-2.13.16]# make UISTYLE=text THREADS=true
此時會產生一個錯誤:
/bin/sh: etags: command not found
make[1]: [tags] Error 127 (ignored)
make[1]: Leaving directory `/soft/unison-2.13.16'
解決方法:
yum -y install ctags-etags
重新編譯:
[root@Server1 unison-2.13.16]# make UISTYLE=text THREADS=true
[root@Server1 unison-2.13.16]# make install && echo OK
此時如果報錯:
mv /root/bin//unison /tmp/unison-10301
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@Server2 unison-2.13.16]# mkdir /root/bin
[root@Server2 unison-2.13.16]# cp unison /root/bin/
重新編譯:
[root@Server1 unison-2.13.16]# make install && echo OK
2.3、修改配置文件;
[root@Server1 data]# cat /root/.unison/default.prf
# 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
2.4、創建同步目錄/data
[root@Server1 ~]# mkdir /data
[root@Server1 ~]# echo "aa" >> aa.txt
2.5、在Server2上同樣操作之上步驟,此處略過
2.6、測試同步
[root@Server1 ~]# unison -servercmd
[root@Server1 data]# unison -servercmd=/root/bin/unison
Contacting server...
Looking for changes
Waiting for changes from server
Reconciling changes
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
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
Saving synchronizer state
Synchronization complete (1 item transferred, 0 skipped, 0 failures)
[root@Server1 data]#
http://xxxxxx/Linuxjc/1184831.html TechArticle