参考
OpenvSwitch完全使用手册
云计算底层技术-使用openvswitch
Open vSwitch 概述;OVS支持的功能;ovs的模块介绍(ovs-vswitchd、ovsdb-server等等
学习 OpenStack
2 个 Hyper-V 虚拟机
Ubuntu 20.04
203.0.113.101 /24 ( 网关:203.0.113.1 )
Ubuntu 20.04
203.0.113.103 /24 ( 网关:203.0.113.1 )
连接示意图

摘录 Ubuntu 相关部分:
Ubuntu/Debian includes ovn-central, ovn-host, ovn-docker, and ovn-common packages that pull in the appropriate Open vSwitch dependencies as needed.
Distributions packaging Open vSwitch
摘录 Ubuntu 相关部分:
Debian and Ubuntu has openvswitch-switch and openvswitch-common packages that includes the core userspace components of the switch
apt 安装
apt install openvswitch-switch
apt install python3-pip
pip3 install networking-ovn==4.0.4
apt install ovn-central ovn-common ovn-host
查询确认一下:
dpkg -l |grep openvswitch
ii openvswitch-common 2.13.8-0ubuntu1 amd64 Open vSwitch common componentsii openvswitch-switch 2.13.8-0ubuntu1 amd64 Open vSwitch switch implementationsii python3-openvswitch 2.13.8-0ubuntu1 all Python 3 bindings for Open vSwitch
pip3 list |grep ovn
networking-ovn 4.0.4
如果需要使用 ifconfig 和 route 命令,先安装 apt install net-tools
如果很熟悉 ip 指令,可以不必安装
一个网桥(bridge)就是一个交换机
2 个虚拟机各建立一个 bridge,就相当于各自接入一个交换机
如果这 2 个交换机被分配到同一个网段,就可以直接互相访问彼此
将这个 bridge 上一个端口 (port )连接到物理网卡 (例如: eth1),他就可以通过这个物理网卡和外部网络互相访问 (即:连接到公网)
在 OpenStack 里面,相当于给所有节点提供一个公网 (Provider networks)
在 203.0.113.101 上
ovs-vsctl del-br br1
ovs-vsctl add-br br1ovs-vsctl add-port br1 eth1
ifconfig eth1 0 up
ifconfig br1 203.0.113.101 up
在 203.0.113.103 上
ovs-vsctl del-br br1
ovs-vsctl add-br br1ovs-vsctl add-port br1 eth1
ifconfig eth1 0 up
ifconfig br1 203.0.113.103 up
测试连通性
在 203.0.113.101 上 ping 203.0.113.103
在 203.0.113.103 上 ping 203.0.113.101
2 个虚拟机各建立一个bridge,就相当于各自接入一个交换机
如果这 2 个交换机被分配到不同网段,就无法直接互相访问彼此
在 OpenStack 里面,相当于给所有节点提供一个私有网络 (Self-service networks)
必须通过某些技术配置后才可以访问:这里是 VxLAN 隧道
在 203.0.113.101 上创建 br0
ovs-vsctl del-br br0ovs-vsctl add-br br0ifconfig br0 1.2.3.101/24 upovs-vsctl add-port br0 vx1 -- set interface vx1 type=vxlan options:remote_ip=203.0.113.101
检查一下 br0
root@ubuntu2004-101:/home/dhbm# ovs-vsctl show
57af7789-d775-440a-a204-e663b3c75b3eBridge br0Port vx1Interface vx1type: vxlanoptions: {remote_ip="203.0.113.101"}Port br0Interface br0type: internalBridge br1Port eth1Interface eth1Port br1Interface br1type: internalBridge br-intfail_mode: securePort br-intInterface br-inttype: internalovs_version: "2.13.8"
检查路由
ip route list
确认存在: default via 203.0.113.1 dev br1
在 203.0.113.103 上上创建 br0
ovs-vsctl del-br br0ovs-vsctl add-br br0ifconfig br0 1.2.3.103/24 upovs-vsctl add-port br0 vx1 -- set interface vx1 type=vxlan options:remote_ip=203.0.113.103
检查一下 br0
root@ubuntu2004-103:/home/dhbm# ovs-vsctl show
a762a8e4-e153-4895-b87a-c7f7bc3ce3c3Bridge br0Port vx1Interface vx1type: vxlanoptions: {remote_ip="203.0.113.103"}Port br0Interface br0type: internalBridge br1Port br1Interface br1type: internalPort eth1Interface eth1Bridge br-intfail_mode: securePort br-intInterface br-inttype: internalovs_version: "2.13.8"
检查路由
ip route list
确认存在: default via 203.0.113.1 dev br1
连通性测试
在 203.0.113.101 上 (Self-service networks : 1.2.3.101)
ping 1.2.3.103
在 203.0.113.103 上 (Self-service networks : 1.2.3.103)
ping 1.2.3.101
步骤 1.2 (在 203.0.113.101 上)可以跳过,直接沿用上一部分的配置
在 203.0.113.101 上创建 br0
ovs-vsctl del-br br0ovs-vsctl add-br br0ifconfig br0 1.2.3.101/24 upovs-vsctl add-port br0 vx1 -- set interface vx1 type=vxlan options:remote_ip=203.0.113.101
检查一下 br0
ovs-vsctl show
57af7789-d775-440a-a204-e663b3c75b3eBridge br0Port vx1Interface vx1type: vxlanoptions: {remote_ip="203.0.113.101"}Port br0Interface br0type: internalBridge br1Port eth1Interface eth1Port br1Interface br1type: internalBridge br-intfail_mode: securePort br-intInterface br-inttype: internalovs_version: "2.13.8"
在 203.0.113.103 上 上创建 br0
ovs-vsctl del-br br0ovs-vsctl add-br br0ifconfig br0 5.6.7.103/24 upovs-vsctl add-port br0 vx1 -- set interface vx1 type=vxlan options:remote_ip=203.0.113.103
检查一下 br0
ovs-vsctl show
a762a8e4-e153-4895-b87a-c7f7bc3ce3c3Bridge br0Port vx1Interface vx1type: vxlanoptions: {remote_ip="203.0.113.103"}Port br0Interface br0type: internalBridge br1Port br1Interface br1type: internalPort eth1Interface eth1Bridge br-intfail_mode: securePort br-intInterface br-inttype: internalovs_version: "2.13.8"
连通性测试
在 203.0.113.101 上 (Self-service networks : 1.2.3.101)
ping 5.6.7.103
不通
在 203.0.113.103 上 (Self-service networks : 5.6.7.103)
ping 1.2.3.101
不通
在 203.0.113.101 上 增加路由
route add -net 5.6.7.0 netmask 255.255.255.0 gw 1.2.3.101 dev br0
检查路由
route -n
Kernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 203.0.113.1 0.0.0.0 UG 0 0 0 br10.0.0.0 192.168.0.81 0.0.0.0 UG 0 0 0 eth01.2.3.0 0.0.0.0 255.255.255.0 U 0 0 0 br05.6.7.0 1.2.3.101 255.255.255.0 UG 0 0 0 br05.6.7.0 1.2.3.1 255.255.255.0 UG 0 0 0 br0192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0203.0.113.0 0.0.0.0 255.255.255.0 U 0 0 0 br1
在 203.0.113.103 上创建 br0
route add -net 1.2.3.0 netmask 255.255.255.0 gw 5.6.7.103 dev br0
检查路由
route -n
Kernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 203.0.113.1 0.0.0.0 UG 0 0 0 br10.0.0.0 192.168.0.81 0.0.0.0 UG 0 0 0 eth01.2.3.0 5.6.7.103 255.255.255.0 UG 0 0 0 br01.2.3.0 5.6.7.1 255.255.255.0 UG 0 0 0 br05.6.7.0 0.0.0.0 255.255.255.0 U 0 0 0 br0192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0203.0.113.0 0.0.0.0 255.255.255.0 U 0 0 0 br1
再次连通性测试
在 203.0.113.101 上 (Self-service networks : 1.2.3.101)
ping 5.6.7.103
OK
在 203.0.113.103 上 (Self-service networks : 5.6.7.103)
ping 1.2.3.101
OK