ZooKeeper(2)配置伪分布模式

很简单,在任意目录下如下创建

|--z1/
|   |--data/
|   |--zoo.cfg
|
|--z2/
|   |--data/
|   |--zoo.cfg
|
|--z3/
|   |--data/
|   |--zoo.cfg
|

zoo.cfg如下

三个zoo.cfg只有clientPort不同,分别为2181,2182,2183

tickTime=2000
initLimit=5
syncLimit=2
dataDir=./data
clientPort=2181

server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890

然后在z1/data,z2/data,z3/data下分别创建文件myid,内容分别为1,2,3

验证服务器

输入stat,看Mode看出哪个是Leader

atalisas@atalisas-MR-X5:~$ telnet localhost 2181
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

stat

Zookeeper version: 3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT
Clients:
 /127.0.0.1:47358[0](queued=0,recved=1,sent=0)

Latency min/avg/max: 0/4/64
Received: 21
Sent: 20
Connections: 1
Outstanding: 0
Zxid: 0x10000000a
Mode: follower
Node count: 4
Connection closed by foreign host.

打开客户端

自动负载均衡,选择一个服务器连接

zkCli.sh -server localhost:2181,localhost:2182,localhost:2183

客户端脚本

创建

-s:顺序节点,创建一样的节点,会分配一个序号
-e:临时节点,客户端崩溃或断开则马上删除
acl:进行权限控制

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

读取

ls path [watch]
get path [watch]

更新:如果指定了version,必须和当前data version一致才能成功

set path data [version]

删除:没有子节点才能删除

delete path [version]

实例

create /temp 123
>Created /temp

ls /
>[temp, zookeeper]

get /temp
>123
>cZxid = 0x10000000c                    //创建时的事务ID
>ctime = Sat Sep 30 20:29:27 CST 2017
>mZxid = 0x10000000c                    //更新时的事务ID
>mtime = Sat Sep 30 20:29:27 CST 2017
>pZxid = 0x10000000c
>cversion = 0
>dataVersion = 0
>aclVersion = 0
>ephemeralOwner = 0x0
>dataLength = 3
>numChildren = 0

set /temp 4456
>cZxid = 0x10000000c
>ctime = Sat Sep 30 20:29:27 CST 2017   //创建时间
>mZxid = 0x10000000d                    
>mtime = Sat Sep 30 20:34:23 CST 2017   //修改时间
>pZxid = 0x10000000c
>cversion = 0
>dataVersion = 1             //data version变化了
>aclVersion = 0
>ephemeralOwner = 0x0
>dataLength = 4              //数据长度
>numChildren = 0

delete /temp

全部命令


    stat path [watch]
    set path data [version]
    ls path [watch]
    delquota [-n|-b] path
    ls2 path [watch]
    setAcl path acl
    setquota -n|-b val path
    history 
    redo cmdno
    printwatches on|off
    delete path [version]
    sync path
    listquota path
    rmr path
    get path [watch]
    create [-s] [-e] path data acl
    addauth scheme auth
    quit 
    getAcl path
    close 
    connect host:port

你可能感兴趣的:(hadoop)