欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 社会 > 基于Docker的ETCD分布式集群

基于Docker的ETCD分布式集群

2024/12/29 0:32:35 来源:https://blog.csdn.net/bennybi/article/details/144773843  浏览:    关键词:基于Docker的ETCD分布式集群

目录

1. 说明

2. 配置表

3. 步骤

3.1 放行端口

3.2 docker-compose 文件

         3.3 部署到3台服务器

3.4 相关命令

4. 参考 


1. 说明

- 以docker容器方式实现ETCD分布式集群,为其他项目提供支持,经过反复试验成功部署(网上资料大都过期或部署失败)

- 三个ETCD服务点供访问

2. 配置表

服务器

etcd nameip备注
center01.dev.sbetcd0172.16.20.20

硬件配置:16核32G

软件配置:ubuntu22.04 + 宝塔面板

host004.dev.sbetcd1172.16.20.63...
host004.dev.sbetcd2172.16.20.64...

3. 步骤

3.1 放行端口

分别放行 4001, 2380, 2379

3.2 docker-compose 文件

docker-compose.etcd0.yml

x-variables:flag_initial_cluster_token: &flag_initial_cluster_token '--initial-cluster-token=etcd-cluster'common_settings: &common_settingsimage: quay.io/coreos/etcd:v3.5.16entrypoint: /usr/local/bin/etcdports:- 4001:4001- 2380:2380- 2379:2379services:etcd0:container_name: etcd0restart: always<<: *common_settingscommand:- '--name=etcd0'- '--advertise-client-urls=http://172.16.20.20:2379,http://172.16.20.20:4001'- '--listen-client-urls=http://0.0.0.0:2379,http://0.0.0.0:4001'- '--initial-advertise-peer-urls=http://172.16.20.20:2380'- '--listen-peer-urls=http://0.0.0.0:2380'- '--initial-cluster=etcd0=http://172.16.20.20:2380,etcd1=http://172.16.20.63:2380,etcd2=http://172.16.20.64:2380'- '--initial-cluster-state=new'logging:driver: "json-file"options:max-size: "1m"max-file: "5"

docker-compose.etcd1.yml

x-variables:flag_initial_cluster_token: &flag_initial_cluster_token '--initial-cluster-token=etcd-cluster'common_settings: &common_settingsimage: quay.io/coreos/etcd:v3.5.16entrypoint: /usr/local/bin/etcdports:- 4001:4001- 2380:2380- 2379:2379services:etcd1:container_name: etcd1restart: always<<: *common_settingscommand:- '--name=etcd1'- '--advertise-client-urls=http://172.16.20.63:2379,http://172.16.20.63:4001'- '--listen-client-urls=http://0.0.0.0:2379,http://0.0.0.0:4001'- '--initial-advertise-peer-urls=http://172.16.20.63:2380'- '--listen-peer-urls=http://0.0.0.0:2380'- '--initial-cluster=etcd0=http://172.16.20.20:2380,etcd1=http://172.16.20.63:2380,etcd2=http://172.16.20.64:2380'- '--initial-cluster-state=new'logging:driver: "json-file"options:max-size: "1m"max-file: "5"

docker-compose.etcd2.yml

x-variables:flag_initial_cluster_token: &flag_initial_cluster_token '--initial-cluster-token=etcd-cluster'common_settings: &common_settingsimage: quay.io/coreos/etcd:v3.5.16entrypoint: /usr/local/bin/etcdports:- 4001:4001- 2380:2380- 2379:2379services:etcd2:container_name: etcd2restart: always<<: *common_settingscommand:- '--name=etcd2'- '--advertise-client-urls=http://172.16.20.64:2379,http://172.16.20.64:4001'- '--listen-client-urls=http://0.0.0.0:2379,http://0.0.0.0:4001'- '--initial-advertise-peer-urls=http://172.16.20.64:2380'- '--listen-peer-urls=http://0.0.0.0:2380'- '--initial-cluster=etcd0=http://172.16.20.20:2380,etcd1=http://172.16.20.63:2380,etcd2=http://172.16.20.64:2380'- '--initial-cluster-state=new'logging:driver: "json-file"options:max-size: "1m"max-file: "5"
 3.3 部署到3台服务器

服务拉起来:

 3.4 相关命令
# 列出节点成员
docker exec etcd0 etcdctl --write-out=table member list# 查看节点状态
docker exec etcd0 etcdctl --write-out=table endpoint status# 查看节点健康
docker exec etcd0 etcdctl --write-out=table endpoint health# 在etcd0中放入KV
docker exec etcd0 etcdctl put name ben# 在etcd1中获取
docker exec etcd1 etcdctl get name

4. 参考 

-  Running etcd under Docker | etcd

-  docker-compose-etcd/docker-compose.yml at master · guessi/docker-compose-etcd · GitHub

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com