环境

host1 10.1.99.13

host2 10.1.99.14

host3 10.1.99.15

host4 10.1.99.12(用于测试添加删除节点)

初始化集群

host1

$ docker run --restart always -d -v /usr/share/ca-certificates/:/etc/ssl/certs -p 4001:4001 -p 2380:2380 -p 2379:2379 \
--name etcd quay.io/coreos/etcd \
etcd \
--name etcd0 \
--advertise-client-urls http://10.1.99.13:2379,http://10.1.99.13:4001 \
--listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
--initial-advertise-peer-urls http://10.1.99.13:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster etcd0=http://10.1.99.13:2380,etcd1=http://10.1.99.14:2380,etcd2=http://10.1.99.15:2380 \
--initial-cluster-state new  

host2

$ docker run --restart always -d -v /usr/share/ca-certificates/:/etc/ssl/certs -p 4001:4001 -p 2380:2380 -p 2379:2379 \
--name etcd quay.io/coreos/etcd \
etcd \
--name etcd1 \
--advertise-client-urls http://10.1.99.14:2379,http://10.1.99.14:4001 \
--listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
--initial-advertise-peer-urls http://10.1.99.14:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster etcd0=http://10.1.99.13:2380,etcd1=http://10.1.99.14:2380,etcd2=http://10.1.99.15:2380 \
--initial-cluster-state new

host3

$ docker run --restart always -d -v /usr/share/ca-certificates/:/etc/ssl/certs -p 4001:4001 -p 2380:2380 -p 2379:2379 \
--name etcd quay.io/coreos/etcd \
etcd \
-name etcd2 \
--advertise-client-urls http://10.1.99.15:2379,http://10.1.99.15:4001 \
--listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
--initial-advertise-peer-urls http://10.1.99.15:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster etcd0=http://10.1.99.13:2380,etcd1=http://10.1.99.14:2380,etcd2=http://10.1.99.15:2380 \
--initial-cluster-state new

验证

#选择任意一个节点 进入 etcd shell
$ docker exec -it etcd bin/sh # 查看节点状态
$ etcdctl member list 52a25183c1fa5a39: name=etcd0 peerURLs=http://10.1.99.13:2380 clientURLs=http://10.1.99.13:2379,http://10.1.99.13:4001 isLeader=false
69aa775a244f2954: name=etcd1 peerURLs=http://10.1.99.14:2380 clientURLs=http://10.1.99.14:2379,http://10.1.99.14:4001 isLeader=true
f18991cb367747f3: name=etcd2 peerURLs=http://10.1.99.15:2380 clientURLs=http://10.1.99.15:2379,http://10.1.99.15:4001 isLeader=false #查看集群状态
etcdctl cluster-health member 52a25183c1fa5a39 is healthy: got healthy result from http://10.1.99.13:2379
member 69aa775a244f2954 is healthy: got healthy result from http://10.1.99.14:2379
member f18991cb367747f3 is healthy: got healthy result from http://10.1.99.15:2379
cluster is healthy #插入一条记录
$ etcdctl set /home/etcdtest value
value
#读取插入记录 在其他节点执行获取到相同结果
$ etcdctl get /home/etcdtest
value

集群管理在集群中加入一个节点

#在现有的集群中执行以下命令
$ etcdctl member add etcd3 http://10.1.99.12:2380 Added member named etcd3 with ID 7b33d7070ed90c25 to cluster ETCD_NAME="etcd3"
ETCD_INITIAL_CLUSTER="etcd0=http://10.1.99.13:2380,etcd1=http://10.1.99.14:2380,etcd3=http://10.1.99.12:2380,etcd2=http://10.1.99.15:2380"
ETCD_INITIAL_CLUSTER_STATE="existing" #在对应的待加入的节点上
$ docker run --restart always -d -v /usr/share/ca-certificates/:/etc/ssl/certs -p : -p : -p : \
--name etcd quay.io/coreos/etcd \
etcd \
--name etcd3 \
--advertise-client-urls http://10.1.99.12:2379,http://10.1.99.12:4001 \
--listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
--initial-advertise-peer-urls http://10.1.99.12:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--initial-cluster-token etcd-cluster- \
--initial-cluster etcd0=http://10.1.99.13:2380,etcd1=http://10.1.99.14:2380,etcd3=http://10.1.99.12:2380,etcd2=http://10.1.99.15:2380 \
--initial-cluster-state existing
注意事项:
使用上面生成的配置内容分别修改对应的属性
设置 --initial-cluster-state existing 删除节点,
#在现有的集群中执行以下命令
#显示当前集群中的所用节点信息
$ etcdctl member list
52a25183c1fa5a39: name=etcd0 peerURLs=http://10.1.99.13:2380 clientURLs=http://10.1.99.13:2379,http://10.1.99.13:4001 isLeader=false
69aa775a244f2954: name=etcd1 peerURLs=http://10.1.99.14:2380 clientURLs=http://10.1.99.14:2379,http://10.1.99.14:4001 isLeader=true
7b33d7070ed90c25: name=etcd3 peerURLs=http://10.1.99.12:2380 clientURLs=http://10.1.99.12:2379,http://10.1.99.12:4001 isLeader=false
f18991cb367747f3: name=etcd2 peerURLs=http://10.1.99.15:2380 clientURLs=http://10.1.99.15:2379,http://10.1.99.15:4001 isLeader=false #在集群中剔除待删除节点
$ etcdctl member remove 7b33d7070ed90c25

Docker 搭建 etcd 集群及管理的更多相关文章

  1. Docker 搭建 etcd 集群

    阅读目录: 主机安装 集群搭建 API 操作 API 说明和 etcdctl 命令说明 etcd 是 CoreOS 团队发起的一个开源项目(Go 语言,其实很多这类项目都是 Go 语言实现的,只能说很 ...

  2. docker搭建etcd集群环境

    其实关于集群网上说的方案已经很多了,尤其是官网,只是这里我个人只有一个虚拟机,在开发环境下建议用docker-compose来搭建etcd集群. 1.拉取etcd镜像 docker pull quay ...

  3. Docker 搭建 etcd 集群配置

    #关闭selinux.防火墙 systemctl stop firewalld.service systemctl disable firewalld.service firewall-cmd --s ...

  4. 庐山真面目之十二微服务架构基于Docker搭建Consul集群、Ocelot网关集群和IdentityServer版本实现

    庐山真面目之十二微服务架构基于Docker搭建Consul集群.Ocelot网关集群和IdentityServer版本实现 一.简介      在第七篇文章<庐山真面目之七微服务架构Consul ...

  5. Docker搭建RabbitMQ集群

    Docker搭建RabbitMQ集群 Docker安装 见官网 RabbitMQ镜像下载及配置 见此博文 集群搭建 首先,我们需要启动运行RabbitMQ docker run -d --hostna ...

  6. 搭建etcd集群

    一 介绍 etcd 高可用一致性键值存储系统,使用Raft一直算法处理日志复制以保证数据一致性.主要在搭建kubernates时关注到etcd来研究部署etcd.使用golang语言编写,和zooke ...

  7. docker 搭建zookeeper集群和kafka集群

    docker 搭建zookeeper集群 安装docker-compose容器编排工具 Compose介绍 Docker Compose 是 Docker 官方编排(Orchestration)项目之 ...

  8. Docker搭建PXC集群

    如何创建MySQL的PXC集群 下载PXC集群镜像文件 下载 docker pull percona/percona-xtradb-cluster 重命名 [root@hongshaorou ~]# ...

  9. 使用docker配置etcd集群

    docker配置etcd集群与直接部署etcd集群在配置上并没有什么太大差别. 我这里直接使用docker-compose来实现容器化的etcd部署 环境如下: HostName IP etcd1 1 ...

随机推荐

  1. 常用Jquery插件整理大全

    做项目的时候总是少不了要用到Jquery插件,但是Jquery插件有太多,每次都要花费一些时间,因此本人就抽时间整理了一些Jquery插件,每个插件都有Demo或者是使用文档供大家下载.整理了一晚上才 ...

  2. 制作iis自动安装包

    原文:制作iis自动安装包 MS 一直没有提供可独立安装的 IIS 安装包,Windows 的缺省安装没有安装它,通常要到控制面板的"添加/删除 Windows 程序"中去选择安装 ...

  3. sql常用语句汇总

    --创建数据库 USE yuju CREATE database YuJu on primary ( name='YuJu', filename='B:\ceshi数据库\YuJu.mdf', max ...

  4. gof设计模式回顾

    gof23根据讲师学习笔记回顾: 1.gof:Gang of Four;叫grasp更具有针对性,解决具体的问题; ---------------------总共分为三大类: ---------创建型 ...

  5. Mvc的多层架构

    分享一个Mvc的多层架构,欢迎大家拍砖斧正   多层架构是什么? 多层架构是开发人员在开发过程当中面对复杂且易变的需求采取的一种以隔离控制为主的应对策略,关于多层架构的标准,我认为有一句话是比较有代表 ...

  6. 博客加上“Fork me on Github”彩带

    给你的博客加上“Fork me on Github”彩带 起 如今,随着Git的大热以及Github的优越性,许多知名开源项目都将源代码托管到Github上了.在Github上不仅可以托管自己的开源项 ...

  7. SZU:B54 Dual Palindromes

    Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Number Only Ju ...

  8. Struts2的拦截器

    拦截器的作用: 拦截器可以动态地拦截发送到指定Action的请求,通过拦截器机制,可以载Action执行的前后插入某些代码,植入我们的逻辑思维. 拦截器的实现原理: 拦截器通过代理的方式来调用,通过动 ...

  9. C#socket通信1

    .net平台下C#socket通信(上) 完全是基础,新手可以随意看看,大牛可以关闭浏览页了,哈哈. 在开始介绍socket前先补充补充基础知识,在此基础上理解网络通信才会顺理成章,当然有基础的可以跳 ...

  10. ASP.NET WebAPI HTTPS

    参照文档 http://southworks.com/blog/2014/06/16/enabling-ssl-client-certificates-in-asp-net-web-api/   第一 ...