大数据框架开发基础之Zookeeper入门 (3)

这是我的zookeeper的集群环境配置:

# The number of milliseconds of each tick tickTime=30000 # 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=http://www.likecs.com/opt/module/zookeeper-3.4.10/dataDir # the port at which the clients will connect 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. # # #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.101=hadoop101:2888:3888 server.102=hadoop102:2888:3888 server.103=hadoop103:2888:3888

在我们的 /opt/module/zookeeper-3.4.10/dataDir中,我们需要添加 myid文件,且每个节点的myid内容必须保持不一致,如笔者的分别为:101,102,103.内容如下:

101

随后,我们便分发到各个机器上去。按要求修改相应的2内容。

Zookeeper的基本命令操作

我们看下Zookeeper的客户端操作:

1.进入客户端

bin/zkCli.sh

2.显示所有的操作命令

help

3.查看当前znode中包含的内容

ls /

4.查看当前znode中详细数据信息

ls2 /

5.分别创建2个普通节点

create /sanguo "jinlian" create /sanguo/shuguo "liubei"

6.获得节点的值

get /sanguo

7.创建短暂节点

create -e /sanguo/wuguo "zhouyu" # 仅在当前客户端下可以看到的目录,退出当前客户端或者使用第二客户端当前所创建的目录军备自动删除

8.创建带序号的节点

# 先创建一个普通的根节点 create /sanguo/weiguo "caocao" # 开始创建一个带序号的节点 create -s /sanguo/weiguo/xiaoqiao "jinlian" create -s /sanguo/weiguo/daqiao "jinlian" create -s /sanguo/weiguo/diaocan "jinlian"

9.修改节点数据值

set /sanguo/weiguo "simayi"

10.节点的值变化监听

get /sanguo watch

11.节点的子节点变化监听(路径变化)

# 在hadoop104主机上注册监听/sanguo节点的子节点变化 ls /sanguo watch # 在hadoop103主机/sanguo节点上创建子节点 create /sanguo/jin "simayi" Created /sanguo/jin # 观察hadoop104主机收到子节点变化的监听

12.删除节点

delete /sanguo/jin

13.递归删除节点

rmr /sanguo/shuguo

14.查看节点状态

stat /sanguo Zookeeper API

这部分内容,后续有时间在写,目前这个API用的比较少,至少我所在的公司不会有这个要求。读者也可以在网上搜索,会有一大堆的。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwzzzg.html