CentOS 6.5 部署Unison双向同步服务

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS 6.5 部署Unison双向同步服务相关的知识,希望对你有一定的参考价值。

CentOS 6.5 部署Unison双向同步服务

环境介绍:

服务器IP
Server1192.168.30.131
Server2192.168.30.132

 

 

 

1、添加主机互信:

  a、添加host文件(在Server1、Server2分别操作):

    [[email protected] ~]#echo -e "192.168.30.131 Server1\n192.168.30.132 Server2" >> /etc/hosts

  b、更改主机名(在Server1、Server2分别操作):

    [[email protected] ~]# sed -i "s/HOSTNAME=.*/HOSTNAME=Server1/g" /etc/sysconfig/network

    [[email protected] ~]# hostname Server1

  c、退出重新登录就会显示出主机名

  d、添加互信

    d1、在主机Server1上操作:

    [[email protected] ~]# ssh-keygen -t rsa

    [[email protected] ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]

    d2、在主机Server2上操作:

    [[email protected] ~]# ssh-keygen -t rsa

    [[email protected] ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]

  

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

    [[email protected] soft]# cd ocaml-3.10.2+rc1/

    [[email protected] ocaml-3.10.2+rc1]# ./configure

    [[email protected] ocaml-3.10.2+rc1]# make world opt

    [[email protected] ocaml-3.10.2+rc1]# make install && echo OK

    

    2.2、安装Unison:

    [[email protected] unison-2.13.16]# cd ../unison-2.13.16

    [[email protected] 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

    重新编译:

    [[email protected] unison-2.13.16]# make UISTYLE=text THREADS=true

    [[email protected] 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

      解决方法:

      [[email protected] unison-2.13.16]# mkdir /root/bin

      [[email protected] unison-2.13.16]# cp unison /root/bin/

 

    重新编译:

    [[email protected] unison-2.13.16]# make install && echo OK

    

    2.3、修改配置文件;

    [[email protected] data]# cat /root/.unison/default.prf 

    # Unison preferences file
    root = /data
    root = ssh://[email protected]//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

    [[email protected] ~]# mkdir /data

    [[email protected] ~]# echo "aa" >> aa.txt

    

    2.5、在Server2上同样操作之上步骤,此处略过

    

    2.6、测试同步

    [[email protected] ~]# unison -servercmd

    [[email protected] 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)
    [[email protected] data]#


    本贴来源:http://www.cnblogs.com/zlyang/articles/5885037.html

本文出自 “Elephant” 博客,请务必保留此出处http://zlyang.blog.51cto.com/1196234/1854042

以上是关于CentOS 6.5 部署Unison双向同步服务的主要内容,如果未能解决你的问题,请参考以下文章

Centos6安装配置Unison+Inotify双向同步

双向同步使用unison

UNISON+inotify数据的双向实时同步

unison做文件双向同步

Rsync+unison双向文件同步

unison+inotify实现数据实时双向同步