大数据实践(五)--Zookeeper集群搭建(Ubuntu)

大数据实践(五)--Zookeeper集群搭建(Ubuntu)

一、简介

Zookeeper 是一个开源的分布式协调服务,目前由 Apache 进行维护。Zookeeper 可以用于实现分布式系统中常见的发布/订阅、负载均衡、命令服务、分布式协调/通知、集群管理、Master 选举、分布式锁和分布式队列等功能。它具有以下特性:

  • 顺序一致性:从一个客户端发起的事务请求,最终都会严格按照其发起顺序被应用到 Zookeeper 中;
  • 原子性:所有事务请求的处理结果在整个集群中所有机器上都是一致的;不存在部分机器应用了该事务,而另一部分没有应用的情况;
  • 单一视图:所有客户端看到的服务端数据模型都是一致的;
  • 可靠性:一旦服务端成功应用了一个事务,则其引起的改变会一直保留,直到被另外一个事务所更改;
  • 实时性:一旦一个事务被成功应用后,Zookeeper 可以保证客户端立即可以读取到这个事务变更后的最新状态的数据。

在这里插入图片描述

使用zookeeeper单独管理集群更加高效。

二、集群安装

基本命令在所有机器上执行:

1、将zookeeper解压

解压到/usr/local/zookeeper

2、配置环境变量
#zoopkeeper home
export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=$ZOOKEEPER_HOME/bin:$PATH

记得让环境生效。

3、修改配置文件

进入安装目录的conf下:

 cp zoo_sample.cfg  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=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/log
# 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=master:2287:3387
server.2=node2:2287:3387
server.3=node3:2287:3387

4、节点配置

建立目录

mkdir -vp  /usr/local/zookeeper/data/

在各主机分别使用一个命令表示id

echo "1" > /usr/local/zookeeper/data/myid #在mster
echo "2" > /usr/local/zookeeper/data/myid #在node2
echo "3" > /usr/local/zookeeper/data/myid
5、测试

各个机器使用:启动zookeeper

zkServer.sh start

使用 zkServer.sh status 查看集群各个节点状态。leader 节点和follower 节点。

zkServer.sh status
posted @ 2020-06-06 03:40  cgl_dong  阅读(109)  评论(0编辑  收藏  举报