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

相关推荐
李元豪2 小时前
grpo nl2sql qwen3 模型强化学习训练有效果的成立条件有哪些
数据库·oracle
Hello.Reader5 小时前
RedisJSON 路径语法深度解析与实战
数据库·redis·缓存
TDengine (老段)5 小时前
TDengine 使用最佳实践(2)
大数据·数据库·物联网·时序数据库·iot·tdengine·涛思数据
设计师小聂!8 小时前
Linux系统中部署Redis详解
linux·运维·数据库·redis
kfepiza8 小时前
Debian-10编译安装Mysql-5.7.44 笔记250706
linux·数据库·笔记·mysql·debian·bash
Touper.8 小时前
Redis 基础详细介绍(Redis简单介绍,命令行客户端,Redis 命令,Java客户端)
java·数据库·redis
不剪发的Tony老师8 小时前
phpMyAdmin:一款经典的MySQL在线管理工具又回来了
数据库·mysql·phpmyadmin
极限实验室8 小时前
TDBC 2025 可信数据库发展大会,极限科技邀您来赴约!
数据库
lixia0417mul210 小时前
使用Starrocks替换Clickhouse的理由
数据库
张璐月11 小时前
mysql的性能优化:组提交、数据页复用、全表扫描优化、刷脏页
数据库·mysql·性能优化