公司的系统是基于kvm的,基本是一台物理及虚拟出十台kvm来用,网络是基于linux bridge的,现在想改用 Open vSwitch ,来改改看:

基本场景:一开始装好的基本系统是没有bridge的,只有eth0配了ip地址,连接到交换机。

先生成ovs 网桥:

ovs-vsctl add-br ovsbr0  

将ovsbr0和eth0加入网桥:

ovs-vsctl add-port ovsbr0 eth0  

注意,执行add-port命令的时候如果是远程,就死定了,网络会断开。所以最好还是在配置文件里把ovs的配置给固定下来。

将eth0的地址交给ovsbr0来处理:

ifconfig eth0 0.0.0.0  
ifconfig ovsbr0 192.168.100.1/24  

看一下结果:

ovs-vsctl show  
79437d32-5f9f-48bf-a2cf-42d87374bd4b  
    Bridge "ovsbr0"
        Port "eth0"
            Interface "eth0"
        Port "ovsbr0"
            Interface "ovsbr0"
                type: internal
    ovs_version: "2.3.1"

shutdown已有的虚机kvm01

virsh shutdown kvm01  

编辑kvm01的配置:

virsh edit kvm01  

修改source bridge,增加virtualport这两个地方,如下:

        <interface type='bridge'>
                <mac address='52:54:00:ad:c1:7c'/>
                +<source bridge='ovsbr0'/>
                +<virtualport type='openvswitch'>
                <model type='virtio'/>
                <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
        </interface>

保存后virsh会自动给virtualport加个interface id的:

virsh dumpxml host01 | grep bridge -A8  
    <interface type='bridge'>
      <mac address='52:54:00:ad:c1:7c'/>
      <source bridge='ovsbr0'/>
      <virtualport type='openvswitch'>
        +<parameters interfaceid='81d6a11b-e89e-9037-f6bb-994b2fbc9dcc'/>
      </virtualport>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>

最后重启kvm01即可,网络层已经变成Open vSwitch了:

virsh start kvm01  

再次查看ovs,会看到vnetx的信息:

# ovs-vsctl show
  238d066c-8354-4978-a9f4-39a98fa2d2e9
      Bridge "ovsbr0"
          Port "eth0"
              Interface "eth0"
          Port "ovsbr0"
              Interface "ovsbr0"
                  type: internal
          Port "vnet0"
              Interface "vnet0"
                  ovs_version: "1.4.2"
comments powered by Disqus