节点 IP vxbr网桥
openvswitch01 192.168.1.221 10.10.1.2/24
openvswitch02 192.168.1.222 10.10.2.2/24

openvswitch01:192.168.1.221                    

[root@localhost ~]# ovs-vsctl add-br vxbr
[root@openvswitch01 ~]# ifconfig vxbr 10.10.1.2/24
#ovs创建一个虚拟网桥,并给网桥一个ip
[root@openvswitch01 ~]# ovs-vsctl add-port vxbr vxlan -- set interface vxlan type=vxlan options:remote_ip=192.168.1.222
#给网桥添加一个vxlan类型的端口,remote_ip就是
openvswitch02的ens33 地址
[root@openvswitch01 ~]# docker run --net=none --privileged=true -it busybox:latest Unable to find image 'busybox:latest' locally latest: Pulling from library/busybox 322973677ef5: Pull complete Digest: sha256:1828edd60c5efd34b2bf5dd3282ec0cc04d47b2ff9caa0b6d4f07a21d1c08084 Status: Downloaded newer image for busybox:latest
#启动一个没有以太网卡的docker容器,并记下这个容器的ID,此时在这个容器里面ifconfig只能看到一个lo的设备。
[root@openvswitch01 ~]# ovs-docker add-port vxbr ens33 136834398a7f
#给容器机指定一个ens33并绑定到宿主机的vxbr网桥
/ # ifconfig ens33 10.10.1.3
#给容器一个IP地址。
/ # ifconfig ens33 ens33 Link encap:Ethernet HWaddr 8E:44:86:53:8A:61 inet addr:10.10.1.3 Bcast:10.255.255.255 Mask:255.0.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:648 (648.0 B) TX bytes:0 (0.0 B)
[root@openvswitch01 ~]# ovs-vsctl show  #查看ovs配置 d428e27e-f942-41ad-a592-fe81ad6c88be Bridge vxbr Port vxbr Interface vxbr type: internal Port vxlan Interface vxlan type: vxlan options: {remote_ip="192.168.1.222"} Port "24cdff930a564_l" Interface "24cdff930a564_l" ovs_version: "2.5.2"

openvswitch01:192.168.1.222                    

[root@localhost ~]# ovs-vsctl add-br vxbr
[root@openvswitch02 ~]# ifconfig vxbr 10.10.2.2/24
[root@openvswitch02 ~]# ovs-vsctl add-port vxbr vxlan -- set interface vxlan type=vxlan options:remote_ip=192.168.1.221
[root@openvswitch02 ~]# docker run --net=none --privileged=true -it busybox:latest Unable to find image 'busybox:latest' locally latest: Pulling from library/busybox 322973677ef5: Pull complete Digest: sha256:1828edd60c5efd34b2bf5dd3282ec0cc04d47b2ff9caa0b6d4f07a21d1c08084 Status: Downloaded newer image for busybox:latest
[root@openvswitch02 ~]# ovs-docker add-port vxbr ens33 4ddcf7e3f902
/ # ifconfig ens33 10.10.2.3 / # ifconfig ens33 ens33 Link encap:Ethernet HWaddr EA:8C:E2:F2:EB:5B inet addr:10.10.2.3 Bcast:10.255.255.255 Mask:255.0.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:648 (648.0 B) TX bytes:0 (0.0 B)
[root@openvswitch02 ~]# ovs-vsctl show 2cd563af-2a6b-4863-960e-fd7a4f56e898 Bridge vxbr Port vxlan Interface vxlan type: vxlan options: {remote_ip="192.168.1.221"} Port vxbr Interface vxbr type: internal Port "52272becc5a54_l" Interface "52272becc5a54_l" ovs_version: "2.5.2"

openvswitch01openvswitch01上关闭防火墙              

[root@openvswitch01 ~]# systemctl stop firewalld
/ # ping 10.10.2.3
PING 10.10.2.3 (10.10.2.3): 56 data bytes
64 bytes from 10.10.2.3: seq=0 ttl=64 time=3.155 ms
64 bytes from 10.10.2.3: seq=1 ttl=64 time=0.916 ms
64 bytes from 10.10.2.3: seq=2 ttl=64 time=0.920 ms
64 bytes from 10.10.2.3: seq=3 ttl=64 time=0.895 ms
64 bytes from 10.10.2.3: seq=4 ttl=64 time=0.874 ms
64 bytes from 10.10.2.3: seq=5 ttl=64 time=0.929 ms
64 bytes from 10.10.2.3: seq=6 ttl=64 time=0.837 ms
64 bytes from 10.10.2.3: seq=7 ttl=64 time=1.263 ms
64 bytes from 10.10.2.3: seq=8 ttl=64 time=0.979 ms
64 bytes from 10.10.2.3: seq=9 ttl=64 time=0.953 ms
64 bytes from 10.10.2.3: seq=10 ttl=64 time=1.192 ms
64 bytes from 10.10.2.3: seq=11 ttl=64 time=0.964 ms
64 bytes from 10.10.2.3: seq=12 ttl=64 time=0.920 ms
64 bytes from 10.10.2.3: seq=13 ttl=64 time=1.011 ms
/ # ping 10.10.1.3
PING 10.10.1.3 (10.10.1.3): 56 data bytes
64 bytes from 10.10.1.3: seq=0 ttl=64 time=0.724 ms
64 bytes from 10.10.1.3: seq=1 ttl=64 time=1.253 ms
64 bytes from 10.10.1.3: seq=2 ttl=64 time=0.968 ms
64 bytes from 10.10.1.3: seq=3 ttl=64 time=3.848 ms

 

[root@openvswitch01 ~]# ifconfig
24cdff930a564_l: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::d4da:5ff:fee5:a239  prefixlen 64  scopeid 0x20<link>
        ether d6:da:05:e5:a2:39  txqueuelen 1000  (Ethernet)
        RX packets 40  bytes 3176 (3.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 40  bytes 3176 (3.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:8e:f0:b0:66  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.221  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::c8e4:7436:3263:f906  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:f0:61:cb  txqueuelen 1000  (Ethernet)
        RX packets 7987  bytes 1325894 (1.2 MiB)
        RX errors 0  dropped 552  overruns 0  frame 0
        TX packets 1569  bytes 151939 (148.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 40  bytes 3176 (3.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 40  bytes 3176 (3.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vxbr: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.10.1.2  netmask 255.255.255.0  broadcast 10.10.1.255
        inet6 fe80::3829:58ff:fe84:c04c  prefixlen 64  scopeid 0x20<link>
        ether 3a:29:58:84:c0:4c  txqueuelen 1000  (Ethernet)
        RX packets 49  bytes 1372 (1.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8  bytes 648 (648.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vxlan_sys_4789: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 65470
        inet6 fe80::3c6e:53ff:fe2b:5bcd  prefixlen 64  scopeid 0x20<link>
        ether 3e:6e:53:2b:5b:cd  txqueuelen 1000  (Ethernet)
        RX packets 66  bytes 3752 (3.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 60  bytes 3584 (3.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0