Zookeeper是一个开源的分布式协调服务,其设计目标是将那些复杂的且容易出错的分布式一致性服务封装起来,构成一个高效可靠的原语集,并以一些简单的接口提供给用户使用。ZooKeeper 背后的动机是减轻分布式应用程序从头开始实现协调服务的责任。
Zookeeper是一个典型的分布式数据一致性的解决方案,分布式应用程序可以基于它实现诸如数据订阅/发布、负载均衡、命名服务、集群管理、分布式锁和分布式队列等功能。
从官网? Apache ZooKeeper?下载相应版本,这里版本为 3.7.2(本系列后续所用版本也是)。
mkdir -p /home/zookeeper/file
tar -zxvf apache-zookeeper-3.7.2-bin.tar.gz -C zookeeper-3.7.2
cp -r zookeeper-3.7.2 zookeeper1
cd zookeeper1
mkdir data
mkdir logs
cd data
vim myid
cd /home/zookeeper/file/zookeeper1/conf
cp zoo_sample.cfg zoo.cfg
dataDir=/home/zookeeper/file/zookeeper1/data
server.1=192.168.119.142:2881:3881
server.2=192.168.119.142:2882:3882
server.3=192.168.119.142:2883:3883
? ? ? ? 注意:dataDir 为当前节点的 data 目录路径,这里为 zookeeper1节点的
? ? ? ? ? ? ? ? ? server.服务器ID有几个配置几个(这里为3个),配置表达式如下:
? ? ? ? ? ? ? ? ??server.服务器ID=服务器IP地址:服务器之间通信端?:服务器之间投票选举端?
cp -r zookeeper1 zookeeper2
cp -r zookeeper1 zookeeper3
dataDir=/home/zookeeper/file/zookeeper2/data
clientPort=2182
dataDir=/home/zookeeper/file/zookeeper3/data
clientPort=2183
./zkServer.sh start
./zkServer.sh status
./zkServer.sh stop
选择 zookeeper3 的 zoo.cfg 配置给列位参照(不同版本可能不同)
# The number of milliseconds of each tick
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.
dataDir=/home/zookeeper/file/zookeeper3/data
# the port at which the clients will connect
clientPort=2183
server.1=192.168.119.142:2881:3881
server.2=192.168.119.142:2882:3882
server.3=192.168.119.142:2883:3883
# 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
## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
启动全部节点后,可通过多种方式确认集群的可用性,这里选择客户端工具
?Zookeeper是一个强大的分布式协调工具,接下来会持续更新Zookeeper的其他内容,包括但不限于分布式锁、分布式队列、源码分析等等。