共計 2870 個字符,預(yù)計需要花費(fèi) 8 分鐘才能閱讀完成。
丸趣 TV 小編給大家分享一下 DDBMS 中如何冗余 docker 網(wǎng)絡(luò),相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
環(huán)境準(zhǔn)備:
vmware 中配置四臺 ubuntu server 14.04(你可以只安裝一個系統(tǒng),使用克隆功能克隆出另外三臺 ubuntu),配置好 SSH
每臺機(jī)器配置兩個網(wǎng)卡,像 openstack 一樣,分 Internal 和 External IP。這里我讓 eth0(NAT)作為 External,eth2(host-only)作為 Internal。
拓?fù)鋱D如下:
安裝 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
創(chuàng)建掛載容器用的 br0 和 br1 網(wǎng)橋:
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(每次開機(jī)先執(zhí)行 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
創(chuàng)建 host1tohost2 的 vxlan 或 gre 隧道(這里我用的是 gre):
ovs-vsctl add-port ovs0 gre0 -- set interface gre0 type=gre options:remote_ip=10.20.10.71
創(chuàng)建 host2tohost1 的 gre 隧道:
ovs-vsctl add-port ovs0 gre0 -- set interface gre0 type=gre options:remote_ip=10.20.10.70
創(chuàng)建 host2tohost3 的隧道:
ovs-vsctl add-port ovs0 gre1 -- set interface gre1 type=gre options:remote_ip=10.20.10.72
創(chuàng)建 host3tohost2 的隧道:
ovs-vsctl add-port ovs0 gre1 -- set interface gre1 type=gre options:remote_ip=10.20.10.71
創(chuàng)建 host3tohost4 的隧道:
ovs-vsctl add-port ovs0 gre2 -- set interface gre2 type=gre options:remote_ip=10.20.10.73
創(chuàng)建 host4tohost3 的隧道:
ovs-vsctl add-port ovs0 gre2 -- set interface gre2 type=gre options:remote_ip=10.20.10.72
創(chuàng)建 host4tohost1 的隧道:
ovs-vsctl add-port ovs0 gre3 -- set interface gre3 type=gre options:remote_ip=10.20.10.70
創(chuàng)建 host1tohost4 的隧道:
ovs-vsctl add-port ovs0 gre3 -- set interface gre3 type=gre options:remote_ip=10.20.10.73
(注意,兩臺主機(jī)間的互通隧道名相同,且每個 OVS 上不能出現(xiàn)重名的隧道)
啟動容器并測試:
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
進(jìn)入容器進(jìn)行測試,你會發(fā)現(xiàn),無論哪個容器,只要掛在同一個 br 網(wǎng)橋(同一網(wǎng)段),它們都是互通的。當(dāng)然,如果你用 192.168.2.11 ping 192.168.3.11 那是絕對不行的(除非你不把 br0 和 br1 掛在 ovs0 上,此時 route 會進(jìn)行路由,這種情況下可以互通)。
此時,你就建立了一個冗余的 docker 容器網(wǎng)絡(luò)。
以上是“DDBMS 中如何冗余 docker 網(wǎng)絡(luò)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注丸趣 TV 行業(yè)資訊頻道!