ZooKeeper使用

配置

  • 1.将conf目录下的zoo_sample.cfg重名为zoo.cfg。

  • 2.配置server.1=localhost:2888:3888。其中“1”代表集群中的节点序号。

  • 3.在dataDir下面创建myid文件,内容为“1”。

配置如下:


# 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=/var/lib/zookeeper



# 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



server.1=localhost:2888:3888

启动服务

sudo ./zkServer.sh start

ZooKeeper JMX enabled by default

Using config: /opt/zookeeper/zookeeper-3.4.7/bin/../conf/zoo.cfg

Starting zookeeper … STARTED

测试启动成功

telnet 127.0.0.1 2181

停止服务

sudo sh zkServer.sh stop

客服端脚本

启动客服端命令终端:

sudo sh zkCli.sh 

或者:

sudo sh zkCli.sh -server ip:port

创建数据节点

create [-s] [-e] path data acl

-s 代表顺序,-e代表临时节点。默认为持久节点。

实例:

[zk: localhost:2181(CONNECTED) 11] create -s /test foo

Created /test0000000001

列出节点

ls path [watch]

实例:

[zk: localhost:2181(CONNECTED) 8] ls /

[example, zookeeper]

查看数据节点

get path [watch]

实例:

[zk: localhost:2181(CONNECTED) 9] get /example

init

cZxid = 0x5

ctime = Sun Jan 24 11:09:58 CST 2016

mZxid = 0x5

mtime = Sun Jan 24 11:09:58 CST 2016

pZxid = 0x5

cversion = 0

dataVersion = 0

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 4

numChildren = 0

更新数据节点

set path data [version]

实例:

[zk: localhost:2181(CONNECTED) 6] set /test bar

cZxid = 0xe

ctime = Sun Jan 24 15:09:33 CST 2016

mZxid = 0xf

mtime = Sun Jan 24 15:10:04 CST 2016

pZxid = 0xe

cversion = 0

dataVersion = 1

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 3

numChildren = 0

删除

delete path [version]

实例:

[zk: localhost:2181(CONNECTED) 8] delete /test
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值