2

I am trying to connect two Docker hosts with an overlay network and am using etcd as a KV-store. etcd is running directly on the first host (not in a container). I finally managed to connect the Docker daemon of the first host to etcd but cannot manage to establish a connection the Docker daemon on the second host.

I downloaded etcd from the Github releases page and followed the instructions under the "Linux" section. After starting etcd, it is listening to the following ports:

etcdmain: listening for peers on http://localhost:2380
etcdmain: listening for peers on http://localhost:7001
etcdmain: listening for client requests on http://localhost:2379
etcdmain: listening for client requests on http://localhost:4001

And I started the Docker daemon on the first host (on which etcd is running as well) like this:

docker daemon --cluster-advertise eth1:2379 --cluster-store etcd://127.0.0.1:2379

After that, I could also create an overlay network with:

docker network create -d overlay <network name>

But I can't figure out how to start the daemon on the second host. No matter which values I tried for --cluster-advertise and --cluster-store, I keep getting the following error message:

discovery error: client: etcd cluster is unavailable or misconfigured

Both my hosts are using the eth1 interface. The IP of host1 is 10.10.10.10 and the IP of host2 is 10.10.10.20. I already ran iperf to make sure they can connect to each other.

Any ideas?

4

1 回答 1

2

所以我终于弄清楚了如何连接两个主机,老实说,我不明白为什么我花了这么长时间才解决问题。但是如果其他人遇到同样的问题,我会在这里发布我的解决方案。如前所述,我从Github 发布页面下载了 etcd并提取了tar文件。

我按照etcd 文档中的说明将其应用于我的情况。我没有直接从命令行使用所有选项运行 etcd,而是创建了一个简单的 bash 脚本。这使得调整选项和重新运行命令变得容易得多。一旦你找到了正确的选项,将它们分别放在一个配置文件中并按照本教程中的说明将 etcd 作为服务运行会很方便。所以这是我的 bash 脚本:

#!/bin/bash

./etcd --name infra0 \
  --initial-advertise-peer-urls http://10.10.10.10:2380 \
  --listen-peer-urls http://10.10.10.10:2380 \
  --listen-client-urls http://10.10.10.10:2379,http://127.0.0.1:2379 \
  --advertise-client-urls http://10.10.10.10:2379 \
  --initial-cluster-token etcd-cluster-1 \
  --initial-cluster infra0=http://10.10.10.10:2380,infra1=http://10.10.10.20:2380 \
  --initial-cluster-state new

我将此文件放在etcd-vX.X.X-linux-amd64还包含etcd二进制文件的目录中(我刚刚下载并解压缩)。在第二台主机上我做了同样的事情,但改变了--nameinfra0infra1并将 IP 调整为第二台主机(10.10.10.20)。该--initial-cluster选项未修改。

然后我先在 host1 上执行脚本,然后在 host2 上执行。我不确定订单是否重要,但在我的情况下,当我反其道而行之时,我收到了一条错误消息。

为确保您的集群设置正确,您可以运行:

./etcdctl cluster-health

如果输出看起来与此类似(列出两个成员),它应该可以工作。

member 357e60d488ae5ab3 is healthy: got healthy result from http://10.10.10.10:2379
member 590f234979b9a5ee is healthy: got healthy result from http://10.10.10.20:2379

如果您想确定,请在 host1 上的 store 中添加一个值,然后在 host2 上检索它:

host1$ ./etcdctl set myKey myValue
host2$ ./etcdctl get myKey

设置 docker 覆盖网络

为了设置 docker 覆盖网络,我必须使用--cluster-storeand--cluster-advertise选项重新启动 Docker 守护程序。我的解决方案可能不是最干净的,但它有效。因此,在两台主机上,首先停止 docker 服务,然后使用以下选项重新启动守护进程:

sudo service docker stop
sudo /usr/bin/docker daemon --cluster-store=etcd://10.10.10.10:2379 --cluster-advertise=10.10.10.10:2379

请注意,在 host2 上,需要调整 IP 地址。然后我在其中一台主机上创建了这样的覆盖网络:

sudo docker network create -d overlay <network name>

如果一切正常,现在可以在另一台主机上看到覆盖网络。用这个命令检查:

sudo docker network ls
于 2016-04-10T18:41:31.400 回答