前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Etcd 服务发现

Etcd 服务发现

作者头像
用户5760343
发布2019-10-29 14:47:33
7170
发布2019-10-29 14:47:33
举报
文章被收录于专栏:sktj

此外,discovery URL 应该仅仅用于集群的初始化启动。在集群已经运行之后修改集群成员,阅读 运行时重配置 指南。

定制 etcd 发现服务

发现使用已有集群来启动自身。如果使用私有的 etcd 集群,可以创建像这样的 URL:

<pre class="prettyprint linenums prettyprinted" style="box-sizing: border-box; overflow: auto; font: 400 13.566px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; display: block; padding: 10px; margin: 0px 0px 16px; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background: rgb(246, 246, 246); border: 1px solid transparent; border-radius: 3px; -webkit-tap-highlight-color: transparent; position: relative; white-space: pre-wrap; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. $ curl -X PUT https://myetcd.local/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0fb83/_config/size -d value=3

</pre>

通过设置 URL 的 size,创建了带有期待集群大小为3的 discovery URL。

用于这个场景的 URL 将是 https://myetcd.local/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0fb83 而 etcd 成员将使用 https://myetcd.local/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0fb83 目录来注册,当他们启动时。

每个成员必须有指定不同的名字标记。 Hostname 或者 machine-id 是个好选择。. 否则发现会因为重复名字而失败

现在我们用这些用于每个成员的相关标记启动 etcd :

<pre class="prettyprint linenums prettyprinted" style="box-sizing: border-box; overflow: auto; font: 400 13.566px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; display: block; padding: 10px; margin: 0px 0px 16px; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background: rgb(246, 246, 246); border: 1px solid transparent; border-radius: 3px; -webkit-tap-highlight-color: transparent; position: relative; white-space: pre-wrap; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. $ etcd --name infra0 --initial-advertise-peer-urls http://10.0.1.10:2380 \
  2. --listen-peer-urls http://10.0.1.10:2380 \
  3. --listen-client-urls http://10.0.1.10:2379,http://127.0.0.1:2379 \
  4. --advertise-client-urls http://10.0.1.10:2379 \
  5. --discovery https://myetcd.local/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0fb83

</pre>

<pre class="prettyprint linenums prettyprinted" style="box-sizing: border-box; overflow: auto; font: 400 13.566px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; display: block; padding: 10px; margin: 0px 0px 16px; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background: rgb(246, 246, 246); border: 1px solid transparent; border-radius: 3px; -webkit-tap-highlight-color: transparent; position: relative; white-space: pre-wrap; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. $ etcd --name infra1 --initial-advertise-peer-urls http://10.0.1.11:2380 \
  2. --listen-peer-urls http://10.0.1.11:2380 \
  3. --listen-client-urls http://10.0.1.11:2379,http://127.0.0.1:2379 \
  4. --advertise-client-urls http://10.0.1.11:2379 \
  5. --discovery https://myetcd.local/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0fb83

</pre>

<pre class="prettyprint linenums prettyprinted" style="box-sizing: border-box; overflow: auto; font: 400 13.566px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; display: block; padding: 10px; margin: 0px 0px 16px; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background: rgb(246, 246, 246); border: 1px solid transparent; border-radius: 3px; -webkit-tap-highlight-color: transparent; position: relative; white-space: pre-wrap; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. $ etcd --name infra2 --initial-advertise-peer-urls http://10.0.1.12:2380 \
  2. --listen-peer-urls http://10.0.1.12:2380 \
  3. --listen-client-urls http://10.0.1.12:2379,http://127.0.0.1:2379 \
  4. --advertise-client-urls http://10.0.1.12:2379 \
  5. --discovery https://myetcd.local/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0fb83

</pre>

这将导致每个成员使用定制的 etcd 发现服务注册自身并开始集群,一旦所有的机器都已经注册。

公共 etcd 发现服务

如果没有现成的集群可用,可以使用托管在 discovery.etcd.io 的公共发现服务。为了使用”new” endpoint来创建私有发现URL,使用命令:

<pre class="prettyprint linenums prettyprinted" style="box-sizing: border-box; overflow: auto; font: 400 13.566px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; display: block; padding: 10px; margin: 0px 0px 16px; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background: rgb(246, 246, 246); border: 1px solid transparent; border-radius: 3px; -webkit-tap-highlight-color: transparent; position: relative; white-space: pre-wrap; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. $ curl https://discovery.etcd.io/new?size=3
  2. https://discovery.etcd.io/3e86b59982e49066c5d813af1c2e2579cbf573de

</pre>

这将创建带有初始化预期大小为3个成员的集群。如果没有指定大小,将使用默认值3。

<pre class="prettyprint linenums prettyprinted" style="box-sizing: border-box; overflow: auto; font: 400 13.566px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; display: block; padding: 10px; margin: 0px 0px 16px; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background: rgb(246, 246, 246); border: 1px solid transparent; border-radius: 3px; -webkit-tap-highlight-color: transparent; position: relative; white-space: pre-wrap; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. ETCD_DISCOVERY=https://discovery.etcd.io/3e86b59982e49066c5d813af1c2e2579cbf573de

</pre>

<pre class="prettyprint linenums prettyprinted" style="box-sizing: border-box; overflow: auto; font: 400 13.566px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; display: block; padding: 10px; margin: 0px 0px 16px; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background: rgb(246, 246, 246); border: 1px solid transparent; border-radius: 3px; -webkit-tap-highlight-color: transparent; position: relative; white-space: pre-wrap; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. --discovery https://discovery.etcd.io/3e86b59982e49066c5d813af1c2e2579cbf573de

</pre>

每个成员必须有指定不同的名字标记。 Hostname 或者 machine-id 是个好选择。. 否则发现会因为重复名字而失败

现在我们用这些用于每个成员的相关标记启动 etcd :

<pre class="prettyprint linenums prettyprinted" style="box-sizing: border-box; overflow: auto; font: 400 13.566px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; display: block; padding: 10px; margin: 0px 0px 16px; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background: rgb(246, 246, 246); border: 1px solid transparent; border-radius: 3px; -webkit-tap-highlight-color: transparent; position: relative; white-space: pre-wrap; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. $ etcd --name infra0 --initial-advertise-peer-urls http://10.0.1.10:2380 \
  2. --listen-peer-urls http://10.0.1.10:2380 \
  3. --listen-client-urls http://10.0.1.10:2379,http://127.0.0.1:2379 \
  4. --advertise-client-urls http://10.0.1.10:2379 \
  5. --discovery https://discovery.etcd.io/3e86b59982e49066c5d813af1c2e2579cbf573de

</pre>

<pre class="prettyprint linenums prettyprinted" style="box-sizing: border-box; overflow: auto; font: 400 13.566px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; display: block; padding: 10px; margin: 0px 0px 16px; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background: rgb(246, 246, 246); border: 1px solid transparent; border-radius: 3px; -webkit-tap-highlight-color: transparent; position: relative; white-space: pre-wrap; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. $ etcd --name infra1 --initial-advertise-peer-urls http://10.0.1.11:2380 \
  2. --listen-peer-urls http://10.0.1.11:2380 \
  3. --listen-client-urls http://10.0.1.11:2379,http://127.0.0.1:2379 \
  4. --advertise-client-urls http://10.0.1.11:2379 \
  5. --discovery https://discovery.etcd.io/3e86b59982e49066c5d813af1c2e2579cbf573de

</pre>

<pre class="prettyprint linenums prettyprinted" style="box-sizing: border-box; overflow: auto; font: 400 13.566px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; display: block; padding: 10px; margin: 0px 0px 16px; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word; background: rgb(246, 246, 246); border: 1px solid transparent; border-radius: 3px; -webkit-tap-highlight-color: transparent; position: relative; white-space: pre-wrap; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

  1. $ etcd --name infra2 --initial-advertise-peer-urls http://10.0.1.12:2380 \
  2. --listen-peer-urls http://10.0.1.12:2380 \
  3. --listen-client-urls http://10.0.1.12:2379,http://127.0.0.1:2379 \
  4. --advertise-client-urls http://10.0.1.12:2379 \
  5. --discovery https://discovery.etcd.io/3e86b59982e49066c5d813af1c2e2579cbf573de

</pre>

这将导致每个成员使用定制的 etcd 发现服务注册自身并开始集群,一旦所有的机器都已经注册。

使用环境变量 ETCD_DISCOVERY_PROXY 来让 etcd 使用 HTTP 代理来连接到发现服务。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019.10.25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 定制 etcd 发现服务
  • 公共 etcd 发现服务
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档