欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ZooKeeper 安装

程序员文章站 2022-05-07 15:41:45
...

1. zookeeper 安装

本文参考ZooKeeper Getting Started Guide编写。

ZooKeeper概览

视本机具体情况选择下载,本次使用zookeeper-3.4.12.tar.gz

1. Windows下单机安装

1.1 ZooKeeper下载

  • 解压到安装目录。
  • 新建一个配置文件conf/zoo.cfg
dataDir=D:\\ProgramFiles\\zookeeper-3.4.12\\data
clientPort=2181

tickTime:指定了ZooKeeper的基本时间单位(以毫秒为单位)。
dataDir:存储内存数据快照位置。
clientPort:监听客户端连接端口。

  • 启动ZooKeeper
$ bin\zkServer.cmd start

ZooKeeper 安装

  • 连接ZooKeeper
$  bin\zkCli.cmd -server 127.0.0.1:2181

ZooKeeper 安装

  • 简单命令
    • create znode
[zkshell: 9] create /zk_test my_data
Created /zk_test
  • 查看目录
[zkshell: 11] ls /
[zookeeper, zk_test]

[zkshell: 9] create /zk_test my_data
Created /zk_test

  • 查看 zk_test 这个znode对应的数据
[zkshell: 12] get /zk_test
my_data
cZxid = 5
ctime = Fri Jun 05 13:57:06 PDT 2009
mZxid = 5
mtime = Fri Jun 05 13:57:06 PDT 2009
pZxid = 5
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0
dataLength = 7
numChildren = 0
  • 修改节点数据
[zkshell: 14] set /zk_test junk
cZxid = 5
ctime = Fri Jun 05 13:57:06 PDT 2009
mZxid = 6
mtime = Fri Jun 05 14:01:52 PDT 2009
pZxid = 5
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0
dataLength = 4
numChildren = 0

查看修改节点后的数据

[zkshell: 15] get /zk_test
junk
cZxid = 5
ctime = Fri Jun 05 13:57:06 PDT 2009
mZxid = 6
mtime = Fri Jun 05 14:01:52 PDT 2009
pZxid = 5
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0
dataLength = 4
numChildren = 0
  • 删除节点
[zkshell: 16] delete /zk_test

查看节点是否还存在

[zkshell: 17] ls /
[zookeeper]

2. windows 集群安装(伪集群)

参考 http://blog.csdn.net/a906998248/article/details/50815031

官方建议集群模式是奇数台服务。至少三台。
http://zookeeper.apache.org/doc/current/zookeeperStarted.html
For replicated mode, a minimum of three servers are required, and it is strongly recommended that you have an odd number of servers. If you only have two servers, then you are in a situation where if one of them fails, there are not enough machines to form a majority quorum. Two servers is inherently less stable than a single server, because there are two single points of failure.

3.zookeeper管理参考文档

相关标签: zookeeper

上一篇: 搭建memcache

下一篇: MySQL数据库