文章做者: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
-->目录发现改变也会通知