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

相关推荐
huaqianzkh1 小时前
了解MySQL 高可用架构:主从备份
数据库·mysql·架构
向往风的男子2 小时前
【mysql】mysql之读写分离以及分库分表
数据库·mysql
阳光开朗_大男孩儿2 小时前
DBUS属性原理
linux·服务器·前端·数据库·qt
挠背小能手2 小时前
达梦数据库SCHEMA使用初探
数据库·oracle
楠神说软件测试3 小时前
接口自动化框架入门(requests+pytest)
运维·数据库·自动化
惟长堤一痕3 小时前
医学数据分析实训 项目一 医学数据采集
数据库
xuan哈哈哈3 小时前
web基础—dvwa靶场(八)SQL Injection(Blind)
数据库·web安全·网络安全
Lill_bin3 小时前
Lua编程语言简介与应用
开发语言·数据库·缓存·设计模式·性能优化·lua
终末圆3 小时前
MyBatis动态SQL中的`if`标签使用【后端 19】
java·数据结构·数据库·sql·算法·spring·mybatis
拾伍廿肆3 小时前
Django ORM(多表)
数据库·django