Zookeeper集群安装部署

 

准备

1.        下载zookeeper,下载地址http://www.apache.org/dyn/closer.cgi/zookeeper,此处为zookeeper-3.3.2

2.        分别解压至zookeepr集群机器(一般为基数台机器)相应目录(此处为$ZOOKEEPER_HOME),集群为mem1mem2mem3hosts对应)。

配置

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

注:dataDirzookeeper的数据目录,需要手动创建

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

id号即为zoo.cfg文件中server.后的数字,如server.1=mem1:2888:3888即表示mem1机器中的myid号为1server.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、启动集群的时候出现找不到JavaJAVA_HOME

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

    解决办法zkEnv.sh文件里写入JAVA_HOME变量

 

 

你可能感兴趣的:(zookeeper集群)