Hadoop 部署之 ZooKeeper

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Hadoop 部署之 ZooKeeper 相关的知识,希望对你有一定的参考价值。

一、Zookeeper功能简介

ZooKeeper 是一个开源的分布式协调服务,由雅虎创建,是 Google Chubby 的开源实现。
分布式应用程序可以基于 ZooKeeper 实现诸如数据发布/订阅、负载均衡、命名服务、分布式协
调/通知、集群管理、Master 选举、配置维护,名字服务、分布式同步、分布式锁和分布式队列
等功能。

二、ZooKeeper基本概念

1、集群角色

一个 ZooKeeper 集群同一时刻只会有一个 Leader,其他都是 Follower 或 Observer。

ZooKeeper 配置很简单,每个节点的配置文件(zoo.cfg)都是一样的,只有 myid 文件不一样。myid 的值必须是 zoo.cfg中server.{数值} 的{数值}部分。

ZooKeeper 默认只有 Leader 和 Follower 两种角色,没有 Observer 角色。为了使用 Observer 模式,在任何想变成Observer的节点的配置文件中加入:peerType=observer 并在所有 server 的配置文件中,配置成 observer 模式的 server 的那行配置追加 :observer

技术分享图片

三、ZooKeeper 的安装

1、下载安装(在datanode节点安装)

# 下载安装包
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz

# 解压安装包
tar xf zookeeper-3.4.10.tar.gz
mv zookeeper-3.4.10 /usr/local/zookeeper

# 创建目录
mkdir -p /home/zookeeper
# zk1节点(datanode1)
echo "1">/home/zookeeper/myid
# zk2节点(datanode2)
echo "2">/home/zookeeper/myid
# zk3节点(datanode3)
echo "3">/home/zookeeper/myid

2、配置ZooKeeper环境变量

编辑文件/etc/profile.d/zookeeper.sh

# ZOOKEEPER ENV
export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin

使ZK环境变量生效。

source /etc/profile.d/zookeeper.sh

3、配置 zoo.cfg

编辑文件/usr/local/zookeeper/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.
dataDir=/home/zookeeper
# 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=zk01:2888:3888
server.2=zk02:2888:3888
server.3=zk03:2888:3888

比较重要的配置如下:
dataDir=/home/zookeeper
server.1=zk01:2888:3888
server.2=zk02:2888:3888
server.3=zk03:2888:3888

4、启动各节点 ZK 服务

[[email protected] ~]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

[[email protected] ~]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

[[email protected] ~]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

5、查看各节点启动状态和角色

[[email protected] ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower

[[email protected] ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: leader

[[email protected] ~]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Mode: follower

官方文档:https://zookeeper.apache.org/doc/current/zookeeperStarted.html

以上是关于Hadoop 部署之 ZooKeeper 的主要内容,如果未能解决你的问题,请参考以下文章

HBase之集群搭建与快速入门

打怪升级之小白的大数据之旅(五十四)<Zookeeper概述与部署>

大数据系列之分布式数据库HBase-1.2.4+Zookeeper 安装及增删改查实践

HBase 快速入门

Hadoop 部署之环境准备

性能测试二十八:环境部署之Dubbo部署