你的位置:首页 > 软件开发 > 数据库 > 分布式架构中一致性解决方案——Zookeeper集群搭建

分布式架构中一致性解决方案——Zookeeper集群搭建

发布时间:2016-07-08 18:00:23
当我们的项目在不知不觉中做大了之后,各种问题就出来了,真jb头疼,比如性能,业务系统的并行计算的一致性协调问题,比如分布式架构的事务问题,我们需要多台机器共同commit事务,经典的案例当然是银行转账,支付宝转账这种,如果是一台机器的话,这个还是很方便的,windows中自带了一 ...

  当我们的项目在不知不觉中做大了之后,各种问题就出来了,真jb头疼,比如性能,业务系统的并行计算的一致性协调问题,比如分布式架构的事务问题,

我们需要多台机器共同commit事务,经典的案例当然是银行转账,支付宝转账这种,如果是一台机器的话,这个还是很方便的,windows中自带了一个事务协

调器mstsc,但是呢,你那种很大很牛逼的项目不可能全是windows服务器,对吧,有些人为了解决这个问题,会采用2pc,3pc这种算法,或者是paxos的思

想进行分布式下的一致性处理,当然在这个世界上,真的不需要你自己去开发这种协调性,因为现在已经有了专门解决这种问题的解决方案,比如zookeeper。

 

一:zookeeper集群搭建

  有些人应该明白,zookeeper正是google的chubby的开源实现,使用zookeeper之前,我们先来搭建一个集群。

1. 下载

   从官网上,我们可以看到,zookeeper的最新版本是3.4.8,下载地址是:http://apache.fayea.com/zookeeper/zookeeper-3.4.8/,可以下载一下:

分布式架构中一致性解决方案——Zookeeper集群搭建

 

2. 文件夹配置

接下来我们解压一下,根目录为zkcluster,下面使用clientport(3000,3001,3002)这样的端口作为文件夹名称,里面就是zookeeper解压包,如下面这样:

分布式架构中一致性解决方案——Zookeeper集群搭建

 

3. 配置zoo.cfg

   现在我们有三个文件夹,也就是3个zookeeper程序,在3001/conf/下面有一个zoo_sample.cfg文件,现在我们改成zoo.cfg,并且修改如下:

# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial # synchronization phase can takeinitLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use /tmp for storage, /tmp here is just # example sakes.dataDir=/root/zkcluster/3001/datadataLogDir=/root/zkcluster/3001/logs# the port at which the clients will connectclientPort=3001# the maximum number of client connections.# increase this if you need to handle more clients#maxClientCnxns=6## Be sure to read the maintenance section of the # administrator guide before turning on autopurge.## http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance## The number of snapshots to retain in dataDir#autopurge.snapRetainCount=3# Purge task interval in hours# Set to "0" to disable auto purge feature#autopurge.purgeInterval=1server.1=192.168.161.134:2888:3888server.2=192.168.161.134:2889:3889server.3=192.168.161.134:2890:3890

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:分布式架构中一致性解决方案——Zookeeper集群搭建

关键词:架构

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。