在 CentOS 8 中使用 NetworkManager 设置 Open vSwitch 的正确方法是什么?

在 CentOS 8 中使用 NetworkManager 设置 Open vSwitch 的正确方法是什么?

在过去的美好时光里,情况是怎样的network-scripts

我已经在文件中描述了桥梁和端口:

/etc/sysconfig/network-scripts/ifcfg-br0
/etc/sysconfig/network-scripts/ifcfg-port0

比重新启动网络

systemctl restart network

一切开始正常运转。

现在network-scripts被标记为已弃用,有一个警告will be removed in one of the next major releases of RHEL.,所以我必须切换到 NetworkManager,对吗?

但是如何使用 NetworkManager 设置 Open vSwitch?

我已经安装NetworkManager-ovs并尝试了这个指导但描述的命令什么都不做,我的意思是输出中什么都没有出现ovs-vsctl show

nmcli networking off && nmcli networking on或者systemctl restart NetworkManager没有任何效果

ifup br0也不起作用:

Error: unknown connection '/etc/sysconfig/network-scripts/ifcfg-br0'.

答案1

创建具有单个内部接口的网桥

$ nmcli conn add type ovs-bridge conn.interface bridge0
Connection 'ovs-bridge-bridge0' (d10fc64d-1d48-4394-a1b8-e1aea72f27d5) successfully added.

$ nmcli conn add type ovs-port conn.interface port0 master bridge0
Connection 'ovs-port-port0' (5ae22bae-bba4-4815-9ade-7e635633e1f0) successfully added.

$ nmcli conn add type ovs-interface slave-type ovs-port conn.interface iface0 \
  master port0 ipv4.method manual ipv4.address 192.0.2.1/24
Connection 'ovs-interface-iface0' (3640d2a1-a2fd-4718-92f1-cffadb5b6cdc) successfully added.

即使只有一个接口,您也需要创建一个端口。此外,在添加接口之前,桥接器和端口设备会显示为活动状态,但尚未在 OVSDB 中配置。您可以使用 ovs-vsctl show 检查结果。

向 Bridge 添加 Linux 接口

$ nmcli conn add type ovs-port conn.interface port1 master bridge0
Connection 'ovs-port-port1' (67d041eb-8e7b-4458-afee-a1d07c9c4552) successfully added.
$ nmcli conn add type ethernet conn.interface eth0 master port1
Connection 'ovs-slave-eth0' (d459c45c-cf78-4c1c-b4b7-505e71379624) successfully added.

现在运行 ovs-vsctl show 并检查它。

答案2

这里展示了使用 NetworkManager 配置 Open vSwitch 的端到端流程。我有主网络接口eth0,我将创建br-ext并连接eth0到它,然后我将创建br-intbr-routed,然后连接br-extbr-int修补端口。

  1. 为 NetworkManager 安装 Open vSwitch 插件并重新启动 NetworkManager 以加载插件:
dnf install NetworkManager-ovs 
systemctl restart NetworkManager
  1. 让我们创建一座桥梁br-ext
nmcli conn add type ovs-bridge conn.interface br-ext               con-name br-ext
nmcli conn add type ovs-port   conn.interface br-ext master br-ext con-name ovs-port-br-ext
nmcli conn add type ovs-interface slave-type ovs-port con.interface br-ext master ovs-port-br-ext \
      con-name ovs-if-br-ext ipv4.method manual ipv4.addresses 10.54.1.98/21 ipv4.gateway 10.54.0.1
  1. 要添加eth0到桥接器br-ext,请注意您可能仍有配置文件/etc/sysconfig/network-scripts/ifcfg-eth0,必须在之前删除此配置文件nmcli reload
nmcli conn add type ovs-port conn.interface eth0 master br-ext        con-name ovs-port-eth0
nmcli conn add type ethernet conn.interface eth0 master ovs-port-eth0 con-name ovs-if-eth0
  1. 有时我们需要为桥接添加额外设置,就像我们之前通过 所做的那样OVS_EXTRA,现在我们可以使用像这样的传递设置ovs-bridge.rstp-enable true。您可以检查哪些选项可以使用 进行设置nmcli conn show br-ext。请注意,这需要在服务器重启后ipv4.method disabled ipv6.method disabled才能启动:br-routed
nmcli conn add type ovs-bridge conn.interface br-routed ovs-bridge.rstp-enable true  con-name br-routed
nmcli conn add type ovs-port conn.interface br-routed master br-routed con-name ovs-port-br-routed
nmcli conn add type ovs-interface slave-type ovs-port conn.interface br-routed \
      master ovs-port-br-routed con-name ovs-if-br-routed ipv4.method disabled ipv6.method disabled
  1. 创建br-int,这里没什么特别的:
nmcli conn add type ovs-bridge conn.interface br-int con-name br-int
nmcli conn add type ovs-port conn.interface br-int master br-int con-name ovs-port-br-int
nmcli conn add type ovs-interface slave-type ovs-port conn.interface br-int
      master ovs-port-br-int con-name ovs-if-br-int ipv4.method disabled ipv6.method disabled
  1. 有时我们需要使用 patch 端口桥接 Open vSwitch,使用以下命令进行br-int连接br-ext
# create patch-br-int
nmcli conn add type ovs-port conn.interface patch-br-int master br-int con-name patch-br-int
nmcli conn add type ovs-interface slave-type ovs-port conn.interface patch-br-int master patch-br-int \
      con-name ovs-if-patch-br-int ovs-interface.type patch ovs-patch.peer patch-br-ext

# create patch-br-ext
nmcli conn add type ovs-port conn.interface patch-br-ext master br-ext con-name patch-br-ext
nmcli conn add type ovs-interface slave-type ovs-port conn.interface patch-br-ext master patch-br-ext \
      con-name ovs-if-patch-br-ext ovs-interface.type patch ovs-patch.peer patch-br-int
  1. 要应用所有这些东西,我们需要重新加载连接:
nmcli conn reload

相关内容