[root@bigdatatest01 software]# tar -xzvf zookeeper-3.4.5-cdh5.16.2.tar.gz -C ~/app/[root@bigdatatest01 software]# cd ~/app/[root@bigdatatest01 app]# cd zookeeper-3.4.5-cdh5.16.2/
修改配置文件
[root@bigdatatest01 zookeeper-3.4.5-cdh5.16.2]# cd conf/[root@bigdatatest01 conf]# ll
total 12
-rw-rw-r-- 1 root root 535 Jun 3 2019 configuration.xsl
-rw-rw-r-- 1 root root 2693 Jun 3 2019 log4j.properties
-rw-rw-r-- 1 root root 922 Jun 3 2019 zoo_sample.cfg
[root@bigdatatest01 conf]# cp zoo_sample.cfg zoo.cfg[root@bigdatatest01 conf]# vim zoo.cfg
dataDir=/root/tmp/zookeeper
### 创建数据目录[root@bigdatatest01 ~]# cd tmp/[root@bigdatatest01 tmp]# mkdir zookeeper[root@bigdatatest01 tmp]# cd zookeeper/[root@bigdatatest01 zookeeper]# pwd
/root/tmp/zookeeper
启动Zookeeper服务
[root@bigdatatest01 conf]# cd ../[root@bigdatatest01 zookeeper-3.4.5-cdh5.16.2]# cd bin/[root@bigdatatest01 bin]# ll
total 44
-rwxr-xr-x 1 root root 238 Jun 3 2019 README.txt
-rwxr-xr-x 1 root root 1909 Jun 3 2019 zkCleanup.sh
-rwxr-xr-x 1 root root 1049 Jun 3 2019 zkCli.cmd
-rwxr-xr-x 1 root root 1512 Jun 3 2019 zkCli.sh
-rwxr-xr-x 1 root root 1333 Jun 3 2019 zkEnv.cmd
-rwxr-xr-x 1 root root 2599 Jun 3 2019 zkEnv.sh
-rwxr-xr-x 1 root root 1084 Jun 3 2019 zkServer.cmd
-rwxr-xr-x 1 root root 4559 Jun 3 2019 zkServer-initialize.sh
-rwxr-xr-x 1 root root 6246 Jun 3 2019 zkServer.sh
[root@bigdatatest01 bin]# ./zkServer.sh start
JMX enabled by default
Using config: /root/app/zookeeper-3.4.5-cdh5.16.2/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@bigdatatest01 bin]# ./zkServer.sh status
JMX enabled by default
Using config: /root/app/zookeeper-3.4.5-cdh5.16.2/bin/../conf/zoo.cfg
Mode: standalone
[root@bigdatatest01 app]# cd zk1/[root@bigdatatest01 zk1]# vim conf/zoo.cfg
dataDir=/root/tmp/zk1
clientPort=2181
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890
[root@bigdatatest01 zk1]# cd ../zk2/[root@bigdatatest01 zk2]# vim conf/zoo.cfg
dataDir=/root/tmp/zk2
clientPort=2182
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890
[root@bigdatatest01 zk2]# cd ../zk3[root@bigdatatest01 zk3]# vim conf/zoo.cfg
dataDir=/root/tmp/zk3
clientPort=2183
server.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890
修改数据文件
[root@bigdatatest01 tmp]# mkdir zk1[root@bigdatatest01 tmp]# mkdir zk2[root@bigdatatest01 tmp]# mkdir zk3[root@bigdatatest01 tmp]# pwd
/root/tmp
[root@bigdatatest01 tmp]# cd zk1/[root@bigdatatest01 zk1]# vim myid
1
[root@bigdatatest01 zk1]# cd ../zk2/[root@bigdatatest01 zk2]# vim myid
2
[root@bigdatatest01 zk2]# cd ../zk3/[root@bigdatatest01 zk3]# vim myid
3
启动ZK集群服务
[root@bigdatatest01 zk3]# cd ../zk1/[root@bigdatatest01 zk1]# pwd
/root/app/zk1
[root@bigdatatest01 zk1]# bin/zkServer.sh start
JMX enabled by default
Using config: /root/app/zk1/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@bigdatatest01 zk1]# bin/zkServer.sh status
JMX enabled by default
Using config: /root/app/zk1/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
[root@bigdatatest01 zk1]# cd ../zk2/[root@bigdatatest01 zk2]# bin/zkServer.sh start
JMX enabled by default
Using config: /root/app/zk2/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@bigdatatest01 zk2]# bin/zkServer.sh status
JMX enabled by default
Using config: /root/app/zk2/bin/../conf/zoo.cfg
Mode: leader
[root@bigdatatest01 zk1]# cd ../zk3[root@bigdatatest01 zk3]# bin/zkServer.sh start
JMX enabled by default
Using config: /root/app/zk3/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@bigdatatest01 zk3]# bin/zkServer.sh status
JMX enabled by default
Using config: /root/app/zk3/bin/../conf/zoo.cfg
Mode: follower
3. Zookeeper Shell常用命令
进入到客户端
[root@bigdatatest01 bin]# pwd
/root/app/zookeeper-3.4.5-cdh5.16.2/bin
[root@bigdatatest01 bin]# ./zkCli.sh [zk: localhost:2181(CONNECTED) 0]help
ZooKeeper -server host:port cmd args
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
3.1 创建节点
创建永久节点
[zk: localhost:2181(CONNECTED) 7] create /hadoop 11
Created /hadoop