DDBMS中如何冗余docker网络

59次阅读
没有评论

共计 2870 个字符,预计需要花费 8 分钟才能阅读完成。

丸趣 TV 小编给大家分享一下 DDBMS 中如何冗余 docker 网络,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

环境准备:

vmware 中配置四台 ubuntu server 14.04(你可以只安装一个系统,使用克隆功能克隆出另外三台 ubuntu),配置好 SSH

每台机器配置两个网卡,像 openstack 一样,分 Internal 和 External IP。这里我让 eth0(NAT)作为 External,eth2(host-only)作为 Internal。

拓扑图如下:

DDBMS 中如何冗余 docker 网络 

安装 OVS:

具体安装教程参考这里:http://www.sdnlab.com/3166.html

附上我的 OVS 启动脚本:

ovs_launch
#!/bin/bash
#launch the ovs
ovsdb-server -v --remote=punix:/usr/local/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,Open_vSwitch,manager_options --private-key=db:Open_vSwitch,SSL,private_key --certificate=db:Open_vSwitch,SSL,certificate --bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert --pidfile --detach
#init the database
ovs-vsctl --no-wait init
#launch the main process
ovs-vswitchd --pidfile --detach
#print the version infomation
ovs-vsctl --version
echo 
echo  OpenVswitch have been launched successfully!

保存并放置该脚本

chmod +x ovs_launch
mv ovs_launch /usr/local/bin

安装 pipework 工具:

git clone https://github.com/jpetazzo/pipework
cp ~/pipework/pipework /usr/local/bin/

安装 docker 最新的版本:https://docs.docker.com/installation/ubuntulinux/

pull 一个镜像:

docker pull ubuntu

创建挂载容器用的 br0 和 br1 网桥:

brctl addbr br0
ip link set dev br0 up
ip addr add 192.168.2.1/24 dev br0
brctl addbr br1
ip link set dev br1 up
ip addr add 192.168.3.1/24 dev br1

在每台 host 上配置 OVS(每次开机先执行 ovs_launch):

ovs-vsctl add-br ovs0
ovs-vsctl set bridge ovs0 stp_enable=true
ovs-vsctl add-port ovs0 br0
ovs-vsctl add-port ovs0 br1

创建 host1tohost2 的 vxlan 或 gre 隧道(这里我用的是 gre):

ovs-vsctl add-port ovs0 gre0 -- set interface gre0 type=gre options:remote_ip=10.20.10.71

创建 host2tohost1 的 gre 隧道:

ovs-vsctl add-port ovs0 gre0 -- set interface gre0 type=gre options:remote_ip=10.20.10.70

创建 host2tohost3 的隧道:

ovs-vsctl add-port ovs0 gre1 -- set interface gre1 type=gre options:remote_ip=10.20.10.72

创建 host3tohost2 的隧道:

ovs-vsctl add-port ovs0 gre1 -- set interface gre1 type=gre options:remote_ip=10.20.10.71

创建 host3tohost4 的隧道:

ovs-vsctl add-port ovs0 gre2 -- set interface gre2 type=gre options:remote_ip=10.20.10.73

创建 host4tohost3 的隧道:

ovs-vsctl add-port ovs0 gre2 -- set interface gre2 type=gre options:remote_ip=10.20.10.72

创建 host4tohost1 的隧道:

ovs-vsctl add-port ovs0 gre3 -- set interface gre3 type=gre options:remote_ip=10.20.10.70

创建 host1tohost4 的隧道:

ovs-vsctl add-port ovs0 gre3 -- set interface gre3 type=gre options:remote_ip=10.20.10.73

(注意,两台主机间的互通隧道名相同,且每个 OVS 上不能出现重名的隧道)

启动容器并测试:

host1:

docker run -itd --name=test1 ubuntu
pipework br0 test1 192.168.2.11/24

host2:

docker run -itd --name=test1 ubuntu
pipework br0 test1 192.168.2.12/24

host3:

docker run -itd --name=test1 ubuntu
pipework br1 test1 192.168.3.11/24

host4:

docker run -itd --name=test1 ubuntu
pipework br1 test1 192.168.3.12/24

进入容器进行测试,你会发现,无论哪个容器,只要挂在同一个 br 网桥(同一网段),它们都是互通的。当然,如果你用 192.168.2.11 ping 192.168.3.11 那是绝对不行的(除非你不把 br0 和 br1 挂在 ovs0 上,此时 route 会进行路由,这种情况下可以互通)。

此时,你就建立了一个冗余的 docker 容器网络。

以上是“DDBMS 中如何冗余 docker 网络”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注丸趣 TV 行业资讯频道!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-25发表,共计2870字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)