博客统计信息

用户名:turbomail_zhw
文章数:33
评论数:15
访问量:18416
无忧币:218
博客积分:330
博客等级:3
注册日期:2009-09-10

Unsion工具实现数据的实时同步
2010-07-06 11:50:44
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://turbomailtt.blog.51cto.com/934223/344762
:Unison简介
     Unison
windowsunix平台下都可以使用的文件同步工具,它能使两个文件夹(本地或网络上的)保持内容的一致。Unison有文字界面和图形界面,这里只介绍如何在文字界面下使用. unison拥有其它一些同步工具或文件系统的相同特性,但也有自己的特点:
    
跨平台使用;
    
对内核和用户权限没有特别要求;
    unison
是双向的,它能自动处理两分拷贝中更新没有冲突的部分,有冲突的部分将会显示出来让用户选择更新策略;
    
只要是能连通的两台主机,就可以运行unison,可以直接使用socket连接或安全的ssh连接方式,对带宽的要求不高,使用类似rsync的压缩传输协议。
:Unison的安装
unison各种版本下载地址:
http://www.seas.upenn.edu/~bcpierce/unison//download.html
unison
编译器下载地址:
http://caml.inria.fr/pub/distrib/ocaml-3.10
以上地址可以下载各种平台,各种版本的unison,有基于源码安装的,有二进制的,我下载的是二进制的,可以直接使用.这里介绍源码安装:
源码安装unison
1.ocaml-3.10.0的安装(安装unsion所需要的依赖包,两台服务器都需要安装)
1. #wget http://caml.inria.fr/pub/distrib/ocaml-3.10/ocaml-3.10.0.tar.gz 
2. #tar -zxvf ocaml-3.10.0.tar.gz 
3. #cd ocaml-3.10.0 
4. #./configure 
5. #make world && make bootstrap && make opt && make opt.opt && make install 
2.unison-2.13.16的安装 (两台服务器都需要安装)
1. #wget http://www.seas.upenn.edu/~bcpierce/unison//download/releases/stable/unison-2.13.16.tar.gz 
2. #tar -zxvf unison-2.13.16.tar.gz 
3. #cd unison-2.13.16 
4. # make UISTYLE=text THREADS=true STATIC=true && make install  
(使用命令行方式,加入线程支持,编译为静态模式)
 :Unsion的配置
1.配置ssh无密码登陆
1)
生成密钥
#ssh-keygen (
一路回车)
2)
配置sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys (
去掉这三项的注释)
3)
导入/导出公钥
node1#scp
root@192.168.0.163:/root/.ssh/id_rsa.pub /root && cat /root/id_rsa.pub >> /root/.ssh/authorized_keys && rm
/root/.ssh/authorized_keys && rm /root/id_rsa.pub"
4)
重启sshd
#service sshd restart
2.配置unison 
1)
创建链接
#ln -s /root/bin/unison /bin
2)
创建/root/.unison/default.prf
注意:root = ssh://192.168.0.163//turbomail/accounts 在另一台服务器上这里写上对方服务器的ip地址
 #vi /root/.unison/default.prf   
2. root = /turbomail/accounts  
3. root = ssh://192.168.0.163//turbomail/accounts/
4. log = true 
5. auto = true 
6. batch = true 
7. maxthreads = 500 
8. owner = true 
9. group = true
10.perms = -1
11.repeat = 1 
12.retry = 3 
13.sshargs = -C  
14.xferbycopying = true  
3.测试
1.
建同步目录
1. #mkdir /root/test  
2. #touch /root/test/i-am-no-empty 
2.测试脚本test.bash
1. #!/bin/bash  
2. for i in `seq 1 20000` ; do  
3. cp -f /root/test/rhel-ld-en.pdf /root/test/${i}.pdf;   
4. done 
3.启动unison
#unison
Contacting server...
Looking for changes
  Waiting for changes from server
Reconciling changes
Nothing to do: replicas have not changed since last sync.
Sleeping for 1 seconds...

本文出自 “旋律@逍遥” 博客,请务必保留此出处http://turbomailtt.blog.51cto.com/934223/344762

turbomail_zhw、414213378
2人
了这篇文章
类别:未分类┆技术圈()┆阅读()┆评论() ┆ 推送到技术圈返回首页

文章评论

 
2011-06-16 14:34:55
这个是怎么实现实时同步的,你的文章名称里面写了实时同步,但是文章里面没有体现出来这个可以实时同步
博主回复:
2011-07-04 14:51:22
编辑default.prf 去定义你要同步的目录,同步效率还是不错的,占用资源也很小,我这边有在生产环境下使用的

 

发表评论            

2011-2012跨年度有奖征文:项目回忆录
昵  称:
登录  快速注册
验证码:

请点击后输入验证码博客过2级,无需填写验证码

内  容: