当前位置:网站首页>ETCD containerized to build a cluster

ETCD containerized to build a cluster

2022-08-11 07:05:00 !Nine thought & & gentleman!

系列文章目录

历史文章1



前言

本文介绍使用docker搭建一个etcd集群,Comes with the corresponding build script.I strongly hope to explain the operation steps and principles in as much detail as possible,make it easier for readers to understand.


一、环境信息

使用本地的vmstation创建3个虚拟机,信息如下

节点名称节点IP节点配置操作系统Etcd版本Docker版本
etcd1192.168.82.1281c1g 20gCentOS7.4v3.513.1
etcd2192.168.82.1291c1g 20gCentOS7.4v3.513.1
etcd3192.168.82.1301c1g 20gCentOS7.4v3.513.1

说明:The server should be able to访问公网,in order to be able to download the corresponding etcd镜像

二、搭建步骤

1.Prepare preconditions

1.1 安装Docker

代码如下(示例):

# 安装docker
yum install -y docker 
# 重启docker
systemctl restart docker 
# 验证docker
docker ps

备注,需要关闭防火墙

systemctl stop firewalld.service
systemctl disable firewalld.service

1.2 拉取镜像

代码如下(示例):

# 拉取镜像
docker pull quay.io/coreos/etcd:v3.5.0  

# 验证镜像
docker images|grep etcd

2.安装Etcd

2.1 新建目录

分别在3Create a new directory on each machine /data/etcd,Used to mount into the container,能够讲etcdThe data is persisted to the local disk.需要注意的是,Reproduce the environment as much as possibleetcdThe data directory is mounted on a separate disk,磁盘的io性能越快越好.磁盘的ioThe bandwidth needs to be guaranteed as much as possible40MByte/s以上.否则etcddue to poor disk performance,Lead to constant cutting or unable to complete the foundationwal&snapshot写入,Causes the overall cluster to be abnormal

2.2 编辑脚本

Save the following commands to the script/data/start.sh,用于搭建etcd集群

代码如下(示例):

#! /bin/sh

name="etcd1"
host="192.168.92.128"
cluster="etcd1=http://192.168.92.128:2380,etcd2=http://192.168.92.129:2380,etcd3=http://192.168.92.130:2380"

docker run -d -p 2379:2379   -p 2380:2380 -v /data/etcd:/etcd-data/   --name $name --net=host  quay.io/coreos/etcd:v3.5.0   /usr/local/bin/etcd --name $name   --data-dir /data/etcd/data   --listen-client-urls http://$host:2379  --advertise-client-urls http://$host:2379 --listen-peer-urls http://$host:2380   --initial-advertise-peer-urls http://$host:2380   --initial-cluster $cluster  --initial-cluster-token tkn   --initial-cluster-state new   --log-level info   --logger zap   --log-outputs stderr

说明:when deployed on different machines,respectively replace in the scripthost和name即可.

2.3 执行部署

分别在3个节点上,Edited and tweaked the scripthost、name配置后,执行bash /data/start.sh命令,创建etcd集群.

三、结果验证

任意选一个节点,执行如下命令,Perform cluster verification,Verify that the build is complete.

代码如下(示例):

export ETCDCTL_API=3
export ETCD_ENDPOINTS=192.168.92.128:2379,192.168.92.129:2379,192.168.92.130:2379

/usr/local/bin/etcdctl --endpoints=192.168.92.128:2379 --write-out=table member list
/usr/local/bin/etcdctl --endpoints=$ETCD_ENDPOINTS --write-out=table endpoint status

注意 member listIs to record all node information in the entire cluster.It does not reflect the current running status of the cluster
endopont statusIt reflects the running status of the current cluster,需要有Leader节点,并且datasize不为0,It means that the cluster is set up normally

在这里插入图片描述

总结

If a stand-alone node is runningbash /data/start.sh后,可以通过执行docker ps -a|grep etcdVerify that the container is created.并通过docker logs ${dockerid}method to view the log

参考

原网站

版权声明
本文为[!Nine thought & & gentleman!]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/223/202208110516537238.html