此外,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;">
$ 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;">
$ etcd --name infra0 --initial-advertise-peer-urls http://10.0.1.10:2380 \
--listen-peer-urls http://10.0.1.10:2380 \
--listen-client-urls http://10.0.1.10:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://10.0.1.10:2379 \
--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;">
$ etcd --name infra1 --initial-advertise-peer-urls http://10.0.1.11:2380 \
--listen-peer-urls http://10.0.1.11:2380 \
--listen-client-urls http://10.0.1.11:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://10.0.1.11:2379 \
--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;">
$ etcd --name infra2 --initial-advertise-peer-urls http://10.0.1.12:2380 \
--listen-peer-urls http://10.0.1.12:2380 \
--listen-client-urls http://10.0.1.12:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://10.0.1.12:2379 \
--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;">
$ curl https://discovery.etcd.io/new?size=3
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;">
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;">
--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;">
$ etcd --name infra0 --initial-advertise-peer-urls http://10.0.1.10:2380 \
--listen-peer-urls http://10.0.1.10:2380 \
--listen-client-urls http://10.0.1.10:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://10.0.1.10:2379 \
--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;">
$ etcd --name infra1 --initial-advertise-peer-urls http://10.0.1.11:2380 \
--listen-peer-urls http://10.0.1.11:2380 \
--listen-client-urls http://10.0.1.11:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://10.0.1.11:2379 \
--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;">
$ etcd --name infra2 --initial-advertise-peer-urls http://10.0.1.12:2380 \
--listen-peer-urls http://10.0.1.12:2380 \
--listen-client-urls http://10.0.1.12:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://10.0.1.12:2379 \
--discovery https://discovery.etcd.io/3e86b59982e49066c5d813af1c2e2579cbf573de
</pre>
这将导致每个成员使用定制的 etcd 发现服务注册自身并开始集群,一旦所有的机器都已经注册。
使用环境变量 ETCD_DISCOVERY_PROXY
来让 etcd 使用 HTTP 代理来连接到发现服务。