---
title: "Zookeeper集群安装部署"
author: "zenoh"
date: "2012-10-09T11:57:28Z"
tags: []
categories: ["开源软件"]
slug: "zookeeper"
draft: false
lastmod: "2012-10-09T11:57:28Z"
id: 1694208
url: "https://zenoh.iteye.com/blog/1694208"
---

**准备**

1.        下载zookeeper，下载地址[http://www.apache.org/dyn/closer.cgi/zookeeper](http://www.apache.org/dyn/closer.cgi/zookeeper)，此处为zookeeper-3.3.2

2.        分别解压至zookeepr集群机器（一般为基数台机器）相应目录（此处为$ZOOKEEPER\_HOME），集群为mem1，mem2，mem3（hosts对应）。

[]()**配置**

1.        分别在zookeepr集群机器上配置$ZOOKEEPER\_HOME/conf/zoo.cfg(默认是没有此文件的，可以由zoo\_sample.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=/data/zkdata

\# the port at which the clients will connect

clientPort=2181

\#

\# 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=master:2888:3888

server.2=slave01:2888:3888

server.3=slave02:2888:3888

注：dataDir是zookeeper的数据目录，需要手动创建

2.        配置myid文件，在dataDir目录下新建myid文件并设置id号

id号即为zoo.cfg文件中server.后的数字，如server.1=mem1:2888:3888即表示mem1机器中的myid号为1，server.2=mem2:2888:3888即表示mem2器中的myid号为2。

## []()测试

1.        启动

分别在zookeepr集群机器

ZOOKEEPER\_HOME/bin/zkServer.sh start

 注：一开始启动的时候会报错，提示连不上集群其他成员。此时是正常信息，等所有集群成员都启动后，该错误信息便会消失。

 

2.        查看集群状态

ZOOKEEPER\_HOME/bin/zkServer.sh status

如果正常启动会提示如下信息

\[hadoop@mem2 zookeeper]$ bin/zkServer.sh  status

JMX enabled by default

Using config:  /usr/local/zookeeper/bin/../conf/zoo.cfg

Mode: follower

或者jps查看是否有QuorumPeerMain服务，如存在则已经启动。

 

遇到的错误：

1、启动集群的时候出现找不到Java（JAVA\_HOME）

   这个问题很莫名其妙，明明是配置了JAVA\_HOME，才bin目录下的zkEnv.sh中不能看到JAVA\_HOME。

    解决办法:  在zkEnv.sh文件里写入JAVA\_HOME变量