Server1(Server) 192.168.81.58 |內(nèi)核版本 3.10.0-123.el7.x86_64 |Docker版本 1.12.6
Server2(Agent) ?192.168.81.59 ? ? ? ? ? ? ? ? ?3.10.0-123.el7.x86_64 ? ? ? ? ? ? ? ? ? ? 1.12.6
目標(biāo):實(shí)現(xiàn)兩個(gè)CentOS7容器server1,server2網(wǎng)絡(luò)互通
上傳docker_consul包c(diǎn)onsul_0.7.2_linux_amd64.zip
解壓consul并移動(dòng)到$PATH中
unzip consul_0.7.2_linux_amd64.zip -d /usr/local/bin
Server1:
mkdir /opt/d_c
nohup consul agent -server -bootstrap -data-dir /opt/d_c -bind=192.168.81.58 &
顯示結(jié)果:nohup: ignoring input and appending output to ‘nohup.out’
Server2:
mkdir /opt/d_c
nohup consul agent -data-dir /opt/d_c -bind=192.168.81.59 &
顯示結(jié)果:nohup: ignoring input and appending output to ‘nohup.out’
讓agent加入到server中
consul join 192.168.81.58
顯示結(jié)果:Successfully joined cluster by contacting 1 nodes.
vim /etc/sysconfig/docker-network
DOCKER_NETWORK_OPTIONS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store consul://localhost:8500 --cluster-advertise eno16777736:2375"
service docker restart
docker network ls
顯示結(jié)果包含:multihost overlay global
查看Docker網(wǎng)絡(luò)內(nèi)的成員
consul members list
Server1:
docker run -d --net=multihost --name=web1 nginx
docker exec -it web1 /bin/bash
Server2:
docker run -d --net=multihost --name=web2 nginx
docker exec -it web2 /bin/bash
ping web1
ping web2
創(chuàng)建指定靜態(tài)IP的network
docker network create -d overlay --ip-range=192.168.2.0/24 --gateway=192.168.2.1 --subnet=192.168.2.0/24 multihost2