[ZooKeeper] 2 环境搭建
- 单机模式:ZooKeeper 运行在一台服务器上,适合测试环境;
- 伪集群模式:在一台物理机上运行多个 ZooKeeper 实例;
- 集群模式:ZooKeeper 运行在一个集群上,称为 ensemble,适合生产环境;
准备工作
- 下载地址:http://zookeeper.apache.org/releases.html,本文以 zookeeper-3.4.11.tar.gz 为例。
- JDK 环境配置:http://www.cnblogs.com/memento/p/8660021.html
Windows 下的配置
单机模式(适合开发环境)
# ----------------------------------------------------------------------
# 基本配置(最低配置)
# ---------------------------------------------------------------------- # the port at which the clients will connect
# 监听客户端连接的端口
clientPort=2181 # The number of milliseconds of each tick
# 服务器之间或者客户端与服务器之间维持心跳的时间间隔,
# 会话(session)的过期时间为2倍的 tickTime;
tickTime=2000 # the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
# 存储内存数据库快照的位置,除非另外说明,否则就是指数据库的更新事务日志
dataDir=../data
bin\zkCli.cmd -server 127.0.0.1:181
[zk: 127.0.0.1:2181(CONNECTED) 0] help
ZooKeeper -server host:port cmd args
stat path [watch]
set path data [version]
ls path [watch]
delquota [-n|-b] path
ls2 path [watch]
setAcl path acl
setquota -n|-b val path
history
redo cmdno
printwatches on|off
delete path [version]
sync path
listquota path
rmr path
get path [watch]
create [-s] [-e] path data acl
addauth scheme auth
quit
getAcl path
close
connect host:port
[zk: 127.0.0.1:2181(CONNECTED) 1] ls /
[zookeeper] [zk: 127.0.0.1:2181(CONNECTED) 2] create /zk_test my_data
Created /zk_test [zk: 127.0.0.1:2181(CONNECTED) 3] ls /
[zookeeper, zk_test] [zk: 127.0.0.1:2181(CONNECTED) 4] get /zk_test
my_data
cZxid = 0x2a
ctime = Wed Apr 11 10:49:31 CST 2018
mZxid = 0x2a
mtime = Wed Apr 11 10:49:31 CST 2018
pZxid = 0x2a
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 7
numChildren = 0 [zk: 127.0.0.1:2181(CONNECTED) 5] set /zk_test junk
cZxid = 0x2a
ctime = Wed Apr 11 10:49:31 CST 2018
mZxid = 0x2b
mtime = Wed Apr 11 10:50:33 CST 2018
pZxid = 0x2a
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0 [zk: 127.0.0.1:2181(CONNECTED) 6] delete /zk_test [zk: 127.0.0.1:2181(CONNECTED) 7] ls /
[zookeeper]
命令 | 描述 |
conf | 打印服务配置的详细信息 |
cons | 列举所有连接到该服务器的客户端的连接或会话,包括发送/接收的包数量,会话 id,操作延迟,最后执行的操作等 |
crst | 重置所有连接或会话的统计信息 |
dump | 列举未经处理的会话和临时节点,只对 leader 有效。 |
envi | 打印服务环境的详细信息 |
ruok | 测试服务器是否处于正确状态,如果是返回"imok",否则不作任何响应。返回"imok"只是表示服务器进程是活动的,且绑定到指定的客户端端口,并不代表该服务器已经加入到集群中。 |
srst | 重置服务器统计信息。 |
srvr | 列举服务器的所有详细信息。 |
stat | 列举服务器及其连接的客户端的简要信息。 |
wchs | 列举服务器上 watch 的简要信息。 |
wchc | 通过 session 列举服务器上 watch 的详细信息。输出一个与 watch 相关的会话(连接)列表。 |
wchp | 通过路径列举服务器上 watch 的详细信息。输出一个与 watch 相关的路径(znode)列表。 |
mntr | 输出一些用于监测集群健康的变量。 |
C:\solrCloud\zk_server_fake\bin>echo mntr | nc localhost 2181
zk_version 3.4.11-37e277162d567b55a07d1755f0b31c32e93c01a0, built on 11/01/2017 18:06 GMT
zk_avg_latency 0
zk_max_latency 0
zk_min_latency 0
zk_packets_received 7
zk_packets_sent 6
zk_num_alive_connections 1
zk_outstanding_requests 0
zk_server_state follower
zk_znode_count 4
zk_watch_count 0
zk_ephemerals_count 0
zk_approximate_data_size 27
C:\solrCloud\zk_server_fake\bin>echo ruok | nc localhost 2181
imok
伪集群模式
# ----------------------------------------------------------------------
# 基本配置(最低配置)
# ---------------------------------------------------------------------- # the port at which the clients will connect
# 监听客户端连接的端口
clientPort=2181 # The number of milliseconds of each tick
# 服务器之间或者客户端与服务器之间维持心跳的时间间隔,
# 会话(session)的过期时间为2倍的 tickTime;
tickTime=2000 # the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
# 存储内存数据库快照的位置,除非另外说明,否则就是指数据库的更新事务日志
dataDir=../data1 # ----------------------------------------------------------------------
# 高级配置
# ---------------------------------------------------------------------- # 存储事务日志的位置,分离出默认的 dataDir 设置中包含的更新事务日志记录,避免日志和快照之间的竞争
dataLogDir=../log1 # Java 属性:zookeeper.globalOutstandingLimit
# 客户端提交请求的速度要比 ZooKeeper 处理请求的速度快很多,尤其有大量的客户端的时候。
# 为了避免由于大量请求导致 ZooKeeper 内存耗尽,ZooKeeper 将调节客户端以保证系统中只有不足 globalOutstandingLimit 个未处理请求。
# 默认值 1000
# globalOutstandingLimit=1000 # Java 属性:zookeeper.preAllocSize
# 为了避免地址寻址,ZooKeeper 给事务日志文件分配了 preAllocSize 字节大小的空间。默认块大小为 64M。
# 如果经常使用快照则可以修改该值,减小块大小。
# preAllocSize # Java 属性:zookeeper.snapCount
# ZooKeeper 使用快照和一个快照日志文件来记录它的事务。snapCount 决定了快照时在事务日志中可以记录的事务数量。
# 为了避免集群中所有的机器同时拍摄快照,每个 ZooKeeper 服务器只有在事务日志中的事务数量达到一个值时才拍摄快照,
# 该值时在运行时生成的介于[snapCount/2+1, snapCount]范围内的随机数。默认值 100000
# snapCount=100000 # the maximum number of client connections.
# increase this if you need to handle more clients
# 限制 ZooKeeper 集群中一个客户端的并发连接数量,通过 IP 地址进行判断识别。
# 可以用于阻止某些 DoS 攻击,包括 file descriptor exhaustion。默认值 60。
# 设置为0时表示取消并发数量限制。
# maxClientCnxns=60 # 3.3.0新增设置
# 最小会话超时时间,默认 minSession=2*tickTime
# minSessionTimeout
# 最大会话超时时间,默认 maxSession=20*tickTime
# maxSessionTimeout # 3.4.0新增设置
# 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 # ----------------------------------------------------------------------
# 集群配置
# ---------------------------------------------------------------------- # The number of ticks that the initial
# synchronization phase can take
# 允许 follower 连接并同步到 leader 的初始化连接次数,以 tickTime 为单位,总计时长为 initLimit*tickTime 毫秒
initLimit=10 # The number of ticks that can pass between
# sending a request and getting an acknowledgement
# leader 与 follower 之间发送消息时,请求和应答之间的通信次数,以 tickTime 为单位,总计时长为 syncLimit*tickTime 毫秒
syncLimit=5 # A:一个正整数,表示服务器的编号
# B:服务器的 IP 地址
# C:ZooKeeper 服务器之间的通信端口
# D:leader 选举端口
# server.A=B:C:D
server.1=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389
clientPort=2182
dataDir=../data2
dataLogDir=../log2
zoo3.cfg,除了如下配置不同,其他与 zoo1.cfg 一致
clientPort=2183
dataDir=../data3
dataLogDir=../log3
C:\solrCloud\zk_server_fake\bin>zkServer1.cmd C:\solrCloud\zk_server_fake\bin>call "C:\Program Files\Java\jdk1.8.0_162"\bin\java "-Dzookeeper.log.dir=C:\solrCloud\zk_server_fake\bin\.." "-Dzookeeper.root.logger=INFO,CONSOLE" -cp "C:\solrCloud\zk_server_fake\bin\..\build\classes;C:\solrCloud\zk_server_fake\bin\..\build\lib\*;C:\solrCloud\zk_server_fake\bin\..\*;C:\solrCloud\zk_server_fake\bin\..\lib\*;C:\solrCloud\zk_server_fake\bin\..\conf" org.apache.zookeeper.server.quorum.QuorumPeerMain "..\conf\zoo1.cfg"
2018-04-11 11:46:40,470 [myid:] - INFO [main:QuorumPeerConfig@136] - Reading configuration from: ..\conf\zoo1.cfg
2018-04-11 11:46:40,489 [myid:] - INFO [main:QuorumPeer$QuorumServer@184] - Resolved hostname: localhost to address: localhost/127.0.0.1
2018-04-11 11:46:40,489 [myid:] - INFO [main:QuorumPeer$QuorumServer@184] - Resolved hostname: localhost to address: localhost/127.0.0.1
2018-04-11 11:46:40,491 [myid:] - INFO [main:QuorumPeer$QuorumServer@184] - Resolved hostname: localhost to address: localhost/127.0.0.1
2018-04-11 11:46:40,491 [myid:] - INFO [main:QuorumPeerConfig@398] - Defaulting to majority quorums
2018-04-11 11:46:40,503 [myid:1] - INFO [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2018-04-11 11:46:40,503 [myid:1] - INFO [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2018-04-11 11:46:40,503 [myid:1] - INFO [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2018-04-11 11:46:40,560 [myid:1] - INFO [main:QuorumPeerMain@130] - Starting quorum peer
2018-04-11 11:46:40,746 [myid:1] - INFO [main:ServerCnxnFactory@117] - Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory
2018-04-11 11:46:40,747 [myid:1] - INFO [main:NIOServerCnxnFactory@89] - binding to port 0.0.0.0/0.0.0.0:2181
2018-04-11 11:46:40,753 [myid:1] - INFO [main:QuorumPeer@1158] - tickTime set to 2000
2018-04-11 11:46:40,753 [myid:1] - INFO [main:QuorumPeer@1204] - initLimit set to 10
2018-04-11 11:46:40,753 [myid:1] - INFO [main:QuorumPeer@1178] - minSessionTimeout set to -1
2018-04-11 11:46:40,753 [myid:1] - INFO [main:QuorumPeer@1189] - maxSessionTimeout set to -1
2018-04-11 11:46:40,760 [myid:1] - INFO [main:QuorumPeer@1467] - QuorumPeer communication is not secured!
2018-04-11 11:46:40,761 [myid:1] - INFO [main:QuorumPeer@1496] - quorum.cnxn.threads.size set to 20
2018-04-11 11:46:40,764 [myid:1] - INFO [main:QuorumPeer@668] - currentEpoch not found! Creating with a reasonable default of 0. This should only happen when you are upgrading your installation
2018-04-11 11:46:40,771 [myid:1] - INFO [main:QuorumPeer@683] - acceptedEpoch not found! Creating with a reasonable default of 0. This should only happen when you are upgrading your installation
2018-04-11 11:46:40,781 [myid:1] - INFO [ListenerThread:QuorumCnxManager$Listener@736] - My election bind port: localhost/127.0.0.1:3387
2018-04-11 11:46:40,789 [myid:1] - INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumPeer@909] - LOOKING
2018-04-11 11:46:40,790 [myid:1] - INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FastLeaderElection@820] - New election. My id = 1, proposed zxid=0x0
2018-04-11 11:46:40,792 [myid:1] - INFO [WorkerReceiver[myid=1]:FastLeaderElection@602] - Notification: 1 (message format version), 1 (n.leader), 0x0 (n.zxid), 0x1 (n.round), LOOKING (n.state), 1 (n.sid), 0x0 (n.peerEpoch) LOOKING (my state)
2018-04-11 11:48:16,324 [myid:1] - WARN [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@584] - Cannot open channel to 2 at election address localhost/127.0.0.1:3388
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:558)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:610)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:845)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:957)
2018-04-11 11:48:32,332 [myid:1] - INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumPeer$QuorumServer@184] - Resolved hostname: localhost to address: localhost/127.0.0.1
2018-04-11 11:48:33,338 [myid:1] - WARN [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumCnxManager@584] - Cannot open channel to 3 at election address localhost/127.0.0.1:3389
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectOne(QuorumCnxManager.java:558)
at org.apache.zookeeper.server.quorum.QuorumCnxManager.connectAll(QuorumCnxManager.java:610)
at org.apache.zookeeper.server.quorum.FastLeaderElection.lookForLeader(FastLeaderElection.java:845)
at org.apache.zookeeper.server.quorum.QuorumPeer.run(QuorumPeer.java:957)
2018-04-11 11:48:33,338 [myid:1] - INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:QuorumPeer$QuorumServer@184] - Resolved hostname: localhost to address: localhost/127.0.0.1
2018-04-11 11:48:33,340 [myid:1] - INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FastLeaderElection@854] - Notification time out: 51200
follow。
leader,剩下两个为 follow。
查看服务器状态,需要安装 Cygwin 工具,然后执行如下命令查看三个服务器的状态:
集群模式
参考说明
[ZooKeeper] 2 环境搭建的更多相关文章
- dubbo+zookeeper+dubboadmin环境搭建
4.环境搭建 4.1.zookeeper注册中心的配置安装(在windows平台下,Linux类似,见官方文档)(Redis注册中心安装,简易注册中心安装,简易监控中心安装,见官方文档) 下载zook ...
- Zookeeper+Dubbo环境搭建与Demo测试
环境准备: 1. zookeeper-3.4.14 (下载地址:http://archive.apache.org/dist/zookeeper/) 2. dubbo-0.2.0 (下载地址 ...
- dubbo+zookeeper简单环境搭建
dubbo+zoopeeper例子 [TOC] 标签(空格分隔): 分布式 dubbo dubbo相关 dubbo是目前国内比较流行的一种分布式服务治理方案.还有一种就是esb了.一般采用的是基于Ap ...
- Zookeeper 分布式环境搭建
一.前期环境 安装概览 IP Host Name Software 192.168.23.128 ae01 JDK 1.7 192.168.23.129 ae02 JDK 1. ...
- 十五、Hadoop学习笔记————Zookeeper的环境搭建
linux中/opt一般用来存放应用/var目录一般用来存放日志 sample为样例文件,复制一份zoo.cfg文件 配置zoo文件,id为服务器id(整数),host为服务器的ip地址,第一个por ...
- zookeeper编译环境搭建
当前我使用的jdk环境是1.8 当看到build successful的时候 说明已经构建成功,在这个期间会下载一些工具,发现下载很慢,比如ivy-2.4.0.jar包,如果下载不下来,可以进行手工下 ...
- zookeeper+Dubbo环境搭建及简单Demo
1 安装zk https://www.cnblogs.com/feifeicui/p/11175502.html 2 安装 dubbo-admin https://www.cnblogs.com/fe ...
- Linux系统zookeeper环境搭建(单机、伪分布式、分布式)
本人现在对zookeeper的环境搭建做一个总结,一般zookeeper的安装部署可以有三种模式,单机模式.伪分布式和分布式,这三种模式在什么时候应用具体看大家的使用场景,如果你只有一台机器且只是想自 ...
- Hadoop学习笔记—14.ZooKeeper环境搭建
从字面上来看,ZooKeeper表示动物园管理员,这是一个十分奇妙的名字,我们又想起了Hadoop生态系统中,许多项目的Logo都采用了动物,比如Hadoop采用了大象的形象,所以我们可以猜测ZooK ...
随机推荐
- java排序算法(五):快速排序
java排序算法(五):快速排序 快速排序是一个速度非常快的交换排序算法,它的基本思路很简单,从待排的数据序列中任取一个数据(如第一个数据)作为分界值,所有比它小的元素放到左边.所有比它大的元素放到右 ...
- color 圆盘染色
Color 圆盘染色 题目大意:给你一个圆盘,等分成n个扇形,有m种颜色,每两个相邻的扇形不能相交,求染色方案数. 注释:m,n<=$10^6$. 想法:这题是小圆盘染色的加强版(小圆盘染色?) ...
- 测试驱动开发实践3————testSave之新增用户
内容指引 1.确定新增用户的业务规则 2.根据业务规则设计测试用例 3.为测试用例赋值并驱动开发 一.确定新增用户的规则 1.注册用户允许通过"用户名+密码"."手机号+ ...
- python(函数)
Python中的namespace Python中通过提供 namespace 来实现重名函数/方法.变量等信息的识别,其一共有三种 namespace,分别为: local namespace: 作 ...
- java.text.DateFormat 多线程并发问题
在日常开发中,java.text.DateFormat 应该算是使用频率比较高的一个工具类,经常会使用它 将 Date 对象转换成字符串日期,或者将字符串日期转化成 Date 对象.先来看一段眼熟的代 ...
- JavaScript(第十八天)【DOM基础】
学习要点: 1.DOM介绍 2.查找元素 3.DOM节点 4.节点操作 DOM(Document Object Model)即文档对象模型,针对HTML和XML文档的API(应用程序接口).DOM描绘 ...
- C语言函数嵌套调用作业总结
成绩管理系统作业小结 devc中出现"ID Return"问题,我帮很多同学看完后发现,大部分还是自身程序问题,如全局变量大小写错误.没有添加c文件进工程等等.所以对于" ...
- 201421123042 《Java程序设计》第3周学习总结
#Week03-面向对象入门 1. 本周学习总结 1.1写出你认为本周学习中比较重要的知识点关键词,如类.对象.封装等 本周学习关键词:类,对象,封装,关键词:final,this,statis. 1 ...
- nyoj 回文字符串
回文字符串 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 所谓回文字符串,就是一个字符串,从左到右读和从右到左读是完全一样的,比如"aba".当 ...
- [Redis源码阅读]redis持久化
作为web开发的一员,相信大家的面试经历里少不了会遇到这个问题:redis是怎么做持久化的? 不急着给出答案,先停下来思考一下,然后再看看下面的介绍.希望看了这边文章后,你能够回答这个问题. 为什么需 ...