(二)準備 Overlay 網路實驗環境
? 為支持容器跨主機通信,Docker 提供了 overlay driver,使用戶可以創建基于 VxLAN 的 overlay 網路,VxLAN 可將二層資料封裝到 UDP 進行傳輸,VxLAN 提供與 VLAN 相同的以太網二層服務,但是擁有更強的擴展性和靈活性,
? Docerk overlay 網路需要一個 key-value 資料庫用于保存網路狀態資訊,包括 Network、Endpoint、IP 等,Consul、Etcd 和 ZooKeeper 都是 Docker 支持的 key-vlaue 軟體,我們這里使用 Consul,
(1)實驗環境描述
我們會直接使用上一章 docker-machine 創建的實驗環境,在 docker 主機 host1(10.0.0.21)和 host2(10.0.0.22)上實踐各種跨主機網路方案,在 10.0.0.20 上部署支持的組件,比如 Consul,
最簡單的方式是以容器方式運行 Consul:
root@cuiyongchao:~# docker run -d -p 8500:8500 -h consul --name consul progrium/consul -server -bootstrap
Unable to find image 'progrium/consul:latest' locally
latest: Pulling from progrium/consul
Image docker.io/progrium/consul:latest uses outdated schema1 manifest format. Please upgrade to a schema2 image for better future compatibility. More information at https://docs.docker.com/registry/spec/deprecated-schema-v1/
c862d82a67a2: Pull complete
0e7f3c08384e: Pull complete
0e221e32327a: Pull complete
09a952464e47: Pull complete
60a1b927414d: Pull complete
4c9f46b5ccce: Pull complete
417d86672aa4: Pull complete
b0d47ad24447: Pull complete
fd5300bd53f0: Pull complete
a3ed95caeb02: Pull complete
d023b445076e: Pull complete
ba8851f89e33: Pull complete
5d1cefca2a28: Pull complete
Digest: sha256:8cc8023462905929df9a79ff67ee435a36848ce7a10f18d6d0faba9306b97274
Status: Downloaded newer image for progrium/consul:latest
dd2630bfaa0d702a3bcaaccb2d5ac5de206bb5306bdef64e7c1196323a9bfe65
root@cuiyongchao:~#
容器啟動后,可以通過10.0.0.20:8500 訪問 Consul,
接下來修改 host1 和 host2 的 docker daemon 的組態檔/etc/systemd/system/docker.service.d/10-machine.conf,
root@host1:~# vi /lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --storage-driver overlay2 --tlsverify --tlscacert /etc/docker/ca.pem --tlscert /etc/docker/server.pem --tlskey /etc/docker/server-key.pem --label provider=generic --insecure-registry 10.0.0.20:5000 --cluster-store consul://10.0.0.20:8500 --cluster-advertise 10.0.0.22:2376 --insecure-registry 10.0.0.20:5000 --cluster-store consul://10.0.0.20:8500 --cluster-advertise 10.0.0.21:2376
root@host1:~#
--cluster-store 指定 consul 的地址, --cluster-advertise 告知 consul 自己的連接地址,
重啟 docker daemon,
systemctl daemon-reload
systemctl restart docker.service
host1 和 host2 將自動注冊到 Consul 資料庫中,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/229372.html
標籤:其他
