etcd是一个高可用的键值存储系统,主要用于共享配置和服务发现。etcd是由CoreOS开发并维护的,灵感来自于 ZooKeeper 和 Doozer,它使用Go语言编写,并通过Raft一致性算法处理日志复制以保证强一致性。Raft是一个来自Stanford的新的一致性算法,适用于分布式系统的日志复制,Raft通过选举的方式来实现一致性,在Raft中,任何一个节点都可能成为Leader。Google的容器集群管理系统Kubernetes、开源PaaS平台Cloud Foundry和CoreOS的Fleet都广泛使用了etcd。etcd的特性如下:

    简单: curl可访问的用户的API(HTTP+JSON)

    安全: 可选的SSL客户端证书认证

    快速: 单实例每秒 1000 次写操作

    可靠: 使用Raft保证一致性

  本次搭建的基础环境:

底层OS:Centos7
docker版本:1.8.-el7.centos
IP:
服务器A:192.168.7.168
服务器B:192.168.7.170
服务器C:192.168.7.172

  首先在各个服务器上下载最新的etcd镜像

# docker pull quay.io/coreos/etcd

接下来我采用了两种方式来创建集群:1、将三个服务器挨个添加进集群;2、将三个服务器统一添加进集群。以下命令标注A的代表在A机器上执行,同理B、C。

1、将服务器挨个添加进集群

  A  在服务器A上运行一个ETCD实例,取名为qf2200-client0,注意其状态为new,“-initial-cluster”中只有自己的IP

# docker run -d -p : -p : --name etcd quay.io/coreos/etcd -name qf2200-client0 -advertise-client-urls http://192.168.7.168:2379 -listen-client-urls http://0.0.0.0:2379 -initial-advertise-peer-urls http://192.168.7.168:2380 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "qf2200-client0=http://192.168.7.168:2380" -initial-cluster-state new

  

  A  在服务器A的ETCD服务上,通过调用API添加一个新的节点:192.168.7.170

# curl http://127.0.0.1:2379/v2/members -XPOST -H "Content-Type: application/json" -d '{"peerURLs": ["http://192.168.7.170:2380"]}'

  

  B  在服务器B上运行一个ETCD实例,取名为qf2200-client1,注意其状态为existing,“-initial-cluster”中有前一个IP及自己的IP

# docker run -d -p : -p : --name etcd quay.io/coreos/etcd -name qf2200-client1 -advertise-client-urls http://192.168.7.170:2379 -listen-client-urls http://0.0.0.0:2379 -initial-advertise-peer-urls http://192.168.7.170:2380 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "qf2200-client0=http://192.168.7.168:2380,qf2200-client1=http://192.168.7.170:2380" -initial-cluster-state existing

  

  A  在服务器A的ETCD服务上,通过调用API添加一个新的节点:192.168.7.172

# curl http://127.0.0.1:2379/v2/members -XPOST -H "Content-Type: application/json" -d '{"peerURLs": ["http://192.168.7.172:2380"]}'

  

  C 在服务器C上运行一个ETCD实例,取名为qf2200-client2,注意其状态为existing,“-initial-cluster”中有之前所有节点的IP及自己的IP

# docker run -d -p : -p : --name etcd quay.io/coreos/etcd -name qf2200-client2 -advertise-client-urls http://192.168.7.172:2379 -listen-client-urls http://0.0.0.0:2379 -initial-advertise-peer-urls http://192.168.7.172:2380 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "qf2200-client0=http://192.168.7.168:2380,qf2200-client1=http://192.168.7.170:2380,qf2200-client2=http://192.168.7.172:2380" -initial-cluster-state existing

2、将服务器统一添加进集群(“-initial-cluster”中包含所有节点的IP,状态均为new)

  A上执行

# docker run -d -p : -p : --restart=always --log-driver=none --name etcd quay.io/coreos/etcd -name qf2200-client0 -advertise-client-urls http://192.168.7.168:2379 -listen-client-urls http://0.0.0.0:2379 -initial-advertise-peer-urls http://192.168.7.168:2380 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "qf2200-client0=http://192.168.7.168:2380,qf2200-client1=http://192.168.7.170:2380,qf2200-client2=http://192.168.7.172:2380" -initial-cluster-state new

  

  B上执行

# docker run -d -p : -p : --restart=always --log-driver=none --name etcd quay.io/coreos/etcd -name qf2200-client1 -advertise-client-urls http://192.168.7.170:2379 -listen-client-urls http://0.0.0.0:2379 -initial-advertise-peer-urls http://192.168.7.170:2380 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "qf2200-client0=http://192.168.7.168:2380,qf2200-client1=http://192.168.7.170:2380,qf2200-client2=http://192.168.7.172:2380" -initial-cluster-state new

  

  C上执行

# docker run -d -p : -p : --restart=always --log-driver=none --name etcd quay.io/coreos/etcd -name qf2200-client2 -advertise-client-urls http://192.168.7.172:2379 -listen-client-urls http://0.0.0.0:2379 -initial-advertise-peer-urls http://192.168.7.172:2380 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "qf2200-client0=http://192.168.7.168:2380,qf2200-client1=http://192.168.7.170:2380,qf2200-client2=http://192.168.7.172:2380" -initial-cluster-state new

集群验证。两种方法创建的集群可通过以下方式进行验证

  1、验证集群members。在集群中的每台机器上查看members,得出的结果应该是相同的

[root@localhost ~]# curl -L http://127.0.0.1:2379/v2/members
{"members":[{"id":"1a661f2b9997ba39","name":"qf2200-client0","peerURLs":["http://192.168.7.168:2380"],"clientURLs":["http://192.168.7.168:2379"]},{"id":"4932c8ea462e079c","name":"qf2200-client2","peerURLs":["http://192.168.7.172:2380"],"clientURLs":["http://192.168.7.172:2379"]},{"id":"c1dbdde07e61741e","name":"qf2200-client1","peerURLs":["http://192.168.7.170:2380"],"clientURLs":["http://192.168.7.170:2379"]}]}

  2、某台机器上添加数据,其他机器上查看数据,得出的结果应该是相同的
  A上执行

[root@localhost ~]# curl -L http://127.0.0.1:2379/v2/keys/message -XPUT -d value="Hello zhenyuyaodidiao"
{"action":"set","node":{"key":"/message","value":"Hello zhenyuyaodidiao","modifiedIndex":,"createdIndex":},"prevNode":{"key":"/message","value":"Hello world1","modifiedIndex":,"createdIndex":}}

  

  B、C上执行

[root@localhost ~]#  curl -L http://127.0.0.1:2379/v2/keys/message
{"action":"get","node":{"key":"/message","value":"Hello zhenyuyaodidiao","modifiedIndex":,"createdIndex":}}

quay.io/coreos/etcd 基于Docker镜像的集群搭建的更多相关文章

  1. 基于Docker的redis集群搭建

    Redis集群官方介绍:http://www.redis.cn/topics/cluster-tutorial.html 基于Docker搭建Redis集群 环境:6个节点,三主三从 制作Redis镜 ...

  2. 基于docker安装pxc集群

    基于docker安装pxc集群 一.PXC 集群的安装 PXC集群比较特殊,需要安装在 linux 或 Docker 之上.这里使用 Docker进行安装! Docker的镜像仓库中包含了 PXC数据 ...

  3. 基于zookeeper的Swarm集群搭建

    简介 Swarm:docker原生的集群管理工具,将一组docker主机作为一个虚拟的docker主机来管理. 对客户端而言,Swarm集群就像是另一台普通的docker主机. Swarm集群中的每台 ...

  4. Docker Swarm redis 集群搭建

    Docker Swarm redis 集群搭建 环境1: 系统:Linux Centos 7.4 x64 内核:Linux docker 3.10.0-693.2.2.el7.x86_64 Docke ...

  5. 基于centos6.5 hbase 集群搭建

    注意本章内容是在上一篇文章“基于centos6.5 hadoop 集群搭建”基础上创建的 1.上传hbase安装包 hbase-0.96.2-hadoop2 我的目录存放在/usr/hadoop/hb ...

  6. docker实验--redis集群搭建

    背景介绍: 我经常在做一些小项目的时候,采用了Redis来做缓存,但是都是基于单节点的,一旦redis挂了,整个项目就挂了.于是乎,想到了多节点集群的方式来使用,就开始折腾着怎么去搭建这个集群.在网上 ...

  7. etcd v3版本生产级集群搭建以及实现一键启动脚本

    本专栏的上一篇文章写了<长篇图解etcd核心应用场景及编码实战>,本文继续.后续计划章节内容如下: <长篇图解etcd核心应用场景及编码实战> <搭建高可用etcd集群& ...

  8. docker redis4.0集群搭建

    一.前言 redis集群对于很多人来说非常熟悉,在前些日子,我也有一位大兄弟也发布过一篇关于在阿里云(centOS7)上搭建redis 集群的文章,虽然集群搭建的文章在网上很多,我比较喜欢这篇文章的地 ...

  9. Tomcat:基于Apache+Tomcat的集群搭建

    根据Tomcat的官方文档说明可以知道,使用Tomcat配置集群需要与其它Web Server配合使用才可以完成,典型的有Apache和IIS. 这里就使用Apache+Tomcat方式来完成基于To ...

随机推荐

  1. 【android studio】解决android studio drawable新建项目时只有一个drawable目录的问题

    概述 android studio默认新建Module时,只新建一个drawable目录,并不会新建适配不同分辨率的drawable目录.但其实,这是可以设置的.有以下两种方法: 方法1 详细步骤 进 ...

  2. Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds 解决方法

    Server Tomcat v6.0 Server at localhost was unable to start within 45 seconds. If the server requires ...

  3. hadoop Error: JAVA_HOME is not set and could not be found.

    Hadoop安装完后,启动时报Error: JAVA_HOME is not set and could not be found.解决办法:        修改/etc/hadoop/hadoop- ...

  4. QQ中打开链接不是默认浏览器

    电脑上装了搜狗和Chrome,Chrome为默认浏览器.但QQ中不论点什么都是以搜狗打开,解决办法: 1.设置, 2. 安全设置-->安全推荐-->使用搜狗打开链接增强安全性.去掉勾勾就行 ...

  5. HTML静态网页 Window.document对象

    一.找到元素: docunment.getElementById("id"):根据id找,最多找一个:    var a =docunment.getElementById(&qu ...

  6. Greenplum 集群部署

    最近开始接触Greenplum,线上也在使用了,感觉还不错,本次介绍一下集群的部署方法.那么Greenplum的架构如下: (架构图来源网络) 简单来说GPDB是一个分布式数据库软件,其可以管理和处理 ...

  7. ACM Binary String Match

    #include <stdio.h> #include <string.h> #include <stdlib.h> void SubString(char sub ...

  8. Beta阶段站立会议-02

    项目名:在线考试系统 组名:金州勇士 组长:尹良亮 组员:王汉斌.杜月.闫浩楠 代码地址: ssh:git@git.coding.net:handsomeman/examm.githttps://gi ...

  9. ModelAndView学习整理

    ModelAndView mav = new ModelAndView("/media/play-video");是什么意思 1.这是SpringMVC里面的问题啊!2.这叫返回一 ...

  10. Mac OS X系统下利用VirtualBox安装和配置Windows XP虚拟机

    准备工作 下载并安装VirtualBox for Mac到https://www.virtualbox.org/wiki/Downloads下载VirtualBox <版本> for OS ...