ZooKeeper 명령: 시작, 상태 보기, help, ls,create,get,set,stat,delete, 네 가지 노드, 감시watch

상태 보기 및 클라이언트 시작
상태 보기
[worker@103-17-143-sh-K05 bin]$ /ssd1/workspace/zookeeper/zookeeper2-3.4.12/bin/./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /ssd1/workspace/zookeeper/zookeeper2-3.4.12/bin/../conf/zoo.cfg
Mode: leader

클라이언트 시작
[worker@103-17-143-sh-K05 bin]$ /ssd1/workspace/zookeeper/zookeeper2-3.4.12/bin/zkCli.sh -server localhost:2181
Connecting to localhost:2181
...(      )
[zk: localhost:2181(CONNECTED) 0]


기본 명령
도움말
[zk: localhost:2181(CONNECTED) 0] help
ZooKeeper -server host:port cmd args
	connect host:port
	get path [watch]
	ls path [watch]
	set path data [version]
	rmr path
	delquota [-n|-b] path
	quit
	printwatches on|off
	create [-s] [-e] path data acl
	stat path [watch]
	close
	ls2 path [watch]
	history
	listquota path
	setAcl path acl
	getAcl path
	sync path
	redo cmdno
	addauth scheme auth
	delete path [version]
	setquota -n|-b val path

디렉토리 ls 보기
[zk: localhost:2181(CONNECTED) 3] ls /
[jodis, zk, zookeeper, codis, codis3, worker_id_forever]

디렉토리create 만들기
[zk: localhost:2181(CONNECTED) 4] create /zk_test hanchao_test
Created /zk_test

데이터 가져오기get
[zk: localhost:2181(CONNECTED) 5] get /zk_test
hanchao_test
cZxid = 0x4000092ec
ctime = Thu Mar 07 10:34:59 CST 2019
mZxid = 0x4000092ec
mtime = Thu Mar 07 10:34:59 CST 2019
pZxid = 0x4000092ec
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 12
numChildren = 0
  • cZxid Zookeeper가 노드에 할당한 Id
  • cTime 노드 생성 시간
  • mZxid 수정된 id
  • mtime 수정 시간
  • pZxid 서브노드 id
  • cversion 서브노드의version
  • 데이터 Version 현재 노드 데이터의 버전 번호
  • aclVersion 권한 Version
  • 데이터 Length 데이터 길이
  • numChildren 서브노드 개수
  • 데이터 set 설정
    [zk: localhost:2181(CONNECTED) 6] set /zk_test hanchaohanchao
    cZxid = 0x4000092ec
    ctime = Thu Mar 07 10:34:59 CST 2019
    mZxid = 0x4000092ed
    mtime = Thu Mar 07 10:35:55 CST 2019
    pZxid = 0x4000092ec
    cversion = 0
    dataVersion = 1
    aclVersion = 0
    ephemeralOwner = 0x0
    dataLength = 14
    numChildren = 0
    

    상태 점검stat
    [zk: localhost:2181(CONNECTED) 12] stat /hanchao_test/defatul_node
    cZxid = 0x4000092f3
    ctime = Thu Mar 07 10:50:52 CST 2019
    mZxid = 0x4000092f6
    mtime = Thu Mar 07 10:54:22 CST 2019
    pZxid = 0x4000092f3
    cversion = 0
    dataVersion = 1
    aclVersion = 0
    ephemeralOwner = 0x0
    dataLength = 22
    numChildren = 0
    

    경로 삭제
    [zk: localhost:2181(CONNECTED) 8] delete /zk_test
    [zk: localhost:2181(CONNECTED) 9] ls /
    [jodis, zk, zookeeper, codis, codis3, worker_id_forever]
    

    네 가지 노드
    create /path data
    

    무질서 영구 노드 (기본값)
    [zk: localhost:2181(CONNECTED) 20] create /hanchao_test/defatul_node "persistent,no-sequence"
    Created /hanchao_test/defatul_node
    [zk: localhost:2181(CONNECTED) 21] ls /hanchao_test
    [defatul_node]
    

    질서정연한 지속 노드
  • 질서 노드 명칭 = 질서 노드 루트 +10자리 순서 번호
  • -s :sequence
  • [zk: localhost:2181(CONNECTED) 3] create -s /hanchao_test/sequence_node "persistent,sequence"
    Created /hanchao_test/sequence_node0000000001
    [zk: localhost:2181(CONNECTED) 4] ls /hanchao_test
    [defatul_node, sequence_node0000000001]
    [zk: localhost:2181(CONNECTED) 5] create -s /hanchao_test/sequence_node "persistent,sequence"
    Created /hanchao_test/sequence_node0000000002
    [zk: localhost:2181(CONNECTED) 6] ls /hanchao_test
    [defatul_node, sequence_node0000000001, sequence_node0000000002]
    

    무질서 임시 노드
  • 임시 노드가client 포트 연결 후 종료
  • -e : temp
  • # client1         
    [zk: localhost:2181(CONNECTED) 3] create -e /hanchao_test/temp_node "no-persistent,no-sequence"
    Created /hanchao_test/temp_node
    [zk: localhost:2181(CONNECTED) 4] ls /hanchao_test
    [temp_node, defatul_node, sequence_node0000000001, sequence_node0000000002]
    
    # client2
    # client1       
    [zk: localhost:2181(CONNECTED) 7] ls /hanchao_test
    [temp_node, defatul_node, sequence_node0000000001, sequence_node0000000002]
    # client1       
    [zk: localhost:2181(CONNECTED) 8] ls /hanchao_test
    [defatul_node, sequence_node0000000001, sequence_node0000000002]
    
    

    순서 임시 노드
    [zk: localhost:2181(CONNECTED) 1] create -s -e /hanchao_test/temp_node_p "no-persistent,order"
    Created /hanchao_test/temp_node_p0000000004
    [zk: localhost:2181(CONNECTED) 2] ls /hanchao_test
    [defatul_node, temp_node_p0000000004, sequence_node0000000001, sequence_node0000000002]
    [zk: localhost:2181(CONNECTED) 3] create -s -e /hanchao_test/temp_node_p "no-persistent,order"
    Created /hanchao_test/temp_node_p0000000005
    [zk: localhost:2181(CONNECTED) 4] ls /hanchao_test
    [defatul_node, temp_node_p0000000005, temp_node_p0000000004, sequence_node0000000001, sequence_node0000000002]
    
  • 같은 디렉터리에서 순서 노드의 순서 번호는 공용
  • 감시watch
  • 지정한 znode나 znode의 하위 데이터가 변경되면 모니터에 알림이 표시됩니다.
  • get 명령에watch만 설정할 수 있습니다.
  • #  client1   
    [zk: localhost:2181(CONNECTED) 14] get /hanchao_test/defatul_node 1
    persistent,no-sequence
    cZxid = 0x4000092f3
    ctime = Thu Mar 07 10:50:52 CST 2019
    mZxid = 0x4000092f6
    mtime = Thu Mar 07 10:54:22 CST 2019
    pZxid = 0x4000092f3
    cversion = 0
    dataVersion = 1
    aclVersion = 0
    ephemeralOwner = 0x0
    dataLength = 22
    numChildren = 0
    
    #  client2 set
    [zk: localhost:2181(CONNECTED) 0] set /hanchao_test/defatul_node "hhhhh"
    cZxid = 0x4000092f3
    ctime = Thu Mar 07 10:50:52 CST 2019
    mZxid = 0x400009301
    mtime = Thu Mar 07 11:10:26 CST 2019
    pZxid = 0x4000092f3
    cversion = 0
    dataVersion = 2
    aclVersion = 0
    ephemeralOwner = 0x0
    dataLength = 5
    numChildren = 0
    
    # client1       
    [zk: localhost:2181(CONNECTED) 15]
    WATCHER::
    
    WatchedEvent state:SyncConnected type:NodeDataChanged path:/hanchao_test/defatul_node
    

    좋은 웹페이지 즐겨찾기