zookeeper集群配置

时间:2022-01-20 16:10:55

  zookeeper集群网上demo一大堆,补充一下一些不明白的地方

  1 复制2份zookeeper,savle作为备份节点

zookeeper集群配置

2.配置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.
dataDir=/usr/data/zookeeper1_master/data
dataLogDir=/usr/data/zookeeper1_master/log
# the port at which the clients will connect
clientPort=2181
#Clusters
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890  

其中要注意的是新增的dataDir=/usr/data/zookeeper1_master/data  这个data文件夹本身在zookeeper是没有的,所以需要新建一个,然后执行 echo "1" > /home/hadoop/storage/zookeeper/myid  创建一个myid文件
  补充一下:之前看到网上有人对myid不知道是什么格式,下图执行file命令:

zookeeper集群配置

3.然后把上面的配置zoo.cfg复制2份,改一下clientPort端口不要和2181重复,默认zookeeper是2181;同时也要记得修改不同zookeeper myid文件,

4.分别启动3台zookeeper服务

  • adoop@slave-01:~/installation/zookeeper-3.3.4$ bin/zkServer.sh start
  • hadoop@slave-02:~/installation/zookeeper-3.3.4$ bin/zkServer.sh start
  • hadoop@slave-03:~/installation/zookeeper-3.3.4$ bin/zkServer.sh start

5.随机进入一个zookeeper服务,执行 bin/zkServer.sh status ,可以发现这台是领导者,其他2台是跟随者。

zookeeper集群配置