Linux系统安装
安装时勾选虚拟机主机服务。
OVS虚拟交换机软件安装
$ sudo zypper in openvswitch ///opensuse
$ sudo dnf install centos-release-nfv-openvswitch ///centos默认源不包含,需安装该repo
$ sudo dnf repolist all ///检查源centos-nfv-openvswitch是否启用
$ sudo dnf search openvswitch ///搜索OVS软件包
$ sudo dnf install openvswitch2.13 ///一般选择最新版本安装
///dnf为最新的rhel centos fedora包管理,老版本替换为yum
检查系统服务
$ systemctl status libvirtd ///虚拟化接口服务
$ systemctl status openvswitch ///OVS服务
///确保服务开机自启并处于运行状态
OVS配置
opensuse
网络选用wicked管理,参考链接https://en.opensuse.org/Portal:Wicked/OpenvSwitch
///生成ovs桥并绑定到物理网口,假定物理网口名为eth0,ovs桥命名为ovsbr
$ sudo ovs-vsctl add-br ovsbr
$ sudo ovs-vsctl add-port ovsbr eth0
///修改物理网口网络配置文件
# /etc/sysconfig/network/ifcfg-eth0
STARTMODE='auto'
BOOTPROTO='none'
///ovs创建桥时默认会自动创建同名称的虚拟内部网络接口供虚拟化主机通信
///因此,创建新的网络配置文件,用于物理主机访问网络
# /etc/sysconfig/network/
$ sudo touch ifcfg-ovsbr
STARTMODE='auto'
BOOTPROTO=dhcp
OVS_BRIDGE='yes'
OVS_BRIDGE_PORT_DEVICE='eth0'
///重启网络使配置生效
$ sudo systemctl restart network
///检查网络状态,正常如下显示
$ ip a
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master ovs-system state UP group default qlen 1000
3: ovs-system: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
4: ovsbr: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
inet xxx.xxx.xxx.xxx/xx brd xxx.xxx.xxx.xxx scope global
valid_lft forever preferred_lft forever
inet6 xxxx::xxxx:xxxx:xxxx:xxxx/64 scope link
valid_lft forever preferred_lft forever
rhel centos fedora
网络采用NetworkManager管理,参考链接https://developer.gnome.org/NetworkManager/stable/nm-openvswitch.html
老版本采用的network-scripts从rhel8开始弃用,不推荐使用
///nm是直接写数据到ovs数据库,因此,需要手动创建ovs桥,端口(port)及接口(interface)
$ nmcli conn add type ovs-bridge conn.interface ovsbr ///创建ovs桥
$ nmcli conn add type ovs-port conn.interface ovsbr master ovsbr ///创建内部port
$ nmcli conn add type ovs-interface slave-type ovs-port conn.interface ovsbr \
master ovsbr ipv4.method auto ///创建内部interface,并采用dhcp获取ip
$ nmcli conn add type ovs-port conn.interface eth0 master ovsbr ///创建物理网口port
$ nmcli conn add type ethernet conn.interface eth0 master eth0 ///绑定到物理网口interface
$ sudo systemctl restart NetworkManager ///重启网络服务使配置生效
///ovs接口状态如下
$ sudo ovs-vsctl show
Bridge ovsbr
Port ovsbr
Interface ovsbr
type: internal
Port eth0
Interface eth0
ovs_version: "2.14.2"
libvirt绑定ovs
$ sudo virsh net-list ///列出当前虚拟化中定义的网络
$ sudo virsh net-edit network ///编辑名称为network的网络
<network>
<name>ovsbr</name>
<uuid></uuid>
<forward mode='bridge'/>
<bridge name='ovsbr'/>
<virtualport type='openvswitch'/>
</network>
///配置文件为xml格式,转发模式改为bridge,桥名称即为ovs桥名称,虚拟端口类型为openvswitch
到此,基本完成配置,后续创建虚拟机时,将网络指向此处即可。