使用docker搭建zk集群

news/2024/12/22 0:23:59/

使用zk搭建一个3节点的zk集群,网络方式为host。

配置节点1

# 创建一个目录
/root/lyl/zookeeper/zk1

创建文件myid,文件内容如下:

1

创建文件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=/data
# 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=14lw.commands.whitelist=ruok,srvr,stat,confserver.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890

创建启动文件startzk.sh,文件内容如下:

#!/bin/shdocker rm -f myzookeeper1docker run --network host  -v /root/lyl/zookeeper/zk1/myid:/data/myid  -v /root/lyl/zookeeper/zk1/zoo.cfg:/conf/zoo.cfg  --name myzookeeper1  --restart always -d zookeeper:3.9.2

完成。

 配置节点2

# 创建一个目录
/root/lyl/zookeeper/zk2

创建文件myid,文件内容如下:

2

创建文件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=/data
# the port at which the clients will connect
clientPort=2182
# 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=14lw.commands.whitelist=ruok,srvr,stat,confserver.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890

创建启动文件startzk.sh,文件内容如下:

#!/bin/shdocker rm -f myzookeeper2docker run --network host  -v /root/lyl/zookeeper/zk2/myid:/data/myid  -v /root/lyl/zookeeper/zk2/zoo.cfg:/conf/zoo.cfg  --name myzookeeper2  --restart always -d zookeeper:3.9.2

完成节点2配置。

 配置节点3

# 创建一个目录
/root/lyl/zookeeper/zk3

创建文件myid,文件内容如下:

3

创建文件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=/data
# the port at which the clients will connect
clientPort=2183
# 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=14lw.commands.whitelist=ruok,srvr,stat,confserver.1=localhost:2888:3888
server.2=localhost:2889:3889
server.3=localhost:2890:3890

创建启动文件startzk.sh,文件内容如下:

#!/bin/shdocker rm -f myzookeeper3docker run --network host  -v /root/lyl/zookeeper/zk3/myid:/data/myid  -v /root/lyl/zookeeper/zk3/zoo.cfg:/conf/zoo.cfg  --name myzookeeper3  --restart always -d zookeeper:3.9.2

完成。


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

相关文章

稀缺森林火险等级预测算法,基于xgboost方法的火险等级预测,共划分5级,依据当前地区月份,降水量,风力等参数进行预测,并提供15000字的报告

森林火险等级预测算法,基于xgboost方法的火险等级预测,共划分5级,依据当前地区月份,降水量,风力等参数进行预测,并提供15000字的报告 森林火险等级预测算法介绍 项目名称 基于XGBoost的森林火险等级预测算…

MQTTnet.Extensions.ManagedClient客户端连接

一、MQTT客户端 代码如下(示例): using MQTTnet; using MQTTnet.Client; using MQTTnet.Extensions.ManagedClient; using MQTTnet.Protocol; using MQTTnet.Server; using System; using System.Collections.Generic; using System.Linq…

C语言 | Leetcode C语言题解之第450题删除二叉搜索树中的节点

题目: 题解: struct TreeNode* deleteNode(struct TreeNode* root, int key){struct TreeNode *cur root, *curParent NULL;while (cur && cur->val ! key) {curParent cur;if (cur->val > key) {cur cur->left;} else {cur c…

git(1) -- 环境配置

1. 配置文件 编辑~/.gitconfig文件,内容如下。 [user]email xflming163.comname xflm [core]editor vim [color]diff autostatus autobranch autoui true [commit]template /home/xflm/configuser/git-commit.template [diff]tool bc4 [difftool]prompt …

无环SLAM系统集成后端回环检测模块(loop):SC-A-LOAM以及FAST_LIO_SLAM

最近在研究SLAM目标检测相关知识,看到一篇论文,集成了SC-A-LOAM作为后端回环检测模块,在学习了论文相关内容后决定看一下代码知识,随后将其移植,学习过程中发现我找的论文已经集成了回环检测模块,但是我的另…

掌握C#核心概念:类、继承、泛型等

C# 是一门功能强大且灵活的面向对象编程语言,它结合了许多现代编程语言的特点和特性。无论你是编程新手,还是有经验的开发者,理解C#中的核心概念都是非常重要的。本文将介绍C#中的类与对象、构造函数和析构函数、方法的重载与重写、继承与多态…

【理论】负载均衡

目录 1. 定义2. 主要作用3. 实现方法4. 实现原理 1. 定义 负载均衡(Load Balancing)将网络流量、请求等输入分发到后端服务器,为后端服务器提供负载均衡,实现高可用和容错。 2. 主要作用 1. 高并发 通过将请求均匀分配到多个服务…

【分布式微服务云原生】Redis投票延迟深度解析:优化集群稳定性的关键策略

Redis投票延迟深度解析:优化集群稳定性的关键策略 摘要: 在Redis集群环境中,网络分区和节点故障是不可避免的问题。本文将详细探讨Redis的投票延迟机制,解释其在集群故障转移过程中的作用,并提供实用的配置建议。通过…