Zookeeper环境搭建

本文涉及的产品
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
简介: Zookeeper环境搭建

Zookeeper环境搭建


网址

官网:https://zookeeper.apache.org/

下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/


依赖

需要依赖 JAVA 环境


JAVA 配置:


单机

进入 ZK 解压目录下的 conf 目录,配置 ZK 配置文件 zoo.cfg,直接复制 conf 目录下 zoo_sample.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=/tmp/zookeeper 配置数据目录
dataDir=/usr/local/apps/zookeeper/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


进入 ZK 解压目录,执行命令即可

# {start|start-foreground|stop|restart|status|print-cmd}
# 启动命令
bin/zkServer.sh start
# 查看状态命令
bin/zkServer.sh status


进入 ZK 客户端管理界面

bin/zkCli.sh -server 127.0.0.1:2181


客户端管理命令

# 获取客户端管理命令
help
# 列举所有节点
ls /
# 创建节点
create /节点名
# 获取节点信息
get /节点名
# 设置节点数据
set /节点名 数据
# 删除节点
delete /节点名


集群

配置

每个zk节点都要配置


进入 ZK 解压目录下的 conf 目录,配置 ZK 配置文件 zoo.cfg,直接复制 conf 目录下 zoo_sample.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=/tmp/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.
#
# 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
# 配置zookeeper服务,server.ID=IP:C:D
# ID:表示每个节点唯一ID;
# IP:表示每个节点的IP;
# C:表示服务器与集群中的leader服务器交换信息的端口
# D:表示leader挂掉时专门用来进行选举leader所用的端口
server.1= 192.168.239.150:2888:3888
server.2= 192.168.239.149:2888:3888
server.3= 192.168.239.151:2888:3888


配置 myid

需要在zoo.cfg中数据文件目录下配置 myid 文件,用于 ServerID标识,和配置zookeeper服务,server.ID=IP:C:D对应

# 在 192.168.239.150 集群中myid数据为
1
# 在 192.168.239.149 集群中myid数据为
2
# 在 192.168.239.151 集群中myid数据为
3


启动

依次启动三个 zookeeper 服务

# {start|start-foreground|stop|restart|status|print-cmd}
# 启动命令
bin/zkServer.sh start
# 查看状态命令
bin/zkServer.sh status


测试

使用 zkCli.sh 客户端,在某一台zookeeper服务中创建节点,在其他台zookeeper服务中查询到说明成功

# 启动 150 机器的zkCli客户端
bin/zkCli.sh -server 192.168.239.150:2181
# 启动 149 机器的zkCli客户端
bin/zkCli.sh -server 192.168.239.149:2181
# 启动 151 机器的zkCli客户端
bin/zkCli.sh -server 192.168.239.151:2181


客户端管理命令

# 获取客户端管理命令
help
# 列举所有节点
ls /
# 创建节点
create /节点名
# 获取节点信息
get /节点名
# 设置节点数据
set /节点名 数据
# 删除节点
delete /节点名


相关实践学习
基于MSE实现微服务的全链路灰度
通过本场景的实验操作,您将了解并实现在线业务的微服务全链路灰度能力。
目录
相关文章
|
4天前
|
消息中间件 存储 Kafka
Kafka【环境搭建 02】kafka_2.11-2.4.1 基于 zookeeper 搭建高可用伪集群(一台服务器实现三个节点的 Kafka 集群)
【2月更文挑战第19天】Kafka【环境搭建 02】kafka_2.11-2.4.1 基于 zookeeper 搭建高可用伪集群(一台服务器实现三个节点的 Kafka 集群)
145 1
|
4天前
|
存储 算法 Java
【分布式】Zookeeper 使用环境搭建
【1月更文挑战第25天】【分布式】Zookeeper 使用环境搭建
|
7月前
|
Linux
ZooKeeper集群环境搭建
ZooKeeper集群环境搭建
66 0
|
9月前
|
Java Linux 开发工具
zookeeper集群环境搭建及使用
zookeeper集群环境搭建及使用
98 0
|
存储
Zookeeper 3.7.1环境搭建
Zookeeper 3.7.1环境搭建
182 0
|
Apache
Zookeeper单机模式和集群模式环境搭建
Zookeeper单机模式和集群模式环境搭建
136 0
|
存储
zookeeper环境搭建
zookeeper环境搭建
88 0
|
Java Linux
Linux java基础环境搭建 ->zookeeper
Linux java基础环境搭建 ->zookeeper
79 0
|
Apache
Zookeeper单机模式和集群模式环境搭建
Zookeeper单机模式和集群模式环境搭建
110 0
|
Linux 数据库
zookeeper 单机. 集群环境搭建
zookeeper分布式系统中面临的很多问题, 如分布式锁,统一的命名服务,配置中心,集群的管理Leader的选举等
141 0