由于项目需要,需要在集群中安装好Zookeeper,这里我选择最新版本的Zookeeper3.4.5。 ZooKeeper是Hadoop的正式子项目,它是一个针对大型分布式系统的可靠协调系统,提供的功能包括:配置维护、名字服务、分布式同步、组服务等。ZooKeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。它也是Google的Chubby一个开源的实现,是高有效和可靠的协同工作系统,Zookeeper能够用来leader选举,配置信息维护等,在一个分布式的环境中,需要一个Master实例或存储一些配置信息,确保文件写入的一致性等。 当然你运行一个zookeeper也是可以的,但是在生产环境中,你最好部署3,5,7个节点。部署的越多,可靠性就越高,zookeeper集群是以宕机个数过半才会让整个集群宕机的,所以奇数个集群更佳。这里我选择5台机器,hostname分别为new-cdh12、new-cdh13、new-cdh15、new-cdh16、new-cdh17。

安装步骤

1、解压

tar -zxvf zookeeper-3.4.5-cdh5.7.0.tar.gz

2、Zookeeper环境变量的配置

[hadoop@new-cdh12 ~]$ vi .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

#set zookeeper environment
export ZOOKEEPER_HOME=/hadoop/soft/zookeeper-3.4.5-cdh5.7.0

PATH=PATH:PATH:HOME/bin:ZOOKEEPER_HOME/bin:ZOOKEEPER\_HOME/bin:ZOOKEEPER_HOME/conf

export PATH

3、修改配置文件

[hadoop@new-cdh12 zookeeper-3.4.5-cdh5.7.0]$ cp conf/zoo_sample.cfg conf/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.
# do not use /tmp for storage, /tmp here is just
# example sakes.
#update by jingshuai start
dataDir=/hadoop/zookeeper/data
dataLogDir=/hadoop/zookeeper/log
#update by jingshuai end

# 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

#update by jingshuai start
server.12=new-cdh12:2888:3888
server.13=new-cdh13:2888:3888
server.15=new-cdh15:2888:3888
server.16=new-cdh16:2888:3888
server.17=new-cdh17:2888:3888
#update by jingshuai end

5、创建文件夹和文件

[hadoop@new-cdh12 zookeeper-3.4.5-cdh5.7.0]$ mkdir -p /hadoop/zookeeper/data/
[hadoop@new-cdh12 zookeeper-3.4.5-cdh5.7.0]$ mkdir -p /hadoop/zookeeper/data/log
[hadoop@new-cdh12 zookeeper-3.4.5-cdh5.7.0]$ echo “12” > /hadoop/zookeeper/data/myid

myid 和zoo.cfg配置必须一样,建议使用ip 最后一个字段。

5、同步到其他机器

把1-5 步骤在其他机器上做一遍 ,myid 不能一样

6、启动

[hadoop@new-cdh12 zookeeper-3.4.5-cdh5.7.0]$ ssh new-cdh12 “/hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/zkServer.sh start”
JMX enabled by default
Using config: /hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/…/conf/zoo.cfg
Starting zookeeper … STARTED
[hadoop@new-cdh12 zookeeper-3.4.5-cdh5.7.0]$ ssh new-cdh13 “/hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/zkServer.sh start”
JMX enabled by default
Using config: /hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/…/conf/zoo.cfg
Starting zookeeper … STARTED
[hadoop@new-cdh12 zookeeper-3.4.5-cdh5.7.0]$ ssh new-cdh15 “/hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/zkServer.sh start”
JMX enabled by default
Using config: /hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/…/conf/zoo.cfg
Starting zookeeper … STARTED
[hadoop@new-cdh12 zookeeper-3.4.5-cdh5.7.0]$ ssh new-cdh16 “/hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/zkServer.sh start”
JMX enabled by default
Using config: /hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/…/conf/zoo.cfg
Starting zookeeper … STARTED
[hadoop@new-cdh12 zookeeper-3.4.5-cdh5.7.0]$ ssh new-cdh17 “/hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/zkServer.sh start”
JMX enabled by default
Using config: /hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/…/conf/zoo.cfg
Starting zookeeper … STARTED

7、查看状态

[hadoop@new-cdh12 ~]$ ssh new-cdh12 “/hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/zkServer.sh status”
JMX enabled by default
Using config: /hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/…/conf/zoo.cfg
Mode: follower
[hadoop@new-cdh12 ~]$ ssh new-cdh13 “/hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/zkServer.sh status”
JMX enabled by default
Using config: /hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/…/conf/zoo.cfg
Mode: follower
[hadoop@new-cdh12 ~]$ ssh new-cdh15 “/hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/zkServer.sh status”
JMX enabled by default
Using config: /hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/…/conf/zoo.cfg
Mode: follower
[hadoop@new-cdh12 ~]$ ssh new-cdh16 “/hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/zkServer.sh status”
JMX enabled by default
Using config: /hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/…/conf/zoo.cfg
Mode: follower
[hadoop@new-cdh12 ~]$ ssh new-cdh17 “/hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/zkServer.sh status”
JMX enabled by default
Using config: /hadoop/soft/zookeeper-3.4.5-cdh5.7.0/bin/…/conf/zoo.cfg
Mode: leader

相关:集群安装