当前位置: 首页 > article >正文

Zookeeper3.5.8集群部署

环境说明

准备三台服务器,我这边是虚拟机,分别为:bigdata141、bigdata142、bigdata143

下载安装包

下载链接:Index of /dist/zookeeper/zookeeper-3.5.8

下载完后,上传到其中一台服务器,我这边上传到 bigdata141 的 /data/soft/ 目录下

解压并配置

解压

[root@bigdata141 soft]# tar -zxvf apache-zookeeper-3.5.8-bin.tar.gz
[root@bigdata141 soft]# ll
total 491240
drwxr-xr-x. 7 root  root        166 Nov 27 16:24 apache-zookeeper-3.5.8-bin
-rw-r--r--. 1 root  root    9394700 Nov 27 15:59 apache-zookeeper-3.5.8-bin.tar.gz

配置

1、进入 zookeeper 下的 conf 目录,复制一份样本配置文件为 zoo.cfg,后面都是修改这份

[root@bigdata141 conf]# cd apache-zookeeper-3.5.8-bin/conf
[root@bigdata141 conf]# cp zoo_sample.cfg zoo.cfg
[root@bigdata141 conf]# vi zoo.cfg

编辑 zoo.cfg 文件,找到 dataDir,这个目录存放的是 zookeeper 的核心数据,最好不要放在 tmp 临时目录下,我这边修改为 /data/soft/apache-zookeeper-3.5.8-bin/data,还要加上 server.0、server.1、server.2 三行

dataDir=/data/soft/apache-zookeeper-3.5.8-bin/data
server.0=bigdata141:2888:3888
server.1=bigdata142:2888:3888
server.2=bigdata143:2888:3888

修改前的完整配置:

# 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=/tmp/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

修改后的完整配置:

# 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=/data/soft/apache-zookeeper-3.5.8-bin/data
server.0=bigdata141:2888:3888
server.1=bigdata142:2888:3888
server.2=bigdata143:2888:3888
# 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

2、创建 myid 文件

然后切换到 zookeeper 目录下,创建 data/ 目录并进入、echo 0 覆盖 myid 文件内容

[root@bigdata141 apache-zookeeper-3.5.8-bin]# mkdir data
[root@bigdata141 apache-zookeeper-3.5.8-bin]# cd data/
[root@bigdata141 data]# echo 0 > myid

3、复制安装包到其他节点

切换到 /data/soft 目录,执行以下命令:

[root@bigdata141 soft]# scp -rq apache-zookeeper-3.5.8-bin/ bigdata142:/data/soft/
[root@bigdata141 soft]# scp -rq apache-zookeeper-3.5.8-bin/ bigdata143:/data/soft/

4、修改其他节点配置 

修改其他节点 zookeeper 下的 myid 文件

[root@bigdata142 apache-zookeeper-3.5.8-bin]# echo 1 > data/myid 
[root@bigdata143 apache-zookeeper-3.5.8-bin]# echo 2 > data/myid 

启动zookeeper

在各个节点执行命令:bin/zkServer.sh start

[root@bigdata141 apache-zookeeper-3.5.8-bin]# bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /data/soft/apache-zookeeper-3.5.8-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

查看各个节点 zookeeper 是否启动:jps -l

都有 QuorumPeerMain 进程就表示启动成功

[root@bigdata141 apache-zookeeper-3.5.8-bin]# jps -l
4241 sun.tools.jps.Jps
4195 org.apache.zookeeper.server.quorum.QuorumPeerMain

查看各个节点 zookeeper 状态:bin/zkServer.sh status

可以看到 Mode,142为 leader 主节点,141、143为 follower 从节点

[root@bigdata141 apache-zookeeper-3.5.8-bin]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data/soft/apache-zookeeper-3.5.8-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
[root@bigdata142 apache-zookeeper-3.5.8-bin]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data/soft/apache-zookeeper-3.5.8-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader
[root@bigdata143 apache-zookeeper-3.5.8-bin]# bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /data/soft/apache-zookeeper-3.5.8-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower

停止Zookeeper

各个节点都要执行:bin/zkServer.sh stop

[root@bigdata141 apache-zookeeper-3.5.8-bin]# bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /data/soft/apache-zookeeper-3.5.8-bin/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
[root@bigdata142 apache-zookeeper-3.5.8-bin]# bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /data/soft/apache-zookeeper-3.5.8-bin/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
[root@bigdata143 apache-zookeeper-3.5.8-bin]# bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /data/soft/apache-zookeeper-3.5.8-bin/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED


http://www.kler.cn/a/413630.html

相关文章:

  • 如何在HarmonyOS NEXT中处理页面间的数据传递?
  • Unity shaderlab 实现LineSDF
  • PHP 去掉特殊不可见字符 “\u200e“
  • 富文本编辑器图片上传并回显
  • NAT:连接私有与公共网络的关键技术(4/10)
  • k8s网络服务
  • 数据库---HSQLDB使用教程详解
  • 什么是虚拟机栈
  • 200. 岛屿数量【 力扣(LeetCode) 】
  • 数据结构 (7)线性表的链式存储
  • uni-app中的样式尺寸单位,px,rpx,vh,vw
  • C++多线程——线程
  • 【人工智能】AutoML自动化机器学习模型构建与优化:使用Auto-sklearn与TPOT的实战指南
  • SpringBoot+Vue的音乐网站项目
  • mysql 触发器进入历史
  • Android 使用Charles抓包显示Unknown
  • MySQL 数据库索引优化实践指南
  • 利用阿里云镜像仓库和 Github Action 同步镜像
  • 【Qt】重写QComboBox下拉展示多列数据
  • CSGO游戏搬砖党如何应对上海Major
  • 【81-90期】Java核心面试问题深度解析:性能优化与高并发设计
  • 卷积神经网络(CNN)中的批量归一化层(Batch Normalization Layer)
  • ORACLE数据库直接取出数据库字段JSON串中的 VALUE内容
  • ensp配置静态路由与RIP协议
  • Harbor安装、HTTPS配置、修改端口后不可访问?
  • 【Java 解释器模式】实现高扩展性的医学专家诊断规则引擎