手把手教你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

解決:對應關閉防火牆即可

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章