为了学习dubbo框架,需要另外学习一个注册中心的组件——zookeeper。
什么是zookeeper?
zookeeper是分布式协调服务组件。它充当服务注册中心的服务器,能够使分布式应用的调用保持一致性。
简单地说即是,多个应用(订单应用、用户信息应用、短信应用、支付应用等应用模块)的增删改查方法在注册中心进行注册,统一标识,各应用在调用某个模块时,通过注册服务名寻找方法,完成调用。zookeeper就是为程序一致性提供服务的。
以下为百度百科解释:
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。
ZooKeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。
ZooKeeper包含一个简单的原语集,[1] 提供Java和C的接口。
ZooKeeper代码版本中,提供了分布式独享锁、选举、队列的接口,代码在zookeeper-3.4.3\src\recipes。其中分布锁和队列有Java和C两个版本,选举只有Java版本。
下载zookeeper
http://mirrors.hust.edu.cn/apache/zookeeper/
安装和使用:
1.解压
2.修改conf目录下zoo_sample.cfg文件名为zoo.cfg
参数修改说明:
# The number of milliseconds of each tick zookeeper与业务服务器或客户端维持连接检验的心跳毫秒数
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes. zookeeper保存数据与日志文件的目录
dataDir=E:/ent_softeware/zookeeper-3.4.10/data
# the port at which the clients will connect zookeeper服务端口号
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# 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=1
3.启动
bin目录下启动zkServer.cmd即可
可用bin目录下的zkCli.cmd连接测试是否已启动