Zookeeper常用Linux命令整理

Posted ZSYL

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Zookeeper常用Linux命令整理相关的知识,希望对你有一定的参考价值。

本地模式安装

  • 启动服务端:bin/zkServer.sh start
  • 查看状态:bin/zkServer.sh status
  • 启动客户端:bin/zkCli.sh
  • 退出:quit
  • 关闭服务:bin/zkServer.sh stop
  • 查看当前目录下的文件:ls /

Zookeeper配置参数解读

  • tickTime=2000ms
  • initLimit=10次,连接时长限制10次心跳,10*2s

Zookeeper分布式安装

集群分发Zookeeper:

xsync zookeeper-3.4.10/

至少配置三台服务器

创建服务器编号

  • 创建服务器编号
  • 在zkData中创建myid
[zs@hadoop102 zookeeper-3.4.10]$ cd zkData/
[zs@hadoop102 zkData]$ touch myid
  • 集群间同步分发
xsync myid

配置zoo.cfg文件

[zs@hadoop102 zkData]$ cd ..
[zs@hadoop102 zookeeper-3.4.10]$ cd conf
[zs@hadoop102 conf]$ pwd
/opt/module/zookeeper-3.4.10/conf
[zs@hadoop102 conf]$ vim zoo.cfg
[zs@hadoop102 conf]$ xsync zoo.cfg 

添加以下内容:

#######################cluster##########################
server.2=hadoop102:2888:3888
server.3=hadoop103:2888:3888
server.4=hadoop104:2888:3888
  • 启动三台服务器上的zkServer:
[zs@hadoop104 zookeeper-3.4.10]$ bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower

启动客户端:

bin/zkCli.sh
[zk: localhost:2181(CONNECTED) 0] ls /
[zookeeper]

查看详细的信息:

ls2/
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] ls /
[zookeeper]
[zk: localhost:2181(CONNECTED) 1] ls2 /
[zookeeper]
cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
pZxid = 0x0
cversion = -1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 1

创建节点

创建节点:

[zk: localhost:2181(CONNECTED) 2] create /sanguo "jinlian"

查看三国下面的文件:

ls /sanguo

获取数据:

[zk: localhost:2181(CONNECTED) 9] get /sanguo/shuguo
liubei
cZxid = 0x100000004
ctime = Tue Sep 28 10:20:02 CST 2021
mZxid = 0x100000004
mtime = Tue Sep 28 10:20:02 CST 2021
pZxid = 0x100000004
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 6
numChildren = 0

创建短暂的节点:

[zk: localhost:2181(CONNECTED) 10] create -e /sanguo/wuguo "zhouyu"
Created /sanguo/wuguo

设置节点数据:

set /sanguo/shuguo "diaochan"

获取节点监听:

[zk: localhost:2181(CONNECTED) 4] get /sanguo watch
jinlian
cZxid = 0x100000003
ctime = Tue Sep 28 10:10:38 CST 2021
mZxid = 0x100000003
mtime = Tue Sep 28 10:10:38 CST 2021
pZxid = 0x100000008
cversion = 4
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 7
numChildren = 2

监听一次有效!

删除节点

delete /sanguo/banzhang

递归删除文件夹

rmr /sanguo

查看节点状态

stat /sanguo

以上是关于Zookeeper常用Linux命令整理的主要内容,如果未能解决你的问题,请参考以下文章

IOS开发-OC学习-常用功能代码片段整理

常用python日期日志获取内容循环的代码片段

Linux · Zookeeper的安装使用及常用命令,虚拟机ping外网,linux防火墙设置

Linux系统:centos7下搭建ZooKeeper3.4中间件,常用命令总结

猿创征文|[Zookeeper]快速上手Zookeeper.Zookeeper的初识别,安装,znode节点的理解,常用命令,Wacher机制,ACL权限控制及上述功能在idea的代码实现

Linux系统:centos7下搭建ZooKeeper3.4中间件,常用命令总结