阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Zookeeper的安装与部署

143次阅读
没有评论

共计 2908 个字符,预计需要花费 8 分钟才能阅读完成。

这是一个分布式服务框架,阿帕奇的一个子项目。关于 ZooKeeper 我只简单的部署一下,以便后面的 HBase。

一  概述

ZooKeeper 分布式服务框架是 Apache Hadoop 的一个子项目,主要是用来解决分布式应用中经常遇到的一些数据管理问题,如:统一命名服务、状态同步服务、集群管理、分布式应用配置项的管理等。

ZooKeeper 是以 Fast Paxos 算法为基础的。

ZooKeeper 集群的初始化过程:集群中所有机器以投票的方式(少数服从多数)选取某一台机器作为 leader(领导者),其余机器作为 follower(追随者)。如果集群中只有一台机器,那么就这台机器就是 leader,没有 follower。

ZooKeeper 集群与客户端的交互:客户端可以在任意情况下 ZooKeeper 集群中任意一台机器上进行读操作;但是写操作必须得到 leader 的同意 后才能执行。

ZooKeeper 选取 leader 的核心算法思想:如果某服务器获得 N /2 + 1 票,则该服务器成为 leader。N 为集群中机器数量。为了避免出现两台服务器获得相同票数(N/2),应该确保 N 为奇数。因此构建 ZooKeeper 集群最少需要 3 台机器。

二  ZooKeeper 部署

1’安装 JDK(最先的博客早就说明配置了)

因为 ZooKeeper 服务器在 JVM 上运行。

2‘修改 ZooKeeper 配置文件

> 首先配置 slave1,slave2,slave3 之间的免密和各个机器的/etc/hosts 文件

 修改 ZooKeeper 的配置文件,步骤如下:

进入解压目录下,把conf 目录下的 zoo_sample.cfg 复制成 zoo.cfg 文件

Zookeeper 的安装与部署

3’打开 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 port at which the clients will connect
    clientPort=2181
    # the directory where the snapshot is stored.
    dataDir=/usr/cstor/zookeeper/data

dataLogDir=/usr/cstor/zookeeper/log

server.1=slave1:2888:3888

server.2=slave2:2888:3888

server.3=slave3:2888:3888

4‘新建两个目录。

mkdir /usr/cstor/zookeeper/data

mkdir /usr/cstor/zookeeper/log

Zookeeper 的安装与部署

将 /usr/cstor/zookeeper 目录传到另外两台机器上。

  scp -r /usr/cstor/zookeeper root@slave2:/usr/cstor

  scp -r /usr/cstor/zookeeper root@slave3:/usr/cstor

分别在三个节点上的 /usr/local/zookeeper/data 目录下创建一个文件:myid。

vi /usr/cstor/zookeeper/data/myid

分别在 myid 上按照配置文件的 server.<id> 中 id 的数值,在不同机器上的该文 件中填写相应过的值,如下:

slave1   的 myid 内容为 1

slave2   的 myid 内容为 2
      slave3   的 myid 内容为 3

5’启动 ZooKeeper 集群

然后,启动 ZooKeeper 集群,进入客户端验证部署完成。

分别在三个节点进入 bin 目录,启动 ZooKeeper 服务进程

cd /usr/cstor/zookeeper/bin

./zkServer.sh start

Zookeeper 的安装与部署

在各机器上依次执行脚本,查看 ZooKeeper 状态信息,两个节点是 follower 状态,一个节点是 leader 状态:

./zkServer.sh status

在其中一台机器上执行客户端脚本:

./zkCli.sh -server slave1:2181,slave2:2181,slave3:2181

Zookeeper 的安装与部署

在客户端 shell 下执行创建目录命令:

create /testZk “”

向 /testZk 目录写数据:

set /testZk ‘aaa’

Zookeeper 的安装与部署

读取 /testZk 目录数据:

get /testZk

删除 /testZk 目录:

rmr /testZk

在客户端 shell 下用 quit 命令退出客户端:

quit

Zookeeper 的安装与部署

在 CentOS7 上安装 Zookeeper-3.4.9 服务 http://www.linuxidc.com/Linux/2016-09/135052.htm 

ZooKeeper 官方文档翻译——ZooKeeper Overview 3.4.6  http://www.linuxidc.com/Linux/2016-12/138025.htm 

CentOS 下 ZooKeeper 3.4.8 集群环境搭建 http://www.linuxidc.com/Linux/2016-12/137958.htm 

CentOS 7 下 Zookeeper 集群安装 http://www.linuxidc.com/Linux/2017-01/139733.htm 

ZooKeeper 学习总结  http://www.linuxidc.com/Linux/2016-07/133179.htm 

Linux 下安装 Zookeeper 集群 http://www.linuxidc.com/Linux/2017-01/139545.htm 

Zookeeper3.4.6 的安装 http://www.linuxidc.com/Linux/2015-05/117697.htm 

Linux 下 Zookeeper 集群的安装  http://www.linuxidc.com/Linux/2017-03/141400.htm 

CentOS 7 下安装 Zookeeper 单机版  http://www.linuxidc.com/Linux/2015-05/117697.htm

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-08/146091.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计2908字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中