docker如何部署etcd集群
更新时间:2023年3月17日 13:59 点击:18 作者:AlexClownfish
需要安装:
docker
docker-compose
参数详细:
–name
:设置成员节点的别名,建议为每个成员节点配置可识别的命名–advertise-client-urls
:广播到集群中本成员的监听客户端请求的地址–initial-advertise-peer-urls
:广播到集群中本成员的Peer监听通信地址–listen-client-urls
:客户端请求的监听地址列表–listen-peer-urls
:Peer消息的监听服务地址列表–initial-cluster-token
:启动集群的时候指定集群口令,只有相同token的几点才能加入到同一集群–initial-cluster
:所有集群节点的地址列表–initial-cluster-state
:初始化集群状态,默认为new,也可以指定为exi-string表示要加入到一个已有集群
创建etcd数据目录
mkdir -p ./etcd-node{1,2,3}
创建docker网络
docker network create --driver bridge --subnet 172.62.0.0/16 --gateway 172.62.0.1 etcd-cluster
etcd-cluster-compose.yml
version: '3' networks: etcd-cluster: external: true services: etcd-node1: image: quay.io/coreos/etcd:v3.3.1 container_name: etcd-node1 ports: - "12379:2379" - "12380:2380" restart: always volumes: - ./etcd-node1:/data/app/etcd command: etcd --name etcd-node1 --data-dir /data/app/etcd/ --advertise-client-urls http://172.62.0.10:2379 --initial-advertise-peer-urls http://172.62.0.10:2380 --listen-client-urls http://0.0.0.0:2379 --listen-peer-urls http://0.0.0.0:2380 --initial-cluster-token etcd-cluster --initial-cluster "etcd-node1=http://172.62.0.10:2380,etcd-node2=http://172.62.0.11:2380,etcd-node3=http://172.62.0.12:2380" --initial-cluster-state new networks: etcd-cluster: ipv4_address: 172.62.0.10 etcd-node2: image: quay.io/coreos/etcd:v3.3.1 container_name: etcd-node2 ports: - "22379:2379" - "22380:2380" restart: always volumes: - ./etcd-node2:/data/app/etcd command: etcd --name etcd-node2 --data-dir /data/app/etcd/ --advertise-client-urls http://172.62.0.11:2379 --initial-advertise-peer-urls http://172.62.0.11:2380 --listen-client-urls http://0.0.0.0:2379 --listen-peer-urls http://0.0.0.0:2380 --initial-cluster-token etcd-cluster --initial-cluster "etcd-node1=http://172.62.0.10:2380,etcd-node2=http://172.62.0.11:2380,etcd-node3=http://172.62.0.12:2380" --initial-cluster-state new networks: etcd-cluster: ipv4_address: 172.62.0.11 etcd-node3: image: quay.io/coreos/etcd:v3.3.1 container_name: etcd-node3 ports: - "32379:2379" - "32380:2380" restart: always volumes: - ./etcd-node3:/data/app/etcd command: etcd --name etcd-node3 --data-dir /data/app/etcd/ --advertise-client-urls http://172.62.0.12:2379 --initial-advertise-peer-urls http://172.62.0.12:2380 --listen-client-urls http://0.0.0.0:2379 --listen-peer-urls http://0.0.0.0:2380 --initial-cluster-token etcd-cluster --initial-cluster "etcd-node1=http://172.62.0.10:2380,etcd-node2=http://172.62.0.11:2380,etcd-node3=http://172.62.0.12:2380" --initial-cluster-state new networks: etcd-cluster: ipv4_address: 172.62.0.12
启动并验证集群
启动
[root@k8s-node1 etcd-cluster]# docker-compose -f etcd-cluster-compose.yml up -d Pulling etcd-node1 (quay.io/coreos/etcd:v3.3.1)... v3.3.1: Pulling from coreos/etcd ff3a5c916c92: Pull complete dec5fcc85a18: Pull complete 3944f16f0112: Pull complete 0b6d29b049fe: Pull complete d8c39ae91d38: Pull complete 42fcea4864ba: Pull complete Digest: sha256:454e69370d87554dcb4272833b8f07ce1b5d457caa153bda4070b76d89a1cc97 Status: Downloaded newer image for quay.io/coreos/etcd:v3.3.1 Creating etcd-node1 ... done Creating etcd-node2 ... done Creating etcd-node3 ... done
[root@k8s-node1 etcd-cluster]# docker-compose -f etcd-cluster-compose.yml ps -a Name Command State Ports ------------------------------------------------------------------------------------------------------ etcd-node1 etcd --name etcd-node1 --d ... Up 0.0.0.0:12379->2379/tcp, 0.0.0.0:12380->2380/tcp etcd-node2 etcd --name etcd-node2 --d ... Up 0.0.0.0:22379->2379/tcp, 0.0.0.0:22380->2380/tcp etcd-node3 etcd --name etcd-node3 --d ... Up 0.0.0.0:32379->2379/tcp, 0.0.0.0:32380->2380/tcp
验证集群
通过etcdctl member list命令可以查询出所有集群节点的列表并且结果一致即为成功
[root@k8s-node1 etcd-cluster]# docker exec -it etcd-node1 /bin/sh / # etcdctl member list 8cef47d732d4acff: name=etcd-node1 peerURLs=http://172.62.0.10:2380 clientURLs=http://172.62.0.10:2379 isLeader=false c93af917b643516f: name=etcd-node3 peerURLs=http://172.62.0.12:2380 clientURLs=http://172.62.0.12:2379 isLeader=true cdee7114ad135065: name=etcd-node2 peerURLs=http://172.62.0.11:2380 clientURLs=http://172.62.0.11:2379 isLeader=false / # exit [root@k8s-node1 etcd-cluster]# docker exec -it etcd-node2 /bin/sh / # etcdctl member list 8cef47d732d4acff: name=etcd-node1 peerURLs=http://172.62.0.10:2380 clientURLs=http://172.62.0.10:2379 isLeader=false c93af917b643516f: name=etcd-node3 peerURLs=http://172.62.0.12:2380 clientURLs=http://172.62.0.12:2379 isLeader=true cdee7114ad135065: name=etcd-node2 peerURLs=http://172.62.0.11:2380 clientURLs=http://172.62.0.11:2379 isLeader=false [root@k8s-node1 etcd-cluster]# docker exec -it etcd-node3 /bin/sh / # etcdctl member list 8cef47d732d4acff: name=etcd-node1 peerURLs=http://172.62.0.10:2380 clientURLs=http://172.62.0.10:2379 isLeader=false c93af917b643516f: name=etcd-node3 peerURLs=http://172.62.0.12:2380 clientURLs=http://172.62.0.12:2379 isLeader=true cdee7114ad135065: name=etcd-node2 peerURLs=http://172.62.0.11:2380 clientURLs=http://172.62.0.11:2379 isLeader=false
k/v操作
CURL
新增
[root@k8s-node1 etcd-cluster]# docker-compose -f etcd-cluster-compose.yml ps -a Name Command State Ports ------------------------------------------------------------------------------------------------------ etcd-node1 etcd --name etcd-node1 --d ... Up 0.0.0.0:12379->2379/tcp, 0.0.0.0:12380->2380/tcp etcd-node2 etcd --name etcd-node2 --d ... Up 0.0.0.0:22379->2379/tcp, 0.0.0.0:22380->2380/tcp etcd-node3 etcd --name etcd-node3 --d ... Up 0.0.0.0:32379->2379/tcp, 0.0.0.0:32380->2380/tcp [root@k8s-node1 etcd-cluster]# curl -L http://127.0.0.1:12379/version {"etcdserver":"3.3.1","etcdcluster":"3.3.0"}[root@k8s-node1 etcd-cluster]# [root@k8s-node1 etcd-cluster]# curl -L http://127.0.0.1:12379/v2/keys/Alexclownfish -X PUT -d value=https://blog.alexcld.com {"action":"set","node":{"key":"/Alexclownfish","value":"https://blog.alexcld.com","modifiedIndex":19,"createdIndex":19}}
查询
[root@k8s-node1 etcd-cluster]# curl -L http://127.0.0.1:12379/v2/keys/Alexclownfish -X GET {"action":"get","node":{"key":"/Alexclownfish","value":"https://blog.alexcld.com","modifiedIndex":19,"createdIndex":19}} [root@k8s-node1 etcd-cluster]# curl -L http://127.0.0.1:22379/v2/keys/Alexclownfish -X GET {"action":"get","node":{"key":"/Alexclownfish","value":"https://blog.alexcld.com","modifiedIndex":19,"createdIndex":19}} [root@k8s-node1 etcd-cluster]# curl -L http://127.0.0.1:32379/v2/keys/Alexclownfish -X GET {"action":"get","node":{"key":"/Alexclownfish","value":"https://blog.alexcld.com","modifiedIndex":19,"createdIndex":19}}
修改
同新建一样
删除
[root@k8s-node1 etcd-cluster]# curl -L http://127.0.0.1:12379/v2/keys/Alexclownfish -X DELETE {"action":"delete","node":{"key":"/Alexclownfish","modifiedIndex":20,"createdIndex":19},"prevNode":{"key":"/Alexclownfish","value":"https://blog.alexcld.com","modifiedIndex":19,"createdIndex":19}} [root@k8s-node1 etcd-cluster]# curl -L http://127.0.0.1:12379/v2/keys/Alexclownfish -X GET {"errorCode":100,"message":"Key not found","cause":"/Alexclownfish","index":20}
etcdctl
新增
/ # etcdctl set clownfish 1234567 1234567 / # etcdctl get clownfish 1234567
查询
/ # etcdctl get clownfish 1234567
修改
/ # etcdctl get clownfish 1234567 / # etcdctl set clownfish 987654321ddd 987654321ddd / # etcdctl get clownfish 987654321ddd
删除
/ # etcdctl rm clownfish PrevNode.Value: 987654321ddd / # etcdctl get clownfish Error: 100: Key not found (/clownfish) [23]
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持猪先飞。
原文出处:https://blog.csdn.net/weixin_45509582/article/details/129492
下一篇: 返回列表
相关文章
- 这篇文章主要介绍了zabbix v3.0安装部署全过程,文中通过一步步的步骤和图文介绍的非常详细,相信对大家具有一定的参考价值,需要的朋友们下面来一起看看吧。...2021-05-07
- 以下就是部署PHP时的4个配置修改说明,大家一个一个进行学习研究。1、short_open_tag 是什么呢? 决定是否允许使用代码开始标志的缩写形式(<? ?> )。如果要和 XML 结合使用PHP,可以禁用此选项以便于嵌入使用<?x...2015-10-21
解决Docker中的error during connect异常情况
这篇文章主要介绍了解决Docker中的error during connect异常情况,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-22- 这篇文章主要介绍了docker部署confluence的完整步骤,这里的镜像并不是小编自己写的是基于他人打包的文中有详细介绍,需要的朋友可以参考下...2021-06-11
- 这篇文章主要介绍了教你如何用Jenkins自动化部署项目(从零到搭建完成),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-10-08
docker 启动elasticsearch镜像,挂载目录后报错的解决
这篇文章主要介绍了docker 启动 elasticsearch镜像,挂载目录后报错的解决,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-20- 通过本文可以帮助大家快速学习Docker安装ElasticSearch的过程,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧...2021-08-31
- 这篇文章主要介绍了docker swarm外部验证负载均衡时不生效的问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-04-27
- 这篇文章主要介绍了在docker中执行linux shell命令的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-30
- 这篇文章主要给大家介绍了关于docker容器与宿主机的数据交互,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-11-09
idea配置springboot热部署终极解决办法(解决热部署失效问题)
这篇文章主要介绍了idea配置springboot热部署终极解决办法(解决热部署失效问题),本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧...2020-07-22详解如何使用Docker部署Django+MySQL8开发环境
这篇文章主要介绍了详解如何使用Docker部署Django+MySQL8开发环境,文中通过示例代码以及图文介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧...2020-07-19安装Docker Desktop报错WSL 2 installation is incomplete的问题(解决报错)
这篇文章主要介绍了安装Docker Desktop报错WSL 2 installation is incomplete的问题,解决方法很简单只需我们自己手动更新一下,我们根据提示去微软官网下载最新版的wsl2安装后即可正常打开,需要的朋友可以参考下...2021-06-13- 这篇文章主要介绍了Tomcat首次部署web项目流程图解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-12-11
- 这篇文章主要介绍了Docker部署Rancher的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-06
使用rpm安装指定版本docker(1.12.6)的详细步骤
为了防止安装高版本的docker引发的错误,需要安装1.12.6版本的docker,下面小编给大家带来了使用rpm安装指定版本的docker(1.12.6)的步骤,感兴趣的朋友一起看看吧...2021-08-11- 这篇文章主要介绍了docker端口映射及外部无法访问问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-19
- Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程,本文给大家分享一个入门案例使用Springboot1.5.9搭建,具体配置部署过程跟随小编一起看看吧...2021-07-12
- Zookeeper是一个针对大型分布式系统的可靠协调系统,提供的功能包括:配置维护、名字服务、分布式同步、组服务等,这篇文章主要介绍了ZooKeeper的安装及部署,需要的朋友可以参考下...2020-06-25
- 现在很多开发者都使用Vagrant来管理他们的虚拟机开发环境,Vagrant确实很酷, 不过也有不少缺点(最主要的是它占用太多的资源)。在容器技术、Docker和更多类Docker技术出现后,解决这个问题就变得简单了。这篇文章主要介绍了Docker配置PHP开发环境,下面来一起看看吧。...2017-01-08