Centos7部署ovs

2023-11-20
1分钟阅读时长

安装依赖

yum groupinstall -y "Development Tools"
yum install -y dnf-plugins-core epel-release
yum config-manager --set-enabled powertools
yum install -y python3-sphinx python3-six numactl-devel libbpf-devel  libbpf libxdp-devel libxdp wget openssl-devel gcc make python3-devel openssl-devel kernel-devel graphviz kernel-debug-devel autoconf automake rpm-build redhat-rpm-config libtool deskto NetworkManager

构建rpm包

wget https://www.openvswitch.org/releases/openvswitch-3.2.1.tar.gz
tar xzf openvswitch-3.2.1.tar.gz
cd openvswitch-3.2.1
./boot.sh
./configure
make -j
make install

配置systemd服务 /etc/systemd/system/ovs.service

[Unit]
Description=Open vSwitch server daemon
Before=network.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/share/openvswitch/scripts/ovs-ctl start
ExecStop=/usr/local/share/openvswitch/scripts/ovs-ctl stop

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable ovs

配置ovs网桥

创建名为ovs_br0的网桥

ovs-vsctl add-br ovs_br0

查看网桥

[root@hstack ~]# ovs-vsctl show
9318c35b-6aa6-4958-ba44-c45c1bd6b26c
    Bridge ovs_br0
        Port ovs_br0
            Interface ovs_br0
                type: internal
        Port eth0
            Interface eth0
    ovs_version: "3.2.1"

配置网桥ip,将原有网卡配置文件替换为以下内容

DEVICE="eth0"
ONBOOT="yes"
NM_CONTROLLED="no"

新建/etc/sysconfig/network-scripts/ifcfg-ovs_br0

TYPE="Ethernet"
DEVICE="ovs_br0"
ONBOOT=yes
NETBOOT=yes
BOOTPROTO=static
NM_CONTROLLED="no"
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=223.5.5.5
## ipv6配置
IPV6INIT=no
IPV6_AUTOCONF=no

将物理网卡eth0添加到 ovs_br0

ovs-vsctl add-port ovs_br0 eth0

执行完上面命令会断网,重启机器恢复

虚拟机相关配置

新建 /etc/libvirt/qemu/networks/ovs.xml:

<network>
  <name>ovs</name>
  <forward mode="bridge"/>
  <bridge name="ovs_br0"/>
  <virtualport type="openvswitch"/>
</network>

将配置文件加到virsh网络中

virsh net-define /etc/libvirt/qemu/networks/ovs.xml

image-20241115152352420

查看

virsh net-list --all

image-20241115152342112

启用ovs虚拟网卡

virsh net-start ovs

虚拟机选择相应网卡

image-20241115152335315