目录

安装Zookeeper

1.安装

1.上传安装包

2.配置文件

1.修改zoo_sample.cfg名称

2.创建一个存放zk数据的目录:

3.配置zoo.cfg 

4.测试

3.把集群文件同步到其它机器

1.同步文件

2.写入

4.集群的启动与关闭

5.检查集群启动的状态


安装Zookeeper

1.安装

1.上传安装包

zookeeper-3.4.10.tar.gz

2.解压安装包

[root@hadoop01 software]# tar -zxvf zookeeper-3.4.10.tar.gz -C /opt/module/
[root@hadoop01 software]# cd /opt/module/
[root@hadoop01 module]# mv zookeeper-3.4.10/ zookeeper
[root@hadoop01 conf]# cd /opt/module/zookeeper/conf

2.配置文件

1.修改zoo_sample.cfg名称

[root@hadoop01 conf]# mv zoo_sample.cfg zoo.cfg

2.创建一个存放zk数据的目录:

[root@hadoop01 zookeeper]# mkdir /opt/module/zookeeper/data

3.配置zoo.cfg 

[root@hadoop01 zookeeper]# vim 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=/opt/module/zookeeper/data
# 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=hadoop01:2888:3888
server.2=hadoop02:2888:3888
server.3=hadoop03:2888:3888

4.测试

[root@hadoop01 data]# cd /opt/module/zookeeper/data/
[root@hadoop01 data]# touch myid
[root@hadoop01 data]# echo 1 > myid
[root@hadoop01 data]# cat myid
1

3.把集群文件同步到其它机器

1.同步文件

[root@hadoop01 zookeeper]# /root/bin/xsync /opt/module/zookeeper

2.写入

[root@hadoop01 zookeeper]# cd /opt/module/zookeeper/data/
[root@hadoop01 data]# cat myid
1
[root@hadoop02 data]# echo 2 > myid
[root@hadoop02 data]# cat myid
2
[root@hadoop03 module]# cd /opt/module/zookeeper/data/
[root@hadoop03 data]# echo 3 > myid
[root@hadoop03 data]# cat myid
3

4.集群的启动与关闭

[root@hadoop01 data]# cd /opt/module/zookeeper/
[root@hadoop02 data]# cd /opt/module/zookeeper/
[root@hadoop03 data]# cd /opt/module/zookeeper/
在三台机器中执行命令:
# bin/zkServer.sh start  ---启动命令
# bin/zkServer.sh stop  ---停止命令
# bin/zkServer.sh status  ---查看状态命令

5.检查集群启动的状态

[root@hadoop01 zookeeper]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper/bin/../conf/zoo.cfg
Mode: follower

[root@hadoop02 zookeeper]#  bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper/bin/../conf/zoo.cfg
Mode: leader

[root@hadoop03 zookeeper]#  bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper/bin/../conf/zoo.cfg
Mode: follower

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐