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 集群,用于处理大规模的数据同步和状态管理。

相关推荐
qq_192779871 小时前
高级爬虫技巧:处理JavaScript渲染(Selenium)
jvm·数据库·python
u0109272711 小时前
使用Plotly创建交互式图表
jvm·数据库·python
爱学习的阿磊1 小时前
Python GUI开发:Tkinter入门教程
jvm·数据库·python
tudficdew2 小时前
实战:用Python分析某电商销售数据
jvm·数据库·python
sjjhd6522 小时前
Python日志记录(Logging)最佳实践
jvm·数据库·python
Configure-Handler2 小时前
buildroot System configuration
java·服务器·数据库
2301_821369613 小时前
用Python生成艺术:分形与算法绘图
jvm·数据库·python
电商API_180079052473 小时前
第三方淘宝商品详情 API 全维度调用指南:从技术对接到生产落地
java·大数据·前端·数据库·人工智能·网络爬虫
2401_832131954 小时前
Python单元测试(unittest)实战指南
jvm·数据库·python
打工的小王4 小时前
redis(四)搭建哨兵模式:一主二从三哨兵
数据库·redis·缓存