Zookeeper分布式安装

软件下载

Zookeeper版本一般是越新越好。注意是带bin的文件
传送门
在这里插入图片描述

上传

本人使用的filezilla.exe将文件上传到虚拟机。我上传的地方是/soft文件下
在这里插入图片描述

解压缩

tar -zxvf apache-zookeeper-3.5.8.tar.gz 

创建文件夹

我是在apache.zookeeper-3.5.8的文件下创建一个文件夹Data。命令可以随意取,这个文件夹是Zookeeper存储数据的目录

mkdir Data

配置

进入到apache.zookeeper-3.5.8/conf下,将其中的zoo_sample.cfg修改成zoo.cfg

# 进入到conf的文件夹
cd conf   
# 修改文件名
mv zoo_sample.cfg zoo.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=/soft/zookeeper3.5.8/Data
# 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:2888:3888
server.2=dataone:2888:3888
server.3=datatwo:2888:3888

修改文件名之后,其他的内容基本上都有,一般没有的是:

server.1=master:2888:3888
server.2=dataone:2888:3888
server.3=datatwo:2888:3888

这部分是根据自己实际情况进行配置,格式如下:

server.Id=host:port1:port2

其中

  1. id:可以自己取,之后在修改myid文件时会使用到这个id,大小在[1,244]
  2. host:可以填自己的主机名,要有主机与ip地址的映射
  3. port1:Leader端口,即该服务器作为Leader时供Follower连接的端口
  4. port2:选举端口,即选取Leader服务器时提供其他Follower连接的端口

还需要修改的一处是:

dataDir=/tmp/zookeeper/Data

因为我上面创建的是Data文件,所以这个使用的目录就是Data,根据自己创建的实际情况处理

相关配置属性介绍(可以先安装完,再回来看):

  1. tickTime:基本事件单元,用来指示一个心跳的时长。以毫秒为单位。
  2. initLimit:集群中的Follower服务器初始化连接leader服务器时能等待的最大心跳树(连接超时时长)。默认为10,即如果经过10个心跳之后,Follower服务器仍没有接收到Leader服务器的返回信息,则连接失败。在我的修改文件中,该参数值是默认值,参数tickTime为2000毫秒,则连接超时时长为5*2000=10秒
  3. syncLimit:集群中Follower服务器和Leader服务器之间发送消息以及请求/应答时所能等待的最多心跳数。
  4. server.id=host:port1:port2:标识不同的Zookeeper服务器
  5. dataDir:Zookeeper存储数据的目录
  6. clientPort:客户端连接Zookeeper服务器的端口。Zookeeper会监听这个端口,接收客户端的请求。

创建文件myid

在前面创建的文件夹下创建一个myid的文件。此处,我就是在Data文件夹下创建一个myid的文件。注意文件名必须一致,在这个文件中填入配置文件中的ID。比如:在我的master服务上,此处填入1.
在这里插入图片描述

分发文件

scp -r zookeeper3.5.8/ datatwo:/soft/

修改myid

登录到每个服务器,修改Zookeeper中myid文件。与zoo.cfg文件中配置一致

启动检验

进入到Zookeeper文件夹中,运行以下命令:

bin/zkServer.sh start

出现下图中提示说明成功了
在这里插入图片描述

查看状态

bin/zkServer.sh status

关闭集群

bin/zkServer.sh stop

注意

Zookeeper的集群启动需要每台装有Zookeeper的服务器上都执行一次启动的命令,才能够将整个集群启动起来

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值