多机器之间的docker通信。

处在不同机器上的 容器是 如何进行通信的。(VXLAN 可以官网看细节。)

首先 这两台主机是可以进行 通信的。

docker的 overlay  网络。(bridge host none 都是单机的。  overlay就是多机网络了)

最北两台安装了  docker的主机   docker1 和 docker2!

然后还需要一个分布式存储的工具。( 这是为了保证ip地址不重复。比如我在docker1主机上, 其中一个容器的ip为 172.17.0.2  。那就需要保证另一台机器上不能再有一个容器 的ip地址也是  172.17.0.2 。  可以是172.17.0.3    172.17.0.4 都可以。所以才需要一个分布式存储的工具来保证这些。)

这里使用  etcd

# 两台主机全都安装上:

[miller@docker4 download]$ ls
Python-3.7.7  Python-3.7.7.tgz  v3.4.7
[miller@docker4 download]$ rm v3.4.7 
[miller@docker4 download]$ wget https://github.com/etcd-io/etcd/releases/download/v3.4.7/etcd-v3.4.7-linux-amd64.tar.gz
--2020-04-11 18:47:37--  https://github.com/etcd-io/etcd/releases/download/v3.4.7/etcd-v3.4.7-linux-amd64.tar.gz
正在解析主机 github.com (github.com)... 52.74.223.119
正在连接 github.com (github.com)|52.74.223.119|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:https://github-production-release-asset-2e65be.s3.amazonaws.com/11225014/cd901e00-7419-11ea-88fc-732f4a7bec4f?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20200411%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200411T104738Z&X-Amz-Expires=300&X-Amz-Signature=879d4434d3aa1db5bcb75cf57c3d139c5ae98904941d1aa3a41ad656774a9766&X-Amz-SignedHeaders=host&actor_id=0&repo_id=11225014&response-content-disposition=attachment%3B%20filename%3Detcd-v3.4.7-linux-amd64.tar.gz&response-content-type=application%2Foctet-stream [跟随至新的 URL]
--2020-04-11 18:47:38--  https://github-production-release-asset-2e65be.s3.amazonaws.com/11225014/cd901e00-7419-11ea-88fc-732f4a7bec4f?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20200411%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200411T104738Z&X-Amz-Expires=300&X-Amz-Signature=879d4434d3aa1db5bcb75cf57c3d139c5ae98904941d1aa3a41ad656774a9766&X-Amz-SignedHeaders=host&actor_id=0&repo_id=11225014&response-content-disposition=attachment%3B%20filename%3Detcd-v3.4.7-linux-amd64.tar.gz&response-content-type=application%2Foctet-stream
正在解析主机 github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)... 52.216.133.75
正在连接 github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)|52.216.133.75|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:17310840 (17M) [application/octet-stream]
正在保存至: “etcd-v3.4.7-linux-amd64.tar.gz”

100%[=============================================================================================================================>] 17,310,840  3.38MB/s 用时 5.1s   

2020-04-11 18:47:45 (3.26 MB/s) - 已保存 “etcd-v3.4.7-linux-amd64.tar.gz” [17310840/17310840])

[miller@docker4 download]$ tar -zxvf etcd-v3.4.7-linux-amd64.tar.gz

[miller@docker4 download]$ cd etcd-v3.4.7-linux-amd64/

然后分别配置

[miller@docker4 etcd-v3.4.7-linux-amd64]$ nohup ./etcd --name 'docker4' \
> --initial-advertise-peer-urls 'http://192.168.42.22:2380' \
> --listen-peer-urls 'http://192.168.42.22:2380' \
> --listen-client-urls 'http://192.168.42.22:2379' \
> --advertise-client-urls 'http://192.168.42.22:2379' \
> --initial-cluster-token 'etcd-cluster' \
> --initial-cluster 'docker4=http://192.168.42.22:2380,docker5=http://192.168.42.23:2380' \
> --initial-cluster-state 'new&' 
nohup: 忽略输入并把输出追加到"nohup.out"

[miller@docker4 etcd
-v3.4.7-linux-amd64]$ nohup ./etcd --name 'docker5' \ > --initial-advertise-peer-urls 'http://192.168.42.23:2380' \ > --listen-peer-urls 'http://192.168.42.23:2380' \ > --listen-client-urls 'http://192.168.42.23:2379, http://127.0.0.1:2379' \ > --advertise-client-urls 'http://192.168.43.23:2379' \ > --initial-cluster-token 'etcd-cluster' \ > --initial-cluster 'docker4=http://192.168.42.22:2380,docker5=http://192.168.42.23:2380' \ > --initial-cluster-state 'new&' nohup: 忽略输入并把输出追加到"nohup.out"

将启动这的docker 听一下。 因为要让docker知道 我们使用了  etcd .

噶偶点了

猜你喜欢

转载自www.cnblogs.com/chengege/p/12682172.html
今日推荐