当前位置: 首页 > news >正文

centos8集群部署etcd

要在测试环境中以非 TLS 模式(纯 IP + 端口)部署一个 3 节点的 etcd 集群用于 Kubernetes,可以参考以下步骤。你当前有三台机器:

节点IP角色
zk1192.168.3.72master
zk2192.168.3.60node
zk3192.168.3.75node

我们用 etcd 二进制方式部署,构建 3 节点 etcd 集群,端口固定使用默认的 2379(client)和 2380(peer)。


🧱 1. 环境准备(所有节点执行)

# 下载 etcd(以 v3.5.12 为例)
wget https://github.com/etcd-io/etcd/releases/download/v3.5.12/etcd-v3.5.12-linux-amd64.tar.gz
tar -xzf etcd-v3.5.12-linux-amd64.tar.gz
sudo mv etcd-v3.5.12-linux-amd64/etcd* /usr/local/bin/# 创建 etcd 数据目录
sudo mkdir -p /var/lib/etcd
sudo chown -R root:root /var/lib/etcd
sudo chmod 700 /var/lib/etcd

⚙️ 2. 设置各节点名称和集群定义

以下是每个节点配置建议(可以用 systemd 管理):

📍 节点 zk1(192.168.3.72):/etc/systemd/system/etcd.service
[Unit]
Description=etcd zk1
Documentation=https://github.com/etcd-io/etcd
After=network.target[Service]
Type=notify
ExecStart=/usr/local/bin/etcd \--name zk1 \--data-dir=/var/lib/etcd \--listen-client-urls=https://192.168.3.72:2379,https://127.0.0.1:2379 \--advertise-client-urls=https://192.168.3.72:2379 \--listen-peer-urls=https://192.168.3.72:2380 \--initial-advertise-peer-urls=https://192.168.3.72:2380 \--initial-cluster=zk1=https://192.168.3.72:2380,zk2=https://192.168.3.60:2380,zk3=https://192.168.3.75:2380 \--initial-cluster-token=etcd-cluster-1 \--initial-cluster-state=new \--cert-file=/etc/kubernetes/pki/etcd/server.crt \--key-file=/etc/kubernetes/pki/etcd/server.key \--trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt \--client-cert-auth=true \--peer-cert-file=/etc/kubernetes/pki/etcd/peer.crt \--peer-key-file=/etc/kubernetes/pki/etcd/peer.key \--peer-client-cert-auth=true \--peer-trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crtRestart=on-failure
LimitNOFILE=65536[Install]
WantedBy=multi-user.target
📍 节点 zk2(192.168.3.60):/etc/systemd/system/etcd.service
[Unit]
Description=etcd zk2
Documentation=https://github.com/etcd-io/etcd
After=network.target[Service]
Type=notify
ExecStart=/usr/local/bin/etcd \--name zk2 \--data-dir=/var/lib/etcd \--listen-client-urls=https://192.168.3.60:2379,https://127.0.0.1:2379 \--advertise-client-urls=https://192.168.3.60:2379 \--listen-peer-urls=https://192.168.3.60:2380 \--initial-advertise-peer-urls=https://192.168.3.60:2380 \--initial-cluster=zk1=https://192.168.3.72:2380,zk2=https://192.168.3.60:2380,zk3=https://192.168.3.75:2380 \--initial-cluster-token=etcd-cluster-1 \--initial-cluster-state=new \--cert-file=/etc/kubernetes/pki/etcd/server.crt \--key-file=/etc/kubernetes/pki/etcd/server.key \--trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt \--client-cert-auth=true \--peer-cert-file=/etc/kubernetes/pki/etcd/peer.crt \--peer-key-file=/etc/kubernetes/pki/etcd/peer.key \--peer-client-cert-auth=true \--peer-trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crtRestart=on-failure
LimitNOFILE=65536[Install]
WantedBy=multi-user.target
📍 节点 zk3(192.168.3.75):/etc/systemd/system/etcd.service
[Unit]
Description=etcd zk3
Documentation=https://github.com/etcd-io/etcd
After=network.target[Service]
Type=notify
ExecStart=/usr/local/bin/etcd \--name zk3 \--data-dir=/var/lib/etcd \--listen-client-urls=https://192.168.3.75:2379,https://127.0.0.1:2379 \--advertise-client-urls=https://192.168.3.75:2379 \--listen-peer-urls=https://192.168.3.75:2380 \--initial-advertise-peer-urls=https://192.168.3.75:2380 \--initial-cluster=zk1=https://192.168.3.72:2380,zk2=https://192.168.3.60:2380,zk3=https://192.168.3.75:2380 \--initial-cluster-token=etcd-cluster-1 \--initial-cluster-state=new \--cert-file=/etc/kubernetes/pki/etcd/server.crt \--key-file=/etc/kubernetes/pki/etcd/server.key \--trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt \--client-cert-auth=true \--peer-cert-file=/etc/kubernetes/pki/etcd/peer.crt \--peer-key-file=/etc/kubernetes/pki/etcd/peer.key \--peer-client-cert-auth=true \--peer-trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crtRestart=on-failure
LimitNOFILE=65536[Install]
WantedBy=multi-user.target

📌 注意事项:

  • --initial-cluster 所有节点必须完全一致

  • 所有节点第一次启动必须为 --initial-cluster-state new

  • 如果 etcd 数据目录不为空则无法用 new 启动,重启时需改为 existing


🚀 启动和验证

每台机器上执行以下命令启用并启动服务:

sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable etcd
sudo systemctl start etcd
sudo systemctl status etcd

✅ 4. 验证集群状态(任一节点执行)

etcdctl --endpoints="http://192.168.3.72:2379,http://192.168.3.60:2379,http://192.168.3.75:2379" endpoint health

查看成员:

etcdctl --endpoints=http://192.168.3.72:2379 member list


文章转载自:
http://angor.hyyxsc.cn
http://champleve.hyyxsc.cn
http://canvas.hyyxsc.cn
http://antimutagenic.hyyxsc.cn
http://antiscriptural.hyyxsc.cn
http://carful.hyyxsc.cn
http://annatto.hyyxsc.cn
http://bridge.hyyxsc.cn
http://cagmag.hyyxsc.cn
http://belligerency.hyyxsc.cn
http://blackball.hyyxsc.cn
http://apogeotropism.hyyxsc.cn
http://aesthetical.hyyxsc.cn
http://abortively.hyyxsc.cn
http://amphitryon.hyyxsc.cn
http://burgh.hyyxsc.cn
http://carthage.hyyxsc.cn
http://bedeck.hyyxsc.cn
http://celestial.hyyxsc.cn
http://ambassador.hyyxsc.cn
http://carbarn.hyyxsc.cn
http://barnaby.hyyxsc.cn
http://cerigo.hyyxsc.cn
http://befogged.hyyxsc.cn
http://chiffchaff.hyyxsc.cn
http://agenize.hyyxsc.cn
http://basophilic.hyyxsc.cn
http://carburant.hyyxsc.cn
http://chromosphere.hyyxsc.cn
http://chon.hyyxsc.cn
http://www.dtcms.com/a/281243.html

相关文章:

  • 【12】MFC入门到精通——MFC 消息对话框 MessageBox()和AfxMessageBox() 解析 示例 及 应用实例
  • 【目标追踪】MUTR3D: A Multi-camera Tracking Framework via 3D-to-2D Queries
  • MongoDB数据问题说明
  • css-css执行的三种方式和css选择器
  • AS32X601 系列 MCU 硬件最小系统设计与调试方案探析
  • Agentic AI 的威胁与缓解措施
  • 如何快速有效地在WordPress中添加Instagram动态
  • 【PTA数据结构 | C语言版】前序遍历二叉树
  • 零基础入门物联网-远程门禁开关:代码调试
  • 过滤数组中null、undefined、‘‘、等非真内容
  • AAAI-2025 | 同济大学面向嘈杂环境的音频视觉导航!BeDAViN:大规模音频-视觉数据集与多声源架构研究
  • OpenCSG QA:您的国产大模型与 Agent 管理平台
  • 变更缓冲池简介
  • 19.1 单元测试框架
  • ssm学习笔记day08mybatis
  • ESP32轻松实现UDP无线通信
  • 使用python的pillow模块将图片转化为灰度图,获取值和修改值
  • 雷军的 IP 革命:人格化力量如何重塑商业规则|创客匠人
  • uniapp微信小程序弹窗
  • 《汇编语言:基于X86处理器》第8章 高级过程(1)
  • 被人工智能激活的哲学
  • 短剧小程序的「技术革命」:从「粗放生长」到「精准运营」
  • Windows内核对象
  • 新方法!家长可用安卓或苹果,远程管理孩子使用iPhone的时长
  • LeetCode|Day12|58. 最后一个单词的长度|Python刷题笔记
  • 跨平台游戏引擎 Axmol-2.7.1 发布
  • C#中Static关键字解析
  • k8s环境使用Operator部署Seaweedfs集群(上)
  • AJAX 入门到精通
  • 堆内存、栈内存、内存地址