Zookeeper 集群搭建

集群规划

在 192.168.98.137、192.168.98.138、192.168.98.139三个节点上部署Zookeeper。

解压安装

  • 解压Zookeeper安装包到/home/zookeeper目录下
tar -zxvf zookeeper-3.4.10.tar.gz
  • 其他两个节点执行一样操作

配置服务器编号

  • 在 /home/zookeeper/zookeeper-3.4.6 目录下创建 zkData
mkdir -p zkData
  • 在 /home/zookeeper/zookeeper-3.4.6/zkData 目录下创建一个 myid 的文件
touch myid

添加myid文件,注意一定要在linux里面创建,在notepad++里面很可能乱码

  • 编辑myid文件
vim myid
  • 在文件中添加与 server 对应的编号:
1
  • 其他两个节点同以上配置,但是要修改 myid 中的值,不能与其他节点重复

配置 zoo.cfg 文件

  • 重命名 /home/zookeeper/zookeeper-3.4.6/conf 这个目录下的 zoo_sample.cfg为 zoo.cfg
mv zoo_sample.cfg zoo.cfg
  • 打开 zoo.cfg 文件
vim zoo.cfg
  • 修改数据存储的路径配置
dataDir=/home/zookeeper/zookeeper-3.4.6/zkData
  • 增加如下配置

server.1=192.168.98.137:2888:3888
server.2=192.168.98.138:2888:3888
server.3=192.168.98.139:2888:3888

  • 其他两个节点配置文件与以上相同
  • 配置参数解读
server.A=B:C:D。

A 是一个数字,表示这个是第几号服务器;
集群模式下配置一个文件myid,这个文件在dataDir目录下,这个文件里面有一个数据就是A的值,Zookeeper启动时读取此文件,拿到里面的数据与zoo.cfg里面的配置信息比较从而判断到底是哪个server。
B 是这个服务器的ip地址;
C 是这个服务器与集群中的Leader服务器交换信息的端口;
D 是万一集群中的Leader服务器挂了,需要一个端口来重新进行选举,选出一个新的Leader,而这个端口就是用来执行选举时服务器相互通信的端口。

启动集群

  • 分别启动 Zookeeper
./zkServer.sh start
  • 查看状态
./zkServer.sh status

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

附三个节点配置文件

192.168.98.137

# 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/zookeeper-3.4.6/zkData
# 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=192.168.98.137:2888:3888
server.2=192.168.98.138:2888:3888
server.3=192.168.98.139:2888:3888




192.168.98.138

# 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/zookeeper-3.4.6/zkData
# 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=192.168.98.137:2888:3888
server.2=192.168.98.138:2888:3888
server.3=192.168.98.139:2888:3888




192.168.98.139

# 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/zookeeper-3.4.6/zkData
# 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=192.168.98.137:2888:3888
server.2=192.168.98.138:2888:3888
server.3=192.168.98.139:2888:3888




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_子栖_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值