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/

etcd 集群安装的更多相关文章

  1. centos下etcd集群安装

    先仔细了解学习etcd 官方: https://github.com/etcd-io/etcd https://www.cnblogs.com/softidea/p/6517959.html http ...

  2. ETCD集群安装实验

    目录 [1.下载二进制程序] [2.安装etcd集群] [3.查询集群状态] [4.存入读取数据] [5.注意事项] [6.参考链接] 简介:     Etcd的官网文档及其在GitHub上的文档,已 ...

  3. etcd集群安装部署

    1. 集群架构 由于我们只有两个机房,所以选择的是以上图中所示的数据同步方案, 通过做镜像的方式保证两个集群的数据实时同步. 整体架构如上图所示, 整个全局元数据中心包括两套集群,廊坊集群和马驹桥集群 ...

  4. etcd集群安装

    etcd 是一个分布式一致性k-v存储系统,可用于服务注册发现与共享配置,具有以下优点:1.简单:相比于晦涩难懂的paxos算法,etcd基于相对简单且易实现的raft算法实现一致性,并通过gRPC提 ...

  5. kubernetes 集群安装etcd集群,带证书

    install etcd 准备证书 https://www.kubernetes.org.cn/3096.html 在master1需要安装CFSSL工具,这将会用来建立 TLS certificat ...

  6. 使用docker方式安装etcd集群,带TLS证书

    网上文档也多,安装的时候,还是踩了几个坑. 现在作一个安装记录吧. 1,先作自签名的证书ca-csr.json(为了和k8s共用根证书,可能将信息调为k8s). { "CN": & ...

  7. 使用k8s operator安装和维护etcd集群

    关于Kubernetes Operator这个新生事物,可以参考下文来了解这一技术的来龙去脉: https://yq.aliyun.com/articles/685522?utm_content=g_ ...

  8. Kubernetes1.91(K8s)安装部署过程(三)--创建高可用etcd集群

    这里的etcd集群复用我们测试的3个节点,3个node都要安装并启动,注意修改配置文件 1.TLS认证文件分发:etcd集群认证用,除了本机有,分发到其他node节点 scp ca.pem kuber ...

  9. yum安装etcd集群

       前一篇文章介绍了如何yum安装简单的kubernetes集群,其中etcd是单点部署.本篇我们来搭建etcd集群,方便日后搭建kubernetes HA集群架构. 1,环境配置说明 etcd1 ...

  10. etcd简介及集群安装部署使用

    目录 1. 简介 2. Linux下载安装 3. 单机模式启动 4. 指定各集群成员的方式配置集群 5. 使用discovery service的方式配置集群 6. 集群模式下客户端命令行 7. et ...

随机推荐

  1. nginx rewrite 语法

    nginx rewrite 语法 一 定义 Rewrite主要实现url地址重写, 以及地址重定向,就是将用户请求web服 务器的地址重新定向到其他URL的过程. 二 语法格式 reweite fia ...

  2. translate speaker 翻译朗读者API - vscode 插件推荐 单词发音

    translate speaker 翻译朗读者API - vscode 插件推荐 单词发音 有个小bug,就是发音发两次,改个配置就好了. "translateSpeaker.mode&qu ...

  3. Sub-process /usr/bin/dpkg returned an error code (1)问题

    在用apt-get安装软件包的时候遇到E: Sub-process /usr/bin/dpkg returned an error code (1)问题,解决方法如下: cd /var/lib/dpk ...

  4. 基于Apollo3-Blue-MCU的智能手表方案源码解析

    一 方案简介 1.简介 Apollo3 Blue Wireless SoC是一款超低功耗无线mcu芯片,它的运行功耗降至6μA/ MHz以下.该器件采用ARM Cortex M4F内核,运行频率高达9 ...

  5. 逆向通达信Level-2 续八 (BackTrace, Trace任意TdxW.exe内部函数, Breakin)

    TdxW kun anti-debugging, i debug you without a debugger. 添加bt命令,BackTrace 下图是hack某一个函数后使用bt命令进行Trace ...

  6. java多线程的锁整理

    参考,欢迎点击原文:https://www.jianshu.com/p/473a3d96a1b0(java锁总结) https://www.jianshu.com/p/dcabdf695557(Ree ...

  7. Performance Improvements in .NET 8 -- Exceptions & Reflection & Primitives【翻译】

    Exceptions 在 .NET 6 中,ArgumentNullException 增加了一个 ThrowIfNull 方法,我们开始尝试提供"抛出助手".该方法的目的是简洁地 ...

  8. 记录--居中为什么要使用 transform?

    这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助 引言 居中是我们在前端布局中经常会遇到的问题,其中包括水平居中和垂直居中.居中的方法很多,比如说水平居中可以使用text-align: c ...

  9. linux查看资源使用情况

    linux查看资源使用情况 top -c # 查看资源使用情况 top 输出如下内容 top - 14:54:21 up 95 days, 20:03, 3 users, load average: ...

  10. java DES 加密和解密

    代码如下 import javax.crypto.Cipher; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESK ...