首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Etcd-集群部署方案

Etcd-集群部署方案

作者头像
运维小路
发布2026-02-28 18:16:10
发布2026-02-28 18:16:10
370
举报
文章被收录于专栏:运维小路运维小路

作者介绍:简历上没有一个精通的运维工程师,下面的思维导图也是预计更新的内容和当前进度(不定时更新)。

数据库是一个系统(应用)最重要的资产之一,所以我们的数据库将从以下几个数据库来进行介绍。

MySQL

PostgreSQL

MongoDB

Redis

Etcd(本章节)

前面介绍Etcd的单节点部署和基本的增删改查,实际环境基本都是以集群方式

来部署的,所以下面我们以三节点和二进制进行部署。

环境规划

前面我们介绍了每个etcd节点都需要自己的名字,所以我们这里就根据IP地址定义了他们的名字。

角色

IP

etcd100

192.168.31.100

etcd101

192.168.31.101

etcd102

192.168.31.102

部署启动

启动etcd100

这里由于集群模式,当启动节点只有一个的时候,无法选举出来Leader,所他会等待其他节点加入,也就无法正常提供服务。

代码语言:javascript
复制
./etcd  \
  --name etcd100 \
  --data-dir /tmp/etcd \
  --listen-client-urls http://192.168.31.100:2379 \
  --advertise-client-urls http://192.168.31.100:2379 \
  --listen-peer-urls http://192.168.31.100:2380 \
  --initial-advertise-peer-urls http://192.168.31.100:2380 \
  --initial-cluster etcd100=http://192.168.31.100:2380,etcd101=http://192.168.31.101:2380,etcd102=http://192.168.31.102:2380 \
  --initial-cluster-token my-etcd-token \
  --initial-cluster-state new

启动etcd101

当第二个节点启动的时候,就可以选举出来Leader,这个时候集群就可以提供服务。

代码语言:javascript
复制
./etcd  \
--name etcd101 \
  --data-dir /tmp/etcd \
  --listen-client-urls http://192.168.31.101:2379 \
  --advertise-client-urls http://192.168.31.101:2379 \
  --listen-peer-urls http://192.168.31.101:2380 \
  --initial-advertise-peer-urls http://192.168.31.101:2380 \
  --initial-cluster etcd100=http://192.168.31.100:2380,etcd101=http://192.168.31.101:2380,etcd102=http://192.168.31.102:2380 \
  --initial-cluster-token my-etcd-token \
  --initial-cluster-state new

启动etcd102

代码语言:javascript
复制
./etcd  \
--name etcd102 \
  --data-dir /tmp/etcd \
  --listen-client-urls http://192.168.31.102:2379 \
  --advertise-client-urls http://192.168.31.102:2379 \
  --listen-peer-urls http://192.168.31.102:2380 \
  --initial-advertise-peer-urls http://192.168.31.102:2380 \
  --initial-cluster etcd100=http://192.168.31.100:2380,etcd101=http://192.168.31.101:2380,etcd102=http://192.168.31.102:2380 \
  --initial-cluster-token my-etcd-token \
  --initial-cluster-state new

参数解释

--listen-client-urls:监听地址,可以多个,一般是本机ip+127.0.0.1

--advertise-client-urls:客户端链接地址

--listen-peer-urls:集群通信监听端口

--initial-advertise-peer-urls:告诉集群自己的对外通信端口

--initial-cluster :集群列表,这里的名字需要前面对应上。

--initial-cluster-token:所有节点令牌,必须一样,才能组成集群。

--initial-cluster-state:new用于新集群,旧集群用existing。

检查Etcd集群状态

代码语言:javascript
复制
# 使用 etcdctl 检查集群健康状态
export ETCDCTL_API=3

# 方式1:检查单个节点
etcdctl --endpoints=192.168.31.100:2379 endpoint health

# 方式2:检查所有节点
etcdctl --endpoints=192.168.31.100:2379,192.168.31.101:2379,192.168.31.102:2379 endpoint health

# 方式3:查看成员列表
etcdctl --endpoints=192.168.31.100:2379 member list

# 方式4:写入测试数据
etcdctl --endpoints=192.168.31.100:2379 put test_key "hello world"
etcdctl --endpoints=192.168.31.101:2379 get test_key

# 方式5:查看当前集群角色
etcdctl --endpoints=http://192.168.31.100:2379,http://192.168.31.101:2379,http://192.168.31.102:2379 endpoint status 

etcdctl --endpoints=http://192.168.31.100:2379,http://192.168.31.101:2379,http://192.168.31.102:2379 endpoint status --write-out=table

这样我们的集群就部署完成。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2026-02-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 运维小路 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • MongoDB
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档