etcd 集群搭建与测试指南

etcd 集群搭建与测试指南

一、容器搭建

1. 拉取 etcd 镜像

首先,需要从 Docker Hub 拉取 etcd 的镜像:

shell 复制代码
docker pull quay.io/coreos/etcd:v3.3.1

2. 创建自定义网络

为了设置容器的固定 IP,需要创建一个自定义网络:

shell 复制代码
docker network create --subnet 172.19.0.0/16 ots

3. 创建容器

以下是创建 etcd 集群的三个节点的命令:

  • 容器一 (IP: 172.19.0.110)
shell 复制代码
docker run -d \
-p 2379:2379 -p 2380:2380 \
--name node1 --network=ots \
--ip 172.19.0.110 \
quay.io/coreos/etcd:v3.3.1 \
etcd \
-name node1 \
-advertise-client-urls http://172.19.0.110:2379 \
-initial-advertise-peer-urls http://172.19.0.110:2380 \
-listen-client-urls http://0.0.0.0:2379  \
-listen-peer-urls http://0.0.0.0:2380 \
-initial-cluster-token etcd-cluster \
-initial-cluster "node1=http://172.19.0.110:2380,node2=http://172.19.0.120:2380,node3=http://172.19.0.130:2380" \
-initial-cluster-state new
  • 容器二 (IP: 172.19.0.120)
shell 复制代码
docker run -d \
-p 2479:2379 -p 2480:2380 \
--name node2 --network=ots \
--ip 172.19.0.120 \
quay.io/coreos/etcd:v3.3.1 \
etcd \
-name node2 \
-advertise-client-urls http://172.19.0.120:2379 \
-initial-advertise-peer-urls http://172.19.0.120:2380 \
-listen-client-urls http://0.0.0.0:2379 \
-listen-peer-urls http://0.0.0.0:2380 \
-initial-cluster-token etcd-cluster \
-initial-cluster "node1=http://172.19.0.110:2380,node2=http://172.19.0.120:2380,node3=http://172.19.0.130:2380" \
-initial-cluster-state new
  • 容器三 (IP: 172.19.0.130)
shell 复制代码
docker run -d \
-p 2579:2379 -p 2580:2380 \
--name node3 --network=ots \
--ip 172.19.0.130 \
quay.io/coreos/etcd:v3.3.1 \
etcd \
-name node3 \
-advertise-client-urls http://172.19.0.130:2379 \
-initial-advertise-peer-urls http://172.19.0.130:2380 \
-listen-client-urls http://0.0.0.0:2379 \
-listen-peer-urls http://0.0.0.0:2380 \
-initial-cluster-token etcd-cluster \
-initial-cluster "node1=http://172.19.0.110:2380,node2=http://172.19.0.120:2380,node3=http://172.19.0.130:2380" \
-initial-cluster-state new

参数解释

  • --listen-client-urls: 监听 URL,用于与客户端通讯。
  • --listen-peer-urls: 监听 URL,用于与其他节点通讯。
  • --initial-advertise-peer-urls: 告知集群其他节点 URL。
  • --advertise-client-urls: 告知客户端 URL。
  • --initial-cluster-token: 集群的 ID。
  • --initial-cluster: 集群中所有节点。
  • --initial-cluster-state new: 表示从无到有搭建 etcd 集群。

4. 检查容器状态

使用以下命令查看所有容器是否都在运行状态:

shell 复制代码
docker ps -a

二、容器集群测试

1. 进入容器

打开两个窗口,分别进入 node1 和 node2 容器:

shell 复制代码
docker exec -it node1 sh
docker exec -it node2 sh

2. 测试数据同步

在 node2 容器中添加数据:

shell 复制代码
etcdctl set /aa/bb 123

在 node1 容器中获取数据:

shell 复制代码
etcdctl get /aa/bb

如果数据能够成功同步,说明集群已经搭建成功。

3. 查看所有节点

使用以下命令查看所有节点信息:

shell 复制代码
etcdctl member list

可以看到 node1 最后的 true,这代表它是主节点。

应用场景

  • 日均流量: 3400万
  • 车场数量: 5万个
  • 设备数量: 5万台

状态查询机制

  • 状态、事件、地感、道闸、道闸开启、鉴权、识别、检索日志

数据处理

  • 每月处理 10 亿数据
  • 使用 Kafka 进行数据持久化

通过上述步骤,可以成功搭建并测试一个 etcd 集群,用于处理大规模的数据同步和状态管理。

相关推荐
倔强的石头_31 分钟前
【金仓数据库】ksql 指南(四) —— 创建与管理表(KingbaseES 数据存储核心)
数据库
赵渝强老师32 分钟前
【赵渝强老师】TiDB PD集群存储的信息
数据库·mysql·tidb
老纪的技术唠嗑局1 小时前
分库分表MyCat 架构迁移 OceanBase | 百丽核心财务系统迁移经验总结与问题汇总
数据库·架构·oceanbase
xrkhy7 小时前
微服务之ShardingSphere
数据库·微服务·oracle
JIngJaneIL7 小时前
停车场管理|停车预约管理|基于Springboot的停车场管理系统设计与实现(源码+数据库+文档)
java·数据库·spring boot·后端·论文·毕设·停车场管理系统
煎蛋学姐7 小时前
SSM儿童福利院管理系统ys9w2d07(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
数据库·ssm 框架·儿童福利院管理系统
sg_knight7 小时前
MySQL 空间索引(SPATIAL)详解:地理位置数据的高效查询利器
数据库·mysql·database·索引·关系型数据库·空间索引·spatial
梦子yumeko9 小时前
第五章Langchain4j之基于内存和redis实现聊天持久化
数据库·redis·缓存
IndulgeCui9 小时前
【金仓数据库产品体验官】KSQL Developer Linux版安装使用体验
linux·运维·数据库
一马平川的大草原10 小时前
基于n8n实现数据库多表数据同步
数据库·数据同步·dify·n8n