安装zk前置条件
  1. 安装jdk,并配置环境变量
  2. 下载zookeeper。在官网http://zookeeper.apache.org/下载zookeeper,本文中使用使用的版本是:zookeeper-3.3.6
  3. 将文件解压到D:\zookeeper
单机安装
  1. 将解压后的文件重命名,修改后的文件目录为
D:\zookeeper\zookeeper-single
  1. 将zoo_sample.cfg重命名为zoo.cfg,并指定data和log的路径,端口
#tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。
#dataDir:顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。
#dataLogDir:顾名思义就是 Zookeeper 保存日志文件的目录
#clientPort:这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求# 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=D:\\zookeeper\\zookeeper-single\\data
dataLogDir=D:\\zookeeper\\zookeeper-single\\log
# the port at which the clients will connect
# 服务端口
clientPort=2180
#
# 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
  1. 启动zookeeper
D:\zookeeper\zookeeper-single\bin>cd D:\zookeeper\zookeeper-single\bin
D:\zookeeper\zookeeper-single\bin>D:
D:\zookeeper\zookeeper-single\bin>zkServer.cmd

启动日志如下:

D:\zookeeper\zookeeper-single\bin>java "-Dzookeeper.log.dir=D:\zookeeper\zookeeper-single\bin\.." "-Dzookeeper.root.logger=INFO,CONSOLE" -cp "D:\zookeeper\zookeeper-single\bin\..\build\classes;D:\zookeeper\zookeeper-single\bin\..\build\lib\*;D:\zookeeper\zookeeper-single\bin\..\*;D:\zookeeper\zookeeper-single\bin\..\lib\*;D:\zookeeper\zookeeper-single\bin\..\conf" org.apache.zookeeper.server.quorum.QuorumPeerMain "D:\zookeeper\zookeeper-single\bin\..\conf\zoo.cfg"
2020-04-19 11:58:41,389 - INFO  [main:QuorumPeerConfig@90] - Reading configuration from: D:\zookeeper\zookeeper-single\bin\..\conf\zoo.cfg
2020-04-19 11:58:41,401 - WARN  [main:QuorumPeerMain@105] - Either no config or no quorum defined in config, running  in standalone mode
2020-04-19 11:58:41,510 - INFO  [main:QuorumPeerConfig@90] - Reading configuration from: D:\zookeeper\zookeeper-single\bin\..\conf\zoo.cfg
2020-04-19 11:58:41,512 - INFO  [main:ZooKeeperServerMain@94] - Starting server
2020-04-19 11:58:41,550 - INFO  [main:Environment@97] - Server environment:zookeeper.version=3.3.6-1366786, built on 07/29/2012 06:22 GMT
2020-04-19 11:58:41,551 - INFO  [main:Environment@97] - Server environment:host.name=JT3RNV28I7B8K6A
2020-04-19 11:58:41,555 - INFO  [main:Environment@97] - Server environment:java.version=1.8.0_45
2020-04-19 11:58:41,557 - INFO  [main:Environment@97] - Server environment:java.vendor=Oracle Corporation
2020-04-19 11:58:41,559 - INFO  [main:Environment@97] - Server environment:java.home=D:\Program Files\Java\jre1.8.0_45
2020-04-19 11:58:41,560 - INFO  [main:Environment@97] - Server environment:java.class.path=D:\zookeeper\zookeeper-single\bin\..\build\classes;D:\zookeeper\zookeeper-single\bin\..\build\lib\*;D:\zookeeper\zookeeper-single\bin\..\zookeeper-3.3.6.jar;D:\zookeeper\zookeeper-single\bin\..\lib\jline-0.9.94.jar;D:\zookeeper\zookeeper-single\bin\..\lib\log4j-1.2.15.jar;D:\zookeeper\zookeeper-single\bin\..\conf
2020-04-19 11:58:41,565 - INFO  [main:Environment@97] - Server environment:java.library.path=C:\ProgramData\Oracle\Java\javapath;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:\Ruby23-x64\bin;C:\ProgramData\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;D:\MyPath;D:\Program Files\Java\jdk1.8.0_45\bin;D:\Program Files\Apache\apache-maven-3.1.0\bin;D:\Program Files\Apache\apache-ant-1.9.6\bin;D:\Program Files\gradle-2.2.1\bin;D:\Program Files\MongoDB\Server\3.2\bin;D:\Program Files\TortoiseSVN\bin;D:\Program Files\Git\cmd;D:\Program Files\Git\usr\bin;D:\Program Files\TortoiseGit\bin;D:\Library\androidSdk\platform-tools;D:\Program Files (x86)\MySQL\MySQL Server 5.1\bin;D:\Program Files\nodejs\;C:\Android;C:\Windows\System32;D:\Python;C:\Program Files (x86)\HP\Common\HPDestPlgIn\;C:\Program Files (x86)\HP\IdrsOCR_15.3.1129.0\;D:\Python\Scripts\;D:\Python\;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\Users\Administrator\AppData\Roaming\npm;D:\Users\Administrator\AppData\Local\Programs\Fiddler;C:\Program Files (x86)\HP\Common\HPDestPlgIn\;.
2020-04-19 11:58:41,569 - INFO  [main:Environment@97] - Server environment:java.io.tmpdir=C:\Users\ADMINI~1\AppData\Local\Temp\
2020-04-19 11:58:41,570 - INFO  [main:Environment@97] - Server environment:java.compiler=<NA>
2020-04-19 11:58:41,571 - INFO  [main:Environment@97] - Server environment:os.name=Windows 8.1
2020-04-19 11:58:41,576 - INFO  [main:Environment@97] - Server environment:os.arch=amd64
2020-04-19 11:58:41,580 - INFO  [main:Environment@97] - Server environment:os.version=6.3
2020-04-19 11:58:41,581 - INFO  [main:Environment@97] - Server environment:user.name=Administrator
2020-04-19 11:58:41,583 - INFO  [main:Environment@97] - Server environment:user.home=C:\Users\Administrator
2020-04-19 11:58:41,584 - INFO  [main:Environment@97] - Server environment:user.dir=D:\zookeeper\zookeeper-single\bin
2020-04-19 11:58:41,597 - INFO  [main:ZooKeeperServer@673] - tickTime set to 2000
2020-04-19 11:58:41,597 - INFO  [main:ZooKeeperServer@682] - minSessionTimeout set to -1
2020-04-19 11:58:41,601 - INFO  [main:ZooKeeperServer@691] - maxSessionTimeout set to -1
2020-04-19 11:58:41,710 - INFO  [main:NIOServerCnxn$Factory@143] - binding to port 0.0.0.0/0.0.0.0:2180
2020-04-19 11:58:41,730 - INFO  [main:FileSnap@82] - Reading snapshot D:\zookeeper\zookeeper-single\data\version-2\snapshot.0
2020-04-19 11:58:41,740 - INFO  [main:FileTxnSnapLog@256] - Snapshotting: 0
伪集群搭建
  1. 按照上面的步骤搭建好单机节点,并且复制成3份,本文中的目录如下
D:\zookeeper\zookeeper0
D:\zookeeper\zookeeper1
D:\zookeeper\zookeeper2
  1. 修改每一个节点的zoo.cfg中的clientPort、dataDir、dataLogDir

zookeeper0的zoo.cfg修改后

#tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。
#dataDir:顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。
#dataLogDir:顾名思义就是 Zookeeper 保存日志文件的目录
#clientPort:这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求# 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=D:\\zookeeper\\zookeeper0\\data
dataLogDir=D:\\zookeeper\\zookeeper0\\log
# the port at which the clients will connect
clientPort=2180
#
# 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#server.A=B:C:D 其中A是服务器的编号,B是服务器的ip地址,C是leader选举的端口,D是zk节点通信端口
server.0=localhost:12287:13387
server.1=localhost:12288:13388
server.2=localhost:12289:13389

zookeeper1的zoo.cfg修改后

#tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。
#dataDir:顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。
#dataLogDir:顾名思义就是 Zookeeper 保存日志文件的目录
#clientPort:这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求# 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=D:\\zookeeper\\zookeeper1\\data
dataLogDir=D:\\zookeeper\\zookeeper1\\log
# the port at which the clients will connect
clientPort=2181
#
# 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#server.A=B:C:D 其中A是服务器的编号,B是服务器的ip地址,C是leader选举的端口,D是zk节点通信端口
server.0=localhost:12287:13387
server.1=localhost:12288:13388
server.2=localhost:12289:13389

zookeeper2的zoo.cfg修改后

#tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。
#dataDir:顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。
#dataLogDir:顾名思义就是 Zookeeper 保存日志文件的目录
#clientPort:这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求# 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=D:\\zookeeper\\zookeeper2\\data
dataLogDir=D:\\zookeeper\\zookeeper2\\log
# the port at which the clients will connect
clientPort=2182
#
# 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#server.A=B:C:D 其中A是服务器的编号,B是服务器的ip地址,C是leader选举的端口,D是zk节点通信端口
server.0=localhost:12287:13387
server.1=localhost:12288:13388
server.2=localhost:12289:13389
  1. 在各个节点里面的dateDir目录下创建myid文件(注意没有后缀名)
    文件内容就是各个节点的编号,zookeeper0的myid文件里面就是0,zookeeper1的myid文件里面就是1,zookeeper2的myid文件里面就是2
  2. 启动各个节点,集群搭建完毕
配置参数含义

在zoo.cfg中的配置参数的含义如下

  1. tickTime:基本事件单元,这个时间是作为Zookeeper服务器之间或客户端与服务器之间维持心跳的时间间隔,每隔tickTime时间就会发送一个心跳;最小 的session过期时间为2倍tickTime
  2. dataDir:存储内存中数据库快照的位置,除非另有说明,否则指向数据库更新的事务日志。注意:应该谨慎的选择日志存放的位置,使用专用的日志存储设备能够大大提高系统的性能,如果将日志存储在比较繁忙的存储设备上,那么将会很大程度上影像系统性能。
  3. client:监听客户端连接的端口。
  4. initLimit:允许follower连接并同步到Leader的初始化连接时间,以tickTime为单位。当初始化连接时间超过该值,则表示连接失败。
  5. syncLimit:表示Leader与Follower之间发送消息时,请求和应答时间长度。如果follower在设置时间内不能与leader通信,那么此follower将会被丢弃。
  6. server.A=B:C:D
    A:其中 A 是一个数字,表示这个是服务器的编号;
    B:是这个服务器的 ip 地址;
    C:Leader选举的端口;
    D:Zookeeper服务器之间的通信端口。
    配置zk集群需要新增的是 server.A=B:C:D 配置,其中 A 对应myid 文件里面的内容。B是集群的各个IP地址,C:D 是端口配置。
Zookeeper的一些常用命令
  1. 启动zookeeper: ./zkServer.sh start
  2. 关闭zookeeper: ./zkServer.sh stop
  3. 客户端连接 ./zkCli.sh -server localhost:2181
  4. 查询当前zookeeper的状态 ./zkServer.sh status
  5. 客户端连接上zookeeper后,可以使用help命令来查询zookeeper的命令
  6. 关闭与服务端的连接 : close
  7. 连接服务端:connect 127.0.0.1:2181
  8. 创建节点 create /name value
  9. 获取节点的信息 get /name
  10. 列出节点 ls /name
  11. 删除节点信息 delete /name
  12. 列出节点 ls2 /name 是ls的加强版
  13. 列出历史执行命令 history
  14. 重新执行某个命令和history结合使用 redo 20
  15. sync 强制同步
  16. stat 查看节点信息
  17. 显示配额 listquota /name
  18. 设置配额 setquota /name
  19. 删除配额 delquota /name
  20. addauth命令用于节点认证,使用方式:如addauth digest username:password
  21. setAcl命令用于设置节点Acl,Acl由三部分构成:1为scheme,2为user,3为permission,一般情况下表示为scheme

    zookeeper在window下的搭建相关推荐

    1. window下eclipse搭建C/C++开发环境(超简单无需插件版) .

      经过若干google之后(百度就不用说了),又经过了若干尝试,终于用最简单的步骤配起来了.(一些比较旧的文章写的太繁杂了,随着各个工具的升级,搭建环境很简单了). 前言:写博客不是为了炫耀什么.发泄什 ...

    2. window下eslipse搭建django遇到的问题以及解决方法积累(持续更新)

      1.模板系统: 问题:because environment variable DJANGO_SETTINGS_MODULE is undefined 解决:右键 -- Run As -- Run C ...

    3. window下zookeeper的下载启动和报错等问题

      在使用dubbo等需要用到zookeeper,之前window下本地部署,启动一直有问题,后面折腾了下才部署成功,此次记录下来. 将zookeeper下载之后,解压到指定目录即可,无需安装.例如:解压 ...

    4. window下搭建qnx编译环境

      引言 window下搭建qnx编译环境 流程说明 1. 前置条件说明 1.1 安装cmake 下载地址(https://cmake.org/files/v3.18/ 的make-3.18.1-win6 ...

    5. 第1章 Window下VSCode的C语言开发环境搭建 (一)

      文章目录 文档视频讲解链接地址 第01章 开发环境搭建 1.1 C语言开发环境搭建 1. 常用的C语言开发环境介绍 VC++ 6.0 VS 2019 Clion DevC++ vim编辑 VSCode ...

    6. window下使用nw.js开发桌面应用程序环境的搭建

      安装node window下去node官网下载长期支持版本或者最新稳定版都可以. 按装nw用来管理和按装nw.js npm install -g nrm # 用来设置npm镜像地址 npm insta ...

    7. 基于zookeeper的solrCloud集群搭建

      转自:https://blog.csdn.net/yougoule/article/details/78445759  基于原文对实践遇到的问题稍作补充 1.安装及搭建相关环境 1.1环境准备 cen ...

    8. window下安装Memcache

      说来惭愧,从事PHP已经1年多了,但是很多PHP相关的知识都不知道. 前一阵子看到网上流传了很久的面试题,才了解到原来还有memcache这么个东西-_-. memcache 具体是什么Google一 ...

    9. zookeeper 在 windows 下配置伪集群环境

      安装启动zookeeper 在 Apache zookeeper 官网下载 https://www.apache.org/dyn/closer.cgi/zookeeper/ 下载后解压,我使用的是3. ...

    最新文章

    1. [转]#pragma once和#pragma comment
    2. 对matlab中colormap的解释及fill、imshow的用法说明
    3. 认识和入门 WebRTC
    4. textFiled输入字数的控制问题之—把带输入的拼音也判断了
    5. 新开通博客园,纪念一下。
    6. 双城记s001_双城记! (使用数据讲故事)
    7. SpringBoot通过配置文件自动加载到map中
    8. AD RMS高可用(二)为rms群集服务器申请证书
    9. fread读取同一个文件得到缓冲区大小不同_c++日志文件操作
    10. python中函数的参数传递
    11. 把ICDAR2019-LSVT原始数据集转为REC任务识别数据
    12. 桌游跑团用roll点器,可以自己设置色字的数量和种类
    13. BLUElegend传奇引擎不使用路由器架设单传奇的办法
    14. linux 鼠标滚轮 太快,Linux - 微软无线鼠标滚动过快问题
    15. 小学教育怎么选择特别容易写的论文选题?
    16. 技术导航网站源码_qq技术导航_小刀娱乐网源码
    17. Unity 2D平面显示3D模型(RenderTextrue)
    18. SAP中库存周转率算法
    19. 【掌控板2.0】<Mind+>:光控灯、声控灯、语音识别模块、实现Easy IoT上MQTT消息的通讯实验
    20. antd组件库封装44-添加字体变量方案

    热门文章

    1. SAP实施方法论之探讨-现状调研与需求分析
    2. MM模块部分名词解释
    3. SMARTFORM的使用BSIS会计凭证中的字段DMBTR(本币金额)报错
    4. 波司登的高端之路,难走!
    5. kali debian 安装mysql_在Kali Linux和Debian 8/9 64位上安装Wine的方法
    6. php iso8601 gmt,如何使用PHP以iso 8601格式顯示日期
    7. java使用druid maven_SpringMVC+Spring+Mybatis整合,使用druid连接池,声明式事务,maven配置...
    8. curl下载失败返回0_curl返回常见错误码
    9. CTF-Xortool,windows上的安装与使用
    10. bash: /etc/apt/sources.list: 权限不够的解决办法