手把手教你Zookeeper集群搭建

部署前准备

本次部署为3台主机集群

  1. zookeeper官网下载,本次部署版本为zookeeper-3.4.9
  2. 主机jdk安装,本次部署版本为jdk1.8

部署过程

  1. 压缩包解压tar -zxvf zookeeper-3.4.9.tar.gz
  2. 修改zookeeper配置文件,在zookeeper-3.4.9/conf/文件夹下,将zoo_sample.cfg复制重命名为zoo.cfg,对应修改配置,主要是dataDir路径、集群配置

# 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=/home/emall/soft/zookeeper/zookeeper-3.4.9/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=136.64.50.223:2888:3888

server.2=136.64.50.224:2888:3888

server.3=136.64.50.225:2888:3888

 

    3.修改zkServer.sh,新增jdk配置

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64/jre

export PATH=$JAVA_HOME/bin:$PATH

    4.zookeeper-3.4.9/路径下新增data文件夹,新建myid文件,内容和步骤2中集群配置server.x中的x相对于,比如:server.1=136.64.50.223:2888:3888,136.64.50.223主机的myid内容为1

部署验证

三台全部部署完成后,分别启动,执行 sh zookeeper-3.4.9/bin/zkServer.sh start,对应可以使用sh zookeeper-3.4.9/bin/zkServer.sh status来查看状态,三台全部启动完成后,分别查看每台status:

以上可看出有一台主节点,两台从节点

 

 

 

问题汇总

zookeeper启动现实成功,但是查看状态显示ZooKeeper JMX enabled by default,如下:

 

查看zookeeper日志(路径为../zookeeper-3.4.9/zookeeper.out),java.net.NoRouteToHostException: No route to host

解决:对应关闭防火墙即可

猜你喜欢

转载自blog.csdn.net/guozhangjie1992/article/details/105984220