文章做者:foochane html
原文連接:https://foochane.cn/article/2019062601.htmlnode
zookeeper數據存儲形式 zookeeper安裝 zookeeper命令行客戶端的使用
zookeeper
中對用戶的數據採用kv
形式存儲shell
key
:是以路徑的形式表示的,各key之間有父子關係,好比 /
是頂層key
apache
用戶建的key
只能在/ 下做爲子節點,好比建一個key: /aa
這個key
能夠帶value
數據bash
也能夠建一個key
: /bb
ssh
也能夠建多個key
: /aa/xx
ide
zookeeper
中,對每個數據key
,稱做一個znode
oop
zookeeper
中的znode
有多種類型:ui
PERSISTENT
持久的:建立者就算跟集羣斷開聯繫,該類節點也會持久存在與zk
集羣中EPHEMERAL
短暫的:建立者一旦跟集羣斷開聯繫,zk
就會將這個節點刪除SEQUENTIAL
帶序號的:這類節點,zk
會自動拼接上一個序號,並且序號是遞增的組合類型:this
PERSISTENT
:持久不帶序號EPHEMERAL
:短暫不帶序號PERSISTENT
且 SEQUENTIAL
:持久且帶序號EPHEMERAL
且 SEQUENTIAL
:短暫且帶序號解壓安裝包 zookeeper-3.4.6.tar.gz
修改conf/zoo.cfg
# 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=/usr/local/bigdata/data/zkdata # 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 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1 server.1=Master:2888:3888 server.2=Slave01:2888:3888 server.3=Slave02:2888:3888
對3臺節點,都建立目錄 /usr/local/bigdata/data/zkdata
對3臺節點,在工做目錄中生成myid
文件,但內容要分別爲各自的id
: 1
,2
,3
Master上: echo 1 > /usr/local/bigdata/data/zkdata/myid Slave01上: echo 2 > /usr/local/bigdata/data/zkdata/myid Slave02上: echo 3 > /usr/local/bigdata/data/zkdata/myid
zookeeper
沒有提供自動批量啓動腳本,須要手動一臺一臺地起zookeeper
進程
在每一臺節點上,運行命令:
$ bin/zkServer.sh start
啓動後,用jps
應該能看到一個進程:QuorumPeerMain
查看狀態
$ bin/zkServer.sh status
zookeeper
沒有提供批量腳本,不能像hadoop
同樣在一臺機器上同時啓動全部節點,能夠本身編寫腳本批量啓動。
#!/bin/bash for host in Master Slave01 Slave02 do echo "${host}:${1}ing....." ssh $host "source ~/.bashrc;/usr/local/bigdata/zookeeper-3.4.6/bin/zkServer.sh $1" done sleep 2 for host in Master Slave01 Slave02 do ssh $host "source ~/.bashrc;/usr/local/bigdata/zookeeper-3.4.6/bin/zkServer.sh status" done
運行命令:
sh zkmanage.sh start #啓動 sh zkmanage.sh stop #中止
啓動本地客戶端:
$ bin/zkCli.sh
啓動其餘機器的客戶端:
$ bin/zkCli.sh -server Master:2181
基本命令:
help
ls /
get /zookeeper
create /節點 數據
, 如:create /aa hello
set /aa helloworld
rmr /aa/bb
get /aa watch
-->數據發生改變會通知 ; ls /aa watch
-->目錄發現改變也會通知