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

推荐订阅源

量子位
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Schneier on Security
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
C
Cybersecurity and Infrastructure Security Agency CISA
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
T
Threat Research - Cisco Blogs
C
Cisco Blogs
Recent Announcements
Recent Announcements
S
Securelist
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
P
Privacy & Cybersecurity Law Blog
宝玉的分享
宝玉的分享
D
Darknet – Hacking Tools, Hacker News & Cyber Security
L
LINUX DO - 热门话题
T
Tor Project blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
月光博客
月光博客
AWS News Blog
AWS News Blog
P
Proofpoint News Feed
博客园 - 司徒正美
L
LINUX DO - 最新话题
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
H
Help Net Security
Spread Privacy
Spread Privacy
PCI Perspectives
PCI Perspectives
Project Zero
Project Zero
I
Intezer
T
The Blog of Author Tim Ferriss
有赞技术团队
有赞技术团队
The Last Watchdog
The Last Watchdog
C
Check Point Blog
Blog — PlanetScale
Blog — PlanetScale
B
Blog RSS Feed
MyScale Blog
MyScale Blog
V
Vulnerabilities – Threatpost
Recorded Future
Recorded Future
T
Tenable Blog
Jina AI
Jina AI
D
DataBreaches.Net
阮一峰的网络日志
阮一峰的网络日志

博客园 - 小得盈满

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/