Hadoop-Zookeepr3.4.5集群搭建

1. 下载

http://archive.cloudera.com/cdh5/cdh/5/zookeeper-3.4.5-cdh5.7.0.tar.gz

2. 解压
# 解压到指定的文件夹
tar xzvf zookeeper-3.4.5-cdh5.7.0.tar.gz -C /usr/local/hadoop/app/
3. 配置文件修改

(1) 在解压目录下创建两个文件夹:/usr/local/hadoop/app/zookeeper-3.4.5-cdh5.7.0

mkdir data
mkdir logs

(2) 在data目录创建myid文件

touch myid
echo 1 > myid

在其他两个节点分别写入2和3

(3) 修改配置文件zoo.cfg
加入如下配置:

dataDir=/usr/local/hadoop/app/zookeeper-3.4.5-cdh5.7.0/data
dataLogDir=/usr/local/hadoop/app/zookeeper-3.4.5-cdh5.7.0/logs

server.1=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888
4. 配置系统环境变量
vi ~/.bashrc
export ZK_HOME=/usr/local/hadoop/app/zookeeper-3.4.5-cdh5.7.0
export PATH=$ZK_HOME/bin:$PATH

bash一下,让配置生效.

测试一下,环境变量是否生效:

echo $ZK_HOME
5. 将配置之后的解压文件,分发到其他节点上,

注意!!!: 修改myid文件

6. 执行以下命令依次启动zkServer
zkServer.sh start
7. 检查是否安装成功
#查看状态
zkServer.sh status 

在各个节点执行查看状态命令,若可以在zookeeper各节点可以看到一个leader和多个follower即表示搭建成功。

leader节点查看状态如下:

[root@slave2 bin]# ./zkServer.sh status
JMX enabled by default
Using config: /usr/local/hadoop/app/zookeeper-3.4.5-cdh5.7.0/bin/../conf/zoo.cfg
Mode: leader

follower节点查看状态如下:

[root@slave1 bin]# ./zkServer.sh status
JMX enabled by default
Using config: /usr/local/hadoop/app/zookeeper-3.4.5-cdh5.7.0/bin/../conf/zoo.cfg
Mode: follower
8. 启动zk客户端,进行基本操作测试

(1) 启动客户端:./zkCli.sh

[root@slave2 bin]# ./zkCli.sh 
Connecting to localhost:2181
Welcome to ZooKeeper!
JLine support is enabled
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTING) 0] 

执行登录命令,出现如上日志内容,即表示登录成功.

(2) zk基本操作命令

zookeeper的基本操作命令和linux命令类似.

ls 命令: 查看所有节点:ls /

[zk: localhost:2181(CONNECTING) 0] ls /
[zookeeper, otter]

示例,根节点有两个,分别为[zookeeper, otter].

get 命令: 查看节点数据内容和属性信息:get /otter

[zk: localhost:2181(CONNECTED) 1] get /otter
null
cZxid = 0x100000004
ctime = Fri Jun 07 11:54:06 CST 2019
mZxid = 0x100000004
mtime = Fri Jun 07 11:54:06 CST 2019
pZxid = 0x100000005
cversion = 1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 1 #有一个子节点

ls2 命令: 查看该节点的子节点信息和属性信息:ls2 /otter

[zk: localhost:2181(CONNECTED) 3] ls2 /otter
[canal]
cZxid = 0x100000004
ctime = Fri Jun 07 11:54:06 CST 2019
mZxid = 0x100000004
mtime = Fri Jun 07 11:54:06 CST 2019
pZxid = 0x100000005
cversion = 1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 1

create 命令: 创建节点,并指定节点内容

[zk: localhost:2181(CONNECTED) 4] create /tmp_test 123
Created /tmp_test

[zk: localhost:2181(CONNECTED) 5] ls /
[zookeeper, tmp_test, otter]

[zk: localhost:2181(CONNECTED) 6] get /tmp_test
123

create -s 命令: 创建顺序节点,并指定节点内容

[zk: localhost:2181(CONNECTED) 7] create -s /tmp_test/sub_node 111
Created /tmp_test/sub_node0000000000

[zk: localhost:2181(CONNECTED) 8] ls /tmp_test
[sub_node0000000000]

[zk: localhost:2181(CONNECTED) 9] create -s /tmp_test/sub_node 112
Created /tmp_test/sub_node0000000001

[zk: localhost:2181(CONNECTED) 10] ls2 /tmp_test
[sub_node0000000001, sub_node0000000000]

[zk: localhost:2181(CONNECTED) 12] get /tmp_test/sub_node0000000001
112

delete 命令: 删除指定节点

[zk: localhost:2181(CONNECTED) 13] ls /tmp_test
[sub_node0000000001, sub_node0000000000]

[zk: localhost:2181(CONNECTED) 14] delete /tmp_test/sub_node0000000000

[zk: localhost:2181(CONNECTED) 15] ls /tmp_test
[sub_node0000000001]

rmr 命令: 删除多个层级的节点

[zk: localhost:2181(CONNECTED) 16] ls /
[zookeeper, tmp_test, otter]

[zk: localhost:2181(CONNECTED) 18] ls /tmp_test
[sub_node0000000001]

[zk: localhost:2181(CONNECTED) 19] rmr /tmp_test

[zk: localhost:2181(CONNECTED) 20] ls /
[zookeeper, otter]

你可能感兴趣的:(Hadoop-Zookeepr3.4.5集群搭建)