處在不同機器上的 容器是 如何進行通信的。(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 .
噶偶點了