ZooKeeper使用

来源:互联网 发布:直播讲课哪个软件 编辑:程序博客网 时间:2024/04/27 14:32

配置

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

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

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

配置如下:

# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial # synchronization phase can takeinitLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgementsyncLimit=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 connectclientPort=2181# the maximum number of client connections.# increase this if you need to handle more clients#maxClientCnxns=60server.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 fooCreated /test0000000001

列出节点

ls path [watch]

实例:

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

查看数据节点

get path [watch]

实例:

[zk: localhost:2181(CONNECTED) 9] get /exampleinitcZxid = 0x5ctime = Sun Jan 24 11:09:58 CST 2016mZxid = 0x5mtime = Sun Jan 24 11:09:58 CST 2016pZxid = 0x5cversion = 0dataVersion = 0aclVersion = 0ephemeralOwner = 0x0dataLength = 4numChildren = 0

更新数据节点

set path data [version]

实例:

[zk: localhost:2181(CONNECTED) 6] set /test barcZxid = 0xectime = Sun Jan 24 15:09:33 CST 2016mZxid = 0xfmtime = Sun Jan 24 15:10:04 CST 2016pZxid = 0xecversion = 0dataVersion = 1aclVersion = 0ephemeralOwner = 0x0dataLength = 3numChildren = 0

删除

delete path [version]

实例:

[zk: localhost:2181(CONNECTED) 8] delete /test
1 0
原创粉丝点击