设为首页 收藏本站
查看: 669|回复: 0

[经验分享] 双向同步镜像软件Unison

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-3-15 08:22:15 | 显示全部楼层 |阅读模式
项目背景:
公司有两台服务器,A和B,保持A和B的数据完全一致,任何一台服务器数据改变,都会更新到另一台!


实验环境:
vmware workstation 11
服务器A:ip:192.168.0.19  iptables关闭  setenforce 0
服务器B:ip:192.168.0.12  iptables关闭  setenforce 0
SecureCRT (ssh远程连接软件)


实验流程:
一、配置双机ssh信任:
二、unison软件安装
直接用yum安装
[iyunv@baculaServer  ~]# yum install -y unison   #主机A上
[iyunv@Slave-drbd ~]# yum install -y unison #主机B上
安装完以后就直接可以用了。
三、本地使用unison
1:创建测试目录test1 test2

[iyunv@baculaServer  ~]# mkdir test1 test2
2:在test1里面创建两个测试文件,test2不做修改

[iyunv@baculaServer  ~]# cd test1/
[iyunv@baculaServer  test1]# ifconfig >testfile1.txt
[iyunv@baculaServer  test1]# ping -c 3 www.baidu.com >testfile2.txt
3:数据同步

[iyunv@baculaServer  ~]# unison test1 test2 -batch
Contacting server...
Connected [//baculaServer //root/test1 -> //baculaServer //root/test2]
Looking for changes
Reconciling changes
deleted  ---->            hgfs  
test1        : deleted
test2        : unchanged dir      modified on 2016-03-14 at  0:54:37  size 0         rwxr-xr-x
new file ---->            test1.txt  
test1        : new file           modified on 2016-03-14 at  1:15:57  size 889       rw-r--r--
test2        : absent
new file ---->            test2  
test1        : new file           modified on 2016-03-14 at  1:16:19  size 548       rw-r--r--
test2        : absent
Propagating updates
UNISON 2.27.57 started propagating changes at 01:17:41 on 14 Mar 2016
[BGN] Copying test1.txt from /root/test1 to /root/test2
[END] Copying test1.txt
[BGN] Copying test2 from /root/test1 to /root/test2
[END] Copying test2
[BGN] Deleting hgfs from /root/test2
[END] Deleting hgfs
UNISON 2.27.57 finished propagating changes at 01:17:41 on 14 Mar 2016
Saving synchronizer state
Synchronization complete  (3 items transferred, 0 skipped, 0 failures)
4:测试

[iyunv@baculaServer  ~]# cd test2
[iyunv@baculaServer  test2]# ls
test1.txt  test2
可以看到我们没有创建这俩文件在test2目录,但是现在出现了!!!yes
四、远程使用unison
[iyunv@baculaServer  ~]# unison /test1 ssh://root@192.168.0.12//mnt -batch
Contacting server...
Connected [//Slave-drbd//mnt -> //baculaServer //test1]
Looking for changes
Warning: No archive files were found for these roots, whose canonical names are:
        /test1
        //Slave-drbd//mnt
This can happen either
because this is the first time you have synchronized these roots,
or because you have upgraded Unison to a new version with a different
archive format.  

Update detection may take a while on this run if the replicas are
large.

Unison will assume that the 'last synchronized state' of both replicas
was completely empty.  This means that any files that are different
will be reported as conflicts, and any files that exist only on one
replica will be judged as new and propagated to the other replica.
If the two replicas are identical, then no changes will be reported.

If you see this message repeatedly, it may be because one of your machines
is getting its address from DHCP, which is causing its host name to change
between synchronizations.  See the documentation for the UNISONLOCALHOSTNAME
environment variable for advice on how to correct this.

Donations to the Unison project are gratefully accepted:
http://www.cis.upenn.edu/~bcpierce/unison

  Waiting for changes from server
Reconciling changes
         <---- dir        /  
local        : absent
Slave-drbd   : dir                modified on 2016-03-14 at  1:22:20  size 0         rwxr-xr-x
Propagating updates
UNISON 2.27.57 started propagating changes at 01:23:58 on 14 Mar 2016
[BGN] Copying  from //Slave-drbd//mnt to /test1
[END] Copying
UNISON 2.27.57 finished propagating changes at 01:23:58 on 14 Mar 2016
Saving synchronizer state
Synchronization complete  (1 item transferred, 0 skipped, 0 failures)

查看服务器B
[iyunv@Slave-drbd ~]# cd /mnt/
[iyunv@Slave-drbd mnt]# ls
hgfs  testfile1.txt  testfile2.txt
可以看到我们多增的这两个文件。

五、删除B服务器的ifconfig.txt,看一下能不能同步成功

这是在服务器B上执行的:
[iyunv@Web1 tmp]# \rm ifconfig.txt
[iyunv@Web1 tmp]# cat ifconfig.txt
cat: ifconfig.txt: No such file or directory

在服务器A上执行同步命令
[iyunv@Server  fuchao1]# unison /fuchao1/ ssh://root@192.168.0.12//tmp -batch

查看/fuchao1目录
[iyunv@Server  fuchao1]# ls
ks-script-HprTeo      virtual-02.bd0Nzs  VMwareDnD
ks-script-HprTeo.log  virtual-02.Nvhjul  vmware-root
ping.txt              vmware-02          yum.log
pulse-eft3MC9bdiQw    vmware-config0     yum_save_tx-2016-03-14-00-51vq7ClS.yumtx

可以看到我们现在/fuchao1目录和服务器B/tmp目录的一模一样!!!!


总结:双向同步更新,有时候特别有用!希望大家能在实际的生产中懂得它的妙用!谢谢大家!!


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-190895-1-1.html 上篇帖子: Linux下实现网卡绑定(负载均衡和冗余备份) 下篇帖子: Codis3手册 服务器 软件 如何 项目
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表