如何从0开始搭建一个3节点的ZooKeeper仲裁集群

2024-03-29 07:48

本文主要是介绍如何从0开始搭建一个3节点的ZooKeeper仲裁集群,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

时间戳:2021-04-08 22:00:46

  1. 场景:客户端与ZK集群交互图
    客户端与ZK集群交互图
    本文,将规划一个3节点的ZK集群。

  2. 软件安装
    本文使用了spack包管理器一键式安装zookeeper软件,命令为

spack install zookeeper

安装好的zookeeper目录结构如下
在这里插入图片描述
3. 配置文件
本集群3节点,需3个配置文件
在这里插入图片描述
如上图所示,分别定义了server.1, server.2, server.3三台服务器。

服务器从 $dataDir/myid 文件中得到自己的ID,在启动集群之前,先将各自的myid文件准备好
在这里插入图片描述
4. 启动集群
启动命令是

zkServer.sh start </path/to/zoo.cfg>

我将集群启动命令写在脚本里,如下图
在这里插入图片描述
执行./start_zk_quorums.sh脚本,将集群启动起来

  1. 检查集群的状态
    在这里插入图片描述

  2. 客户端连接

/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/zkCli.sh \
-server 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183Connecting to 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
2021-04-08 21:55:59,402 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.11-37e277162d567b55a07d1755f0b31c32e93c01a0, built on 11/01/2017 18:06 GMT
2021-04-08 21:55:59,407 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=192.168.1.5
2021-04-08 21:55:59,407 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.8.0_281
2021-04-08 21:55:59,409 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2021-04-08 21:55:59,409 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
2021-04-08 21:55:59,409 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../build/classes:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../build/lib/*.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../lib/slf4j-log4j12-1.6.1.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../lib/slf4j-api-1.6.1.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../lib/netty-3.10.5.Final.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../lib/log4j-1.2.16.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../lib/jline-0.9.94.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../lib/audience-annotations-0.5.0.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../zookeeper-3.4.11.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../src/java/lib/*.jar:/Users/ben/software/opensource/Spack/spack/opt/spack/darwin-bigsur-cannonlake/apple-clang-12.0.0/zookeeper-3.4.11-bedjbhw3v2t3jpgsbpxotsne6mhimssc/bin/../conf:
2021-04-08 21:55:59,409 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/Users/ben/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
2021-04-08 21:55:59,410 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/var/folders/9d/x216k2yd6kjbqt67_svwpy940000gn/T/
2021-04-08 21:55:59,410 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
2021-04-08 21:55:59,410 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Mac OS X
2021-04-08 21:55:59,410 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=x86_64
2021-04-08 21:55:59,410 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=10.16
2021-04-08 21:55:59,410 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=ben
2021-04-08 21:55:59,410 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/Users/ben
2021-04-08 21:55:59,410 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/Users/ben/zkPractice
2021-04-08 21:55:59,412 [myid:] - INFO  [main:ZooKeeper@441] - Initiating client connection, connectString=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@27fa135a
Welcome to ZooKeeper!
2021-04-08 21:55:59,437 [myid:] - INFO  [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@1035] - Opening socket connection to server 127.0.0.1/127.0.0.1:2182. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2021-04-08 21:55:59,450 [myid:] - INFO  [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@877] - Socket connection established to 127.0.0.1/127.0.0.1:2182, initiating session
2021-04-08 21:55:59,458 [myid:] - INFO  [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@1302] - Session establishment complete on server 127.0.0.1/127.0.0.1:2182, sessionid = 0x200026b38b80001, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183(CONNECTED) 0] ls
[zk: 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183(CONNECTED) 1] ls /
[zookeeper]
[zk: 127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183(CONNECTED) 2]
  1. 小结

ZooKeeper为分布式应用提供协调服务。让开发者更少关注分布式系统协调服务,将有限的精力投入到更有价值的业务的开发。

这篇关于如何从0开始搭建一个3节点的ZooKeeper仲裁集群的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/858022

相关文章

服务器集群同步时间手记

1.时间服务器配置(必须root用户) (1)检查ntp是否安装 [root@node1 桌面]# rpm -qa|grep ntpntp-4.2.6p5-10.el6.centos.x86_64fontpackages-filesystem-1.41-1.1.el6.noarchntpdate-4.2.6p5-10.el6.centos.x86_64 (2)修改ntp配置文件 [r

Zookeeper安装和配置说明

一、Zookeeper的搭建方式 Zookeeper安装方式有三种,单机模式和集群模式以及伪集群模式。 ■ 单机模式:Zookeeper只运行在一台服务器上,适合测试环境; ■ 伪集群模式:就是在一台物理机上运行多个Zookeeper 实例; ■ 集群模式:Zookeeper运行于一个集群上,适合生产环境,这个计算机集群被称为一个“集合体”(ensemble) Zookeeper通过复制来实现

HDFS—集群扩容及缩容

白名单:表示在白名单的主机IP地址可以,用来存储数据。 配置白名单步骤如下: 1)在NameNode节点的/opt/module/hadoop-3.1.4/etc/hadoop目录下分别创建whitelist 和blacklist文件 (1)创建白名单 [lytfly@hadoop102 hadoop]$ vim whitelist 在whitelist中添加如下主机名称,假如集群正常工作的节

Hadoop集群数据均衡之磁盘间数据均衡

生产环境,由于硬盘空间不足,往往需要增加一块硬盘。刚加载的硬盘没有数据时,可以执行磁盘数据均衡命令。(Hadoop3.x新特性) plan后面带的节点的名字必须是已经存在的,并且是需要均衡的节点。 如果节点不存在,会报如下错误: 如果节点只有一个硬盘的话,不会创建均衡计划: (1)生成均衡计划 hdfs diskbalancer -plan hadoop102 (2)执行均衡计划 hd

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

搭建Kafka+zookeeper集群调度

前言 硬件环境 172.18.0.5        kafkazk1        Kafka+zookeeper                Kafka Broker集群 172.18.0.6        kafkazk2        Kafka+zookeeper                Kafka Broker集群 172.18.0.7        kafkazk3

day-51 合并零之间的节点

思路 直接遍历链表即可,遇到val=0跳过,val非零则加在一起,最后返回即可 解题过程 返回链表可以有头结点,方便插入,返回head.next Code /*** Definition for singly-linked list.* public class ListNode {* int val;* ListNode next;* ListNode() {}*

【IPV6从入门到起飞】5-1 IPV6+Home Assistant(搭建基本环境)

【IPV6从入门到起飞】5-1 IPV6+Home Assistant #搭建基本环境 1 背景2 docker下载 hass3 创建容器4 浏览器访问 hass5 手机APP远程访问hass6 更多玩法 1 背景 既然电脑可以IPV6入站,手机流量可以访问IPV6网络的服务,为什么不在电脑搭建Home Assistant(hass),来控制你的设备呢?@智能家居 @万物互联

pico2 开发环境搭建-基于ubuntu

pico2 开发环境搭建-基于ubuntu 安装编译工具链下载sdk 和example编译example 安装编译工具链 sudo apt install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib 注意cmake的版本,需要在3.17 以上 下载sdk 和ex

【每日一题】LeetCode 2181.合并零之间的节点(链表、模拟)

【每日一题】LeetCode 2181.合并零之间的节点(链表、模拟) 题目描述 给定一个链表,链表中的每个节点代表一个整数。链表中的整数由 0 分隔开,表示不同的区间。链表的开始和结束节点的值都为 0。任务是将每两个相邻的 0 之间的所有节点合并成一个节点,新节点的值为原区间内所有节点值的和。合并后,需要移除所有的 0,并返回修改后的链表头节点。 思路分析 初始化:创建一个虚拟头节点