节点1/键值存储:192.168.50.130
节点2:192.168.50.131
1.下载Consul二进制包并启动
wget https://releases.hashicorp.com/consul/0.9.2/consul_0.9.2_linux_amd64.zip
unzip consul_0.9.2_linux_amd64.zipmv consul /usr/bin/consul && chmod +x /usr/bin/consul
nohup consul agent -server -bootstrap -ui -data-dir /var/lib/consul -client=192.168.50.130 -bind=192.168.50.130
&>/var/log/consul.log &
2.节点配置Docker守护进程连接Consul
vi /lib/systemd/system/docker.service
[Service]
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store
consul://192.168.50.130:8500 --cluster-advertise 192.168.1.130:2375
systemctl restart docker
3.创建overlay网络
docker network create -d overlay multi_host
4.测试互通
docker run -itd --net=multi_host busybox
节点B:192.168.50.131
1.启动docker:
Systemctl start docker
2.修改配置文件:vim /usr/lib/systemd/system/docker.service
-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store consul:// 192.168.50.131:8500 --cluster-advertise 192.168.50.131:2375
systemctl daemon-reload && systemctl restart docker
就可以在consul ui上面看到新增加的节点了
3.创建overlay网络:
docker network create -d overlay multi_host(只要在一个节点创建,就会同步到其他节点,不需要在配置其他节点)
4.测试互通:
A B节点都启动一个容器
docker run -it --rm=true --net=multi_host mydockerfile /bin/bash
ping overlay分配的网络
Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONE
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin-top:0cm;
mso-para-margin-right:0cm;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0cm;
line-height:11.0pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-font-kerning:1.0pt;}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章