今天发现还有另外的方法给ovs添加bridge、绑定网卡等操作,此前我都是这般操作ovs-vsctl add-br br-ex; ovs-vsctl add-port br-ex eth0,这样操作的结果会保存在openvswitch的conf.db里面。现在只需要在网卡配置文件中指定即可,适用于网卡数量较少,neutron网络模式gre、vxlan的local_ip要配置在br-ex的场景。
前提
yum install openvswitch -y # 安装openvswitch包 systemctl start openvswitch # 确保openvswitch服务启动
范例
cat /etc/sysconfig/network-scripts/ifcfg-br-ex DEVICE=br-ex BOOTPROTO=static ONBOOT=yes NM_CONTROLLED=no IPADDR=172.16.105.16 NETMASK=255.255.255.0 GATEWAY=172.16.105.254 TYPE=OVSBridge # 指定为OVSBridge类型 DEVICETYPE=ovs # 设备类型是ovs cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 ONBOOT=yes NM_CONTROLLED=no TYPE=OVSPort # 指定为OVSPort类型 DEVICETYPE=ovs # 设备类型是ovs OVS_BRIDGE=br-ex # 和br-ex ovs bridge关联 # 如果是在OpenStack in OpenStack的场景下,还需要设置mac地址 [root@trove-demo ~(keystone_admin)]# cat /etc/sysconfig/network-scripts/ifcfg-br-eth0 ONBOOT="yes" USERCTL="yes" PEERDNS="yes" PERSISTENT_DHCLIENT="1" DEVICE=br-eth0 DEVICETYPE=ovs OVSBOOTPROTO="dhcp" TYPE=OVSBridge OVSDHCPINTERFACES=eth0 OVS_EXTRA="set bridge br-eth0 other-config:hwaddr=fa:16:3e:ad:c6:f6" [root@trove-demo ~(keystone_admin)]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 DEVICETYPE=ovs TYPE=OVSPort OVS_BRIDGE=br-eth0 ONBOOT=yes BOOTPROTO=none
ovs-vsctl add-port br-ex eth0;systemctl restart network # 网络服务重启生效 [root@controller001 network-scripts(keystone_admin)]# ovs-vsctl show Bridge br-ex Port "eth0" Interface "eth0" # br-ex和eth0关联br-ex自动帮你都创建好了 # 如果是在openstack in openstack的环境下 ovs-vsctl set bridge br-ex other-config:hwaddr="<<eth0的mac地址>>" # 不然网络不通
这里注意下,centos 7系统默认rdo源的openvswitch包在内核升完级的情况下有个bug,详情见:https://bugzilla.redhat.com/show_bug.cgi?id=1185521
参考资料
《redhat openstack培训教材》