惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
H
Help Net Security
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
阮一峰的网络日志
阮一峰的网络日志
Engineering at Meta
Engineering at Meta
The Register - Security
The Register - Security
U
Unit 42
Hugging Face - Blog
Hugging Face - Blog
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
IT之家
IT之家
云风的 BLOG
云风的 BLOG
腾讯CDC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
D
Docker
T
The Blog of Author Tim Ferriss
Recorded Future
Recorded Future
月光博客
月光博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
罗磊的独立博客
G
Google Developers Blog
Jina AI
Jina AI
P
Proofpoint News Feed
J
Java Code Geeks
I
InfoQ
博客园 - 司徒正美
D
DataBreaches.Net
博客园 - 叶小钗
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
Google DeepMind News
Google DeepMind News
L
LangChain Blog
博客园_首页
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - Franky
人人都是产品经理
人人都是产品经理
V
V2EX
F
Full Disclosure
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
美团技术团队
V
Visual Studio Blog

博客园 - 小得盈满

Hudi 时间旅行与增量查询的区别分析 NATS 的基本安装及使用 Doris 和 StarRocks 性能测试对比 ClickHouse 添加磁盘扩容存储 使用 Docker 部署 Elasticsearch 集群 Qdrant 单机和集群的安装方法 ClickHouse UDF 的基本用法 StarRocks 容器镜像构建 Kafka 线上性能调优 StarRocks 集群安装 Kafka 的分片和副本机制 Flink 自定义 ClickHouse Table Connector 的简单实现 Redis 性能优化实战 记一次 Go 调用系统命令出现的问题分析 APISIX proxy-cache 插件用法 etcd 历史版本回溯的方法 APISIX 简单的自定义插件开发步骤 Kafka 集群副本数量调整 使用 Docker Compose 安装 APISIX Consul 集群安装
etcd 集群安装
小得盈满 · 2023-09-24 · via 博客园 - 小得盈满

1.环境准备

下载安装包:https://github.com/etcd-io/etcd/releases/ 这里下载的安装包为:etcd-v3.5.9-linux-amd64.tar.gz,即我们当前安装的 etcd 版本为:3.5.9

这里有 3 个节点,分别为:

10.23.0.21 ec1
10.23.0.22 ec2
10.23.0.23 ec3

2.安装配置

首先在所有机器安装 etcd 如下:

tar -xvzf etcd-v3.5.9-linux-amd64.tar.gz 
cd etcd-v3.5.9-linux-amd64/
mv etcd* /usr/local/bin/
# 查看版本号
etcd --version

然后在所有机器创建 etcd 数据目录:

mkdir /data/etcd

然后为集群指定一个初始化的令牌,防止意外的跨集群交互,可以生成一个 UUID:

uuidgen

不使用 UUID 也可以使用其他字符串,只要保证唯一就好,然后我们依次前台启动 etcd 服务:

# ec1 执行
etcd --data-dir=/data/etcd --name ec1 \
    --initial-advertise-peer-urls http://10.23.0.21:2380 --listen-peer-urls http://10.23.0.21:2380 \
    --advertise-client-urls http://10.23.0.21:2379 --listen-client-urls http://10.23.0.21:2379 \
    --initial-cluster ec1= http://10.23.0.21:2380,ec2=http://10.23.0.22:2380 ,ec3=http://10.23.0.23:2380 \
    --initial-cluster-state new --initial-cluster-token c660d863-24b4-4003-ba9c-ca27cfadda1d
# ec2 执行
etcd --data-dir=/data/etcd --name ec2 \
    --initial-advertise-peer-urls http://10.23.0.22:2380 --listen-peer-urls http://10.23.0.22:2380 \
    --advertise-client-urls http://10.23.0.22:2379 --listen-client-urls http://10.23.0.22:2379 \
    --initial-cluster ec1= http://10.23.0.21:2380,ec2=http://10.23.0.22:2380 ,ec3=http://10.23.0.23:2380 \
    --initial-cluster-state new --initial-cluster-token c660d863-24b4-4003-ba9c-ca27cfadda1d
# ec3 执行
etcd --data-dir=/data/etcd --name ec3 \
    --initial-advertise-peer-urls http://10.23.0.23:2380 --listen-peer-urls http://10.23.0.23:2380 \
    --advertise-client-urls http://10.23.0.23:2379 --listen-client-urls http://10.23.0.23:2379 \
    --initial-cluster ec1= http://10.23.0.21:2380,ec2=http://10.23.0.22:2380 ,ec3=http://10.23.0.23:2380 \
    --initial-cluster-state new --initial-cluster-token c660d863-24b4-4003-ba9c-ca27cfadda1d

其中参数的含义如下:

--listen-peer-urls 监听用于节点间通信的地址和端口,默认端口是 2380

--initial-advertise-peer-urls 表示提供给对端用于节点间访问的 URL,通常和上面的一样,但是在多网卡的环境下配置可能不一样

--listen-client-urls 监听客户端服务的地址和端口,默认端口是 2379

--advertise-client-urls 表示提供给客户端来访问 etcd 服务的 URL,通常和监听的一致,但是在多网卡环境下配置可能会不同

--initial-cluster 这个是固定格式,指定集群的节点和具体访问地址,所有节点都需要指定一样的。

--initial-cluster-state 新建集群需要写 new ,如果是加入已经存在的集群要写 existing

--initial-cluster-token 这个是填写我们刚才生成的 token 即可。

所有机器都启动后,集群就启动成功了。

查看状态:

# 这里写几个地址就显示几个
etcdctl --write-out=table --endpoints=http://10.23.0.21:2379 endpoint status
# 检查节点是否健康
etcdctl --endpoints=http://10.23.0.21:2379 endpoint health
# 查看成员列表 但是有时候显示会有延迟
etcdctl --endpoints=http://10.23.0.21:2379 --write-out=table member list

为了方便运行,可以使用 systemd 进行管理,首先需要将这么多参数抽出配置文件,etcd 支持通过 --config-file 传递配置文件路径,创建配置文件:

# 所有节点都需要创建配置文件
mkdir /etc/etcd
touch /etc/etcd/etcd.yml

然后对于 ec1 的配置文件如下:

# This is the configuration file for the etcd server.

# Human-readable name for this member.
name: 'ec1'

# Path to the data directory.
data-dir: /data/etcd

# List of comma separated URLs to listen on for peer traffic.
listen-peer-urls: http://10.23.0.21:2380

# List of comma separated URLs to listen on for client traffic.
listen-client-urls: http://10.23.0.21:2379

# List of this member's peer URLs to advertise to the rest of the cluster.
# The URLs needed to be a comma-separated list.
initial-advertise-peer-urls: http://10.23.0.21:2380

# List of this member's client URLs to advertise to the public.
# The URLs needed to be a comma-separated list.
advertise-client-urls: http://10.23.0.21:2379

# Comma separated string of initial cluster configuration for bootstrapping.
# Example: initial-cluster: "infra0= http://10.0.1.10:2380,infra1=http://10.0.1.11:2380 ,infra2=http://10.0.1.12:2380"
initial-cluster: "ec1= http://10.23.0.21:2380,ec2=http://10.23.0.22:2380 ,ec3=http://10.23.0.23:2380"

# Initial cluster token for the etcd cluster during bootstrap.
initial-cluster-token: 'c660d863-24b4-4003-ba9c-ca27cfadda1d'

# Initial cluster state ('new' or 'existing').
initial-cluster-state: 'new'

基本配置就是上面这些,我们保存配置,然后所有节点都需要填写该配置文件,其中的主机名和 IP 要根据节点实际的进行修改,所有节点编辑无误保存。

然后每个机器都要创建服务文件:/etc/systemd/system/etcd.service,内容如下:

[Unit]
Description="etcd"
Requires=network-online.target
After=network-online.target

[Service]
User=root
Group=root
ExecStart=/usr/local/bin/etcd --config-file=/etc/etcd/etcd.yml
ExecReload=/bin/kill --signal HUP $MAINPID
KillMode=process
KillSignal=SIGTERM
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

所有机器都需要同步服务文件,同步之后我们手动结束掉之前阻塞的进程,然后启动服务:

# 所有节点都需要启动
systemctl start etcd.service
systemctl status etcd.service

检查服务状态都正常就可以了。

Reference:

  1. https://etcd.io/docs/v3.5/tutorials/how-to-setup-cluster/