Linux—zookeeper

news/2024/10/22 14:30:28/

文档结构

  • 1、概念简介
    • 1.1、选举机制
  • 2、环境部署
    • 2.1、单机部署
    • 2.2、集群部署
    • 2.3、客户端指令
  • 3、配置应用

1、概念简介

1.1、选举机制

2、环境部署

下载链接:https://zookeeper.apache.org/releases.html
下载版本:apache-zookeeper-3.7.1-bin.tar.gz

此处下载带 bin 的包,即经过编译的安装包;如果下载源码包,要重新编译打包后才可以使用;否则启动服务会报错 Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain

2.1、单机部署

1)下载解压
解压和安装路径:/software/Zookeeper

2)配置调整

zk 默认没有 zoo.cfg 文件,需要复制 conf 下的样例配置文件;

[gdsuser@hz-yyserv bin]$ pwd
/software/Zookeeper/bin
[gdsuser@hz-yyserv bin]$ cp ../conf/zoo_sample.cfg ../conf/zoo.cfg
[gdsuser@hz-yyserv bin]$ 
[gdsuser@hz-yyserv bin]$ ll ../conf
total 16
-rw-r--r-- 1 gdsuser gdsgrp  535 May  7 14:44 configuration.xsl
-rw-r--r-- 1 gdsuser gdsgrp 3435 May  7 14:44 log4j.properties
-rw-r--r-- 1 gdsuser gdsgrp 1148 Aug 18 14:28 zoo.cfg
-rw-r--r-- 1 gdsuser gdsgrp 1148 May  7 14:44 zoo_sample.cfg
[gdsuser@hz-yyserv bin]$

设置数据文件路径:为 ../dataDir

[gdsuser@hz-yyserv conf]$ pwd
/software/Zookeeper/conf
[gdsuser@hz-yyserv conf]$ vim 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=../dataDir
# 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.
#

3)启动服务端

[gdsuser@hz-yyserv bin]$ 
[gdsuser@hz-yyserv bin]$ sh zkServer.sh start
[gdsuser@hz-yyserv bin]$ sh zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /software/Zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[gdsuser@hz-yyserv bin]$ 
  • 状态查看
[gdsuser@hz-yyserv bin]$ sh zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /software/Zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: standalone
[gdsuser@hz-yyserv bin]$
  • 停止服务
    sh zkServer.sh stop

4)客户端启动
sh zkCli.sh
输出信息:

Connecting to localhost:2181
................
................
................
Welcome to ZooKeeper!
................
................
WATCHER::
WatchedEvent state:SyncConnected type: None path:null
[zk: localhost:2181(CONNECTED) 0]

2.2、集群部署

zookeeper 的三个端口作用

A)2181 : 对 client 端提供服务
B)2888 : 集群内机器通信使用
C)3888 : 选举 leader 使用

按照3个节点组成一套zookeeper集群,相比于单节点的部署方式,集群新增如下步骤:
1)在每个节点 zoo.cfg 文件配置末尾添加如下配置

server.1=node1_ip:2888:3888
server.2=node2_ip:2888:3888
server.3=node3_ip:2888:3888

2)配置 myid
在 zookeeper根目录新建 myid文件,按照节点编号分别配置,如 1 2 3;

3)服务端启动
说明:该步骤和单节点相同;

3)状态查看
区别于单节点的状态Mode: standalone,集群模式下模式的值分为 leader或 follswer;

2.3、客户端指令

  • 节点访问
[gdsuser@hz-yyserv bin]$ sh zkCli.sh
[zk: localhost:2181(CONNECTED) 0] ls /
[zookeeper]
[zk: localhost:2181(CONNECTED) 1] ls /zookeeper
[config, quota]
[zk: localhost:2181(CONNECTED) 2] ls /zookeeper/config
[]
  • 节点属性
[zk: localhost:2181(CONNECTED) 3] get -s -w /zookeeper/configcZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
pZxid = 0x0
cversion = 0
dataVersion = 0
aclVersion = -1
ephemeralOwner = 0x0
dataLength = 0
numChildren = 0
[zk: localhost:2181(CONNECTED) 4] 

说明:'get path [watch]' has been deprecated. Please use 'get [-s] [-w] path' instead.

  • 节点状态
[zk: localhost:2181(CONNECTED) 8] stat -w /zookeeper/config
cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
pZxid = 0x0
cversion = 0
dataVersion = 0
aclVersion = -1
ephemeralOwner = 0x0
dataLength = 0
numChildren = 0
[zk: localhost:2181(CONNECTED) 9]
  • 退出连接
[zk: localhost:2181(CONNECTED) 9] quit

3、配置应用

============================================== over =============================================


http://www.ppmy.cn/news/670700.html

相关文章

ZCU104开发板:开发板介绍1

简介 嵌入式视觉低成本(EVLC)开发套件使汽车,AR / VR,无人机,机器视觉和工业视觉开发人员能够在ZynqUltraScale™MPSoC XCZU7EV-2FFVC1156器件上构建设计原型和测试他们的设计。ZU7EV器件集成了四核ArmCortex™-A53处…

keil 简介

熟悉Keil C 51的朋友对于Keil MDK上手应该比较容易,毕竟界面是很像的。但ARM内核毕竟不同于51内核,因此无论在设置上还是在编程思想上,都需要下番功夫研究的。本文以MDK V4.03为例,详细的写一下MDK的设置、界面、工具。可能会有些…

【MDK KEIL】keil最新版安装

附赠下载地址 链接:https://pan.baidu.com/s/14W-UIj89a69Tm-JXu5s0JQ 提取码:ycyl --来自百度网盘超级会员V4的分享 1.下载地址 Keil Product Downloads下载适合你的一个版本 复制CID

zk-ui 安装部署

zookeeper的一个UI管理界面,是一个开源的项目,接下来安装部署在centos7上。在安装zk-ui之前,你要确保已经安装好了zookeeper。 1、环境准备(如果你还没有安装git 和 maven 先装一下): centos7 git maven 2、下载zk-ui git c…

Edgex Device Profile

Device Profile - EdgeX Foundry Documentation Device Profile Reference - EdgeX Foundry Documentation 设备配置文件描述了EdgeX系统中的一种设备类型。由设备服务管理的每个设备都与设备配置文件关联,设备配置文件根据其支持的操作定义设备类型。 有关设备配…

ZCU104开发板:开发板组件描述

1. Zynq UltraScale XCUZU7EV MPSoC ZCU104板上安装了Zynq UltraScale XCZU7EV-2FFVC1156 MPSoC,它在同一设备中集成了功能强大的处理系统(PS)和可编程逻辑(PL)。Zynq UltraScale MPSoC中的PS采用Arm旗舰产品Cortex…

zcu102开发板使用和评测

作者 QQ群:852283276 微信:arm80x86 微信公众号:青儿创客基地 B站:主页 https://space.bilibili.com/208826118 参考 ug1082 AR# 71584 Zynq UltraScale MPSoC: How to view SATA performance in Linux AR# 68971 Zynq UltraSca…

zookeper

zookeeper启动不了 常用命令解决zookeeper启动不了首先检查java环境先前拷贝zoo_example.cfg的文件zoo.cfg启动zkServer.sh start,查看集群状态展开Server.sh status,如果仍然没有启动,查看配置的文件目录data下myid文件是否配置正确。netsta…