环境

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. 异常:必须先将 ContentLength 字节写入请求流,然后再调用 [Begin]

    异常描述 异常:必须先将 ContentLength 字节写入请求流,然后再调用 [Begin] 解决方案 //解决异常:必须先将 ContentLength 字节写入请求流,然后再调用 [Begin ...

  2. 我的Android 4 学习系列之数据库和Content Provider

    目录 创建数据库和使用SQLite 使用Content Provider.Cusor和Content Value来存储.共享和使用应用程序数据 使用Cursor Loader异步查询Content P ...

  3. 前后端分离之Web前端架构设计

    架构设计:前后端分离之Web前端架构设计 在前面的文章里我谈到了前后端分离的一些看法,这个看法是从宏观的角度来思考的,没有具体的落地实现,今天我将延续上篇文章的主题,从纯前端的架构设计角度谈谈前后端分 ...

  4. HttpRuntime详解分析

    HttpRuntime详解分析(上) 文章内容 从上章文章都知道,asp.net是运行在HttpRuntime里的,但是从CLR如何进入HttpRuntime的,可能大家都不太清晰.本章节就是通过深入 ...

  5. springmvc3.1.1+hibernate4

    上篇介绍了基本的配置,这篇着重介绍与hibernate4整合. 1.web.xml文件中加入spring-hibernate的配置.新的web.xml文件内容如下: <?xml version= ...

  6. iOS基础 - 单元测试

    单元测试(unit testing):对软件中最小可测试单元进行检查和验证.一般面向过程的语言中,基本单元为函数,面向对象的语言中,基本单元通常是类,其实对于一个手机上的app来说基本单元也可以是一个 ...

  7. 【IOS开发】SimPholders的使用

    推荐一个Xocde开发工具 “SimPholders”,能够快速访问到你的模拟器文件夹,最重要的是完全免费! 官方地址

  8. Controller 和 Action (2)

    Controller 和 Action (2) 继上一篇文章之后,本文将介绍 Controller 和 Action 的一些较高级特性,包括 Controller Factory.Action Inv ...

  9. 记关于 Lambda 表达式的基础写法

    namespace MyLambda { public delegate void Action<in T1, in T2, in T3, in T4, in T5, in T6, in T7, ...

  10. 《12个有趣的C语言问答》(4)

    C语言面试问答——<12个有趣的C语言问答>评析(4) 前文链接:http://www.cnblogs.com/pmer/p/3324063.html 8,Making changes i ...