虚拟化逻辑架构:OVS 交换机与端口管理

目录

一、实验

1.OVS 交换机管理

2.OVS端口管理

二、问题

1.KVM下的br0和virbr0有何区别

2.OVS 虚拟交换机 与接口如何实现关联的创建和删除

3.两个ovs之间如何进行流量交互

4.虚拟网络如何和物理网络互联


一、实验

1.OVS 交换机管理

(1)查看网络信息

lo:本地回环接口

enp0s17 :  ubuntu系统识别到的物理网卡

virbr0/br1/virbr0-nic : linux bridge 网桥相关

root:~# ip add show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s17:  mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:d8:2a:24 brd ff:ff:ff:ff:ff:ff
    inet 192.168.31.20/24 brd 192.168.31.255 scope global dynamic noprefixroute enp0s17
       valid_lft 42599sec preferred_lft 42599sec
    inet6 fe80::f79a:6227:76ba:e22e/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: br1:  mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 3a:e1:3f:67:ea:22 brd ff:ff:ff:ff:ff:ff
4: virbr0:  mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:2f:20:d6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
5: virbr0-nic:  mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:2f:20:d6 brd ff:ff:ff:ff:ff:ff

(2)安装 openvswitch-switch

sudo apt-get install openvswitch-switch

(3)查看软件ID与软件版本

root:/# sudo ovs-vsctl show
e436b05b-210c-468a-9d94-fd63c6c419ed
    ovs_version: "2.9.8"

(4)创建OVS 虚拟交换机

ovs-vsctl add-br br0

(5)查看openvswitch

root:/# sudo ovs-vsctl show
e436b05b-210c-468a-9d94-fd63c6c419ed
    Bridge "br0"
        Port "br0"
            Interface "br0"
                type: internal
    ovs_version: "2.9.8"

(6)删除OVS 虚拟交换机并查看

ovs-vsctl del-br br0

(7)再次查看openvswitch。显示已删除

root:/# sudo ovs-vsctl show
e436b05b-210c-468a-9d94-fd63c6c419ed
    ovs_version: "2.9.8"

2.OVS端口管理

 (1)向br0 中添加 if01端口,并且绑定 if01接口,设置端口类型 internal类型

ovs-vsctl add-port br0 if01 -- set interface if01 type=internal

(2)将if01端口设置为access VLAN模式

ovs-vsctl set port if01 VLAN_mode=access 

(3)查看openvswitch

root:/# sudo ovs-vsctl show
e436b05b-210c-468a-9d94-fd63c6c419ed
    Bridge "br0"
        Port "if01"
            Interface "if01"
                type: internal
        Port "br0"
            Interface "br0"
                type: internal
    ovs_version: "2.9.8"

(4)查看网络信息

已新增br0和if01

root:/# ip addr show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s17:  mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:d8:2a:24 brd ff:ff:ff:ff:ff:ff
    inet 192.168.31.20/24 brd 192.168.31.255 scope global dynamic noprefixroute enp0s17
       valid_lft 39205sec preferred_lft 39205sec
    inet6 fe80::f79a:6227:76ba:e22e/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: br1:  mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 3a:e1:3f:67:ea:22 brd ff:ff:ff:ff:ff:ff
4: virbr0:  mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:2f:20:d6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
5: virbr0-nic:  mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:2f:20:d6 brd ff:ff:ff:ff:ff:ff
8: ovs-system:  mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 3a:6f:7f:57:9f:3d brd ff:ff:ff:ff:ff:ff
9: br0:  mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether ae:f5:0b:f1:b4:4c brd ff:ff:ff:ff:ff:ff
10: if01:  mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 96:1e:9c:4d:4d:62 brd ff:ff:ff:ff:ff:ff

(5)向br0 中添加 if02端口,并且绑定 if02接口,设置端口类型 internal类型

ovs-vsctl add-port br0 if02 -- set interface if02 type=internal

(6)查看openvswitch

root:/# sudo ovs-vsctl show
e436b05b-210c-468a-9d94-fd63c6c419ed
    Bridge "br0"
        Port "if02"
            Interface "if02"
                type: internal
        Port "if01"
            Interface "if01"
                type: internal
        Port "br0"
            Interface "br0"
                type: internal
    ovs_version: "2.9.8"

(7) 查看网络信息

root:/# ip addr show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s17:  mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:d8:2a:24 brd ff:ff:ff:ff:ff:ff
    inet 192.168.31.20/24 brd 192.168.31.255 scope global dynamic noprefixroute enp0s17
       valid_lft 39017sec preferred_lft 39017sec
    inet6 fe80::f79a:6227:76ba:e22e/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: br1:  mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 3a:e1:3f:67:ea:22 brd ff:ff:ff:ff:ff:ff
4: virbr0:  mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:2f:20:d6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
5: virbr0-nic:  mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:2f:20:d6 brd ff:ff:ff:ff:ff:ff
8: ovs-system:  mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 3a:6f:7f:57:9f:3d brd ff:ff:ff:ff:ff:ff
9: br0:  mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether ae:f5:0b:f1:b4:4c brd ff:ff:ff:ff:ff:ff
10: if01:  mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 96:1e:9c:4d:4d:62 brd ff:ff:ff:ff:ff:ff
11: if02:  mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 66:c9:a7:75:d2:d8 brd ff:ff:ff:ff:ff:ff

(8)删除名称为 br0的 ovs的if01端口

 ovs-vsctl del-port br0 if01

(9)查看openvswitch

root:/# sudo ovs-vsctl show
e436b05b-210c-468a-9d94-fd63c6c419ed
    Bridge "br0"
        Port "if02"
            Interface "if02"
                type: internal
        Port "br0"
            Interface "br0"
                type: internal
    ovs_version: "2.9.8"

(10)查看br0桥-OVS上的所有添加的port端口

root:/# ovs-vsctl list-ports br0
if02

(11)查看网络信息
显示端口if01已删除

root:/# ip addr show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s17:  mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:d8:2a:24 brd ff:ff:ff:ff:ff:ff
    inet 192.168.31.20/24 brd 192.168.31.255 scope global dynamic noprefixroute enp0s17
       valid_lft 38737sec preferred_lft 38737sec
    inet6 fe80::f79a:6227:76ba:e22e/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: br1:  mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 3a:e1:3f:67:ea:22 brd ff:ff:ff:ff:ff:ff
4: virbr0:  mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:2f:20:d6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
5: virbr0-nic:  mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:2f:20:d6 brd ff:ff:ff:ff:ff:ff
8: ovs-system:  mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 3a:6f:7f:57:9f:3d brd ff:ff:ff:ff:ff:ff
9: br0:  mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether ae:f5:0b:f1:b4:4c brd ff:ff:ff:ff:ff:ff
11: if02:  mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 66:c9:a7:75:d2:d8 brd ff:ff:ff:ff:ff:ff

(12)删除名称为 br0的 ovs的if02端口

 ovs-vsctl del-port br0 if02

(13)查看openvswitch

root:/# sudo ovs-vsctl show
e436b05b-210c-468a-9d94-fd63c6c419ed
    Bridge "br0"
        Port "br0"
            Interface "br0"
                type: internal
    ovs_version: "2.9.8"

(14)查看网络信息

root:/# ip addr show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s17:  mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:d8:2a:24 brd ff:ff:ff:ff:ff:ff
    inet 192.168.31.20/24 brd 192.168.31.255 scope global dynamic noprefixroute enp0s17
       valid_lft 38698sec preferred_lft 38698sec
    inet6 fe80::f79a:6227:76ba:e22e/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: br1:  mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 3a:e1:3f:67:ea:22 brd ff:ff:ff:ff:ff:ff
4: virbr0:  mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:2f:20:d6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
5: virbr0-nic:  mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:2f:20:d6 brd ff:ff:ff:ff:ff:ff
8: ovs-system:  mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 3a:6f:7f:57:9f:3d brd ff:ff:ff:ff:ff:ff
9: br0:  mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether ae:f5:0b:f1:b4:4c brd ff:ff:ff:ff:ff:ff

(15)删除名称为 br0的 ovs

ovs-vsctl del-br br0

(16)查看openvswitch

root:/# sudo ovs-vsctl show
e436b05b-210c-468a-9d94-fd63c6c419ed
    ovs_version: "2.9.8"

二、问题

1.KVM下的br0和virbr0有何区别

(1)KVM 的三种网络模式

桥接、仅主机、NAT

(2)区别

默认br0是桥接模式;

virbr0为NAT模式,它其实就是hypervisor的虚拟接口

2.OVS 虚拟交换机 与接口如何实现关联的创建和删除

(1)关联操作

#向br0 – OVS中添加 if01 端口,并且绑定  if01接口  ,设置端口类型 internal类型
ovs-vsctl add-port br0 if01   -- set interface  if01 type=internal

#将if01 端口设置为 access VLAN模式
ovs-vsctl set port if01 VLAN_mode=access

#查看br0桥-OVS上的所有添加的port端口
 ovs-vsctl  list-ports br0 

# 在ovs – br0 删除掉if01端口 (接口也删除)
ovs-vsctl   del-port  br0 if01

#为VM虚拟机配置IP地址
sudo ifconfig eth0 172.16.10.1 netmask 255.255.255.0

#查看br0的接口信息
ovs-ofctl show br0

#查看br0的MAC地址表(VLAN信息)
ovs-appctl  fdb/show br0

# 添加VLAN标记
ovs-vsctl  add port if01  tag 10  #将接口01划分到vlan10
ovs-vsctl  add port if02  tag 20  #将接口02划分到vlan20

#删除VLAN标记
ovs-vsctl  remove port if01  tag 10  #将接口01划分到vlan10

# 查看OVS数量-名称
ovs-vsctl list-br


3.两个ovs之间如何进行流量交互

(1)设置互联patch

#默认允许所有VLAN通过patch接口互联需要设置peer(对端)
ovs-vsctl add-port br0 patch-br0-br2 -- set interface patch-br0-br2 type=patch options:peer=patch-br2-br0

ovs-vsctl add-port br2 patch-br2-br0 -- set interface patch-br2-br0 type=patch options:peer=patch-br0-br2

4.虚拟网络如何和物理网络互联

(1)添加上行链路

#将一个物理网卡作为OVS虚拟交换机的上行链路,一个网卡作为虚拟交换机的上行链路后,该网卡直接作为OVS的一个逻辑接口,衔接物理和虚拟网络
ovs-vsctl add port  br0 enp0s17   #将enp0s17物理网卡绑定到br0虚拟交换机,作为一个ovs中的一个接口

ovs-ctl set port enp0s17 VLAN_mode=trunk

ovs-ctl set port enp0s17 trunk=10,20

你可能感兴趣的:(虚拟化逻辑架构,架构,运维,ubuntu)