首页 > 其他分享 >etcd 集群安装

etcd 集群安装

时间:2023-09-24 21:24:06浏览次数:39  
标签:10.23 http -- initial 2380 集群 etcd 安装

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/

标签:10.23,http,--,initial,2380,集群,etcd,安装
From: https://www.cnblogs.com/freeweb/p/17726690.html

相关文章

  • kubepi加入集群,生成token
    防丢失https://www.cnblogs.com/Chinori/p/17506348.html kubectlcreatesakubepi-user--namespacekube-systemkubectlcreateclusterrolebindingkubepi-user--clusterrole=cluster-admin--serviceaccount=kube-system:kubepi-userkubectl-nkube-systemcreatetoke......
  • kingbaseES单机安装
    测试环境地址系统版本架构168.3.1.212rhel7.6v8.6单实例测试步骤关闭防火墙和selinuxsystemctlstopfirewalldsystemctldisablefirewalldsed-i's/SELINUX=enforcing/SELINUX=disabled/g'/etc/selinux/config修改系统内核cat>>/etc/sysctl.conf<<eofkernel.shmmax=......
  • kingbaseES读写分离集群搭建
    测试环境 IPVIPOSDB主库168.3.1.212168.3.1.214rhel7.6KingbaseESV008R006C007B0012备库168.3.1.213168.3.1.214rhel7.6KingbaseESV008R006C007B0012测试记录1.操作系统配置该步骤主库和备库都必须执行.systemctlstopfirewalldsystemctldisablefirewalldsed-i's/SEL......
  • ZooKeeper集群搭建
    ZooKeeper是一个分布式服务框架,它主要是用来解决分布式应用中经常遇到的一些数据管理问题,如:命名服务、状态同步、配置中心、集群管理等。消费者模型0生产者启动1生产者注册至zookeeper(生产者的代码启动)2消费者启动并订阅频道(消费者往那个频道注册的就会到那个频道去......
  • tesseract-ocr下载安装与配置
    tesseract-ocr下载安装与配置 1:下载地址:https://digi.bib.uni-mannheim.de/tesseract/......
  • Consul 集群安装
    1.介绍Consul是一款服务网络平台,主要实现服务注册、服务发现、服务网格、服务网关、安全网络以及配置管理等多类服务,非常适合做为微服务架构的底层网络平台。配置中心其实就是一个KV存储,我们如果做配置中心的话其实主要就是用KV存储部分,但是为了以后的可扩展性,我们可能会使......
  • 用其它路径的pip安装包
    D:\ProgramData\Anaconda3\python.exe-mpipinstall--upgradepip(base)C:\WINDOWS\system32>D:\ProgramData\Anaconda3\python.exe-mpipinstall--upgradepipRequirementalreadysatisfied:pipind:\programdata\anaconda3\lib\site-packages(22......
  • linux yum 无法安装程序
    因为系统需要更新首先,进入到yum的repos目录cd/etc/yum.repos.d/ ......
  • 网络分析利器:在 Ubuntu 16.04 上安装 Bro
    Bro是一个开源的网络分析框架,侧重于网络安全监控。这是一项长达15年的研究成果,被各大学、研究实验室、超级计算机中心和许多开放科学界广泛使用。它主要由伯克利国际计算机科学研究所和伊利诺伊大学厄巴纳-香槟分校的国家超级计算机应用中心开发。Bro的功能包括:Bro的脚本语言......
  • 麒麟桌面操作系统安装软件
    方法一:1、双击安装包2、点击“一键安装”3、输入管理员密码4、安装中5、安装完成方法二:1、右键点击桌面,选择“打开终端”2、输入“sudodpkg-i软件包名”,输入管理员密码进行安装方法三:1、点击“开始菜单”,点击“软件商店”2、搜索框搜索软件名称,点击下载3、安装中4、安装完成点......