本篇文章介绍如何规划及创建openvswitch+vlan网络,实现实例间及实例与外部的通讯。读者应对OpenStack及其网络服务Neutron有初步的了解。

1.规划网络

部署节点为一个controller节点(包含网络节点),两个compute节点。controller节点有3个网卡,分别为eth0(管理和API网络,CIDR为11.11.175.0/24)、eth1(租户网络,不设置IP)、eth2(外部网络,CIDR为10.10.10.0/24,不设置IP);compute节点有2个网卡,分别为eth0(管理和API网络,CIDR为11.11.175.0/24)、eth1(租户网络,不设置IP)。  
Neutron总结-openvswitch+vlan网络

Neutron ML2的Type Driver为vlan  
Neutron ML2的Mechanism Driver为Open vSwitch  
Neutron L2 Agent为Open vSwitch 
Neutron总结-openvswitch+vlan网络

2.创建虚拟网络

修改配置文件 
/etc/neutron/plugins/ml2/ml2_conf.ini 
Neutron总结-openvswitch+vlan网络
controller 节点 /etc/neutron/plugins/ml2/openvswitch_agent.ini 
注意:这里没有用到vxlan网络,enable_vxlan必须设置为False,否则会报错。 
Neutron总结-openvswitch+vlan网络
compute 节点 /etc/neutron/plugins/ml2/openvswitch_agent.ini 
注意:这里没有用到vxlan网络,enable_vxlan必须设置为False,否则会报错。 
Neutron总结-openvswitch+vlan网络 
/etc/neutron/l3_agent.ini 
Neutron总结-openvswitch+vlan网络
/etc/neutron/dhcp_agent.ini 
Neutron总结-openvswitch+vlan网络

准备ovs网桥 
controller节点

  • 创建 br-eth1 
  • 将物理网卡 eth1 桥接在 br-eth1 上 
  • 创建 br-ex 
  • 将物理网卡 eth2 桥接在 br-ex 上

Neutron总结-openvswitch+vlan网络

compute节点

  • 创建 br-eth1 
  • 将物理网卡 eth1 桥接在 br-eth1 上 
    Neutron总结-openvswitch+vlan网络

重启网络相关服务。

登陆到dashboard,可以查看网络服务信息。  
controller节点启动了 neturon-metadata-agent、neutron-l3-agent、neutron-openvswitch-agent、neutron-dhcp-agent  
compute节点启动了 neutron-openvswitch-agent 

Neutron总结-openvswitch+vlan网络

创建vlan100网络,物理网络为provider(和前面的配置一致,否则报错),网络地址为172.16.100.0/24  
Neutron总结-openvswitch+vlan网络

创建vlan101网络,物理网络为provider(和前面的配置一致,否则报错),网络地址为172.16.101.0/24  
Neutron总结-openvswitch+vlan网络

创建外部网络,物理网络为external(和前面的配置一致,否则报错),网络地址为10.10.10.0/24  
Neutron总结-openvswitch+vlan网络

创建路由器,把vlan网络和外部网络连通  
Neutron总结-openvswitch+vlan网络

我们的网络环境就准备好了。

3.测试网络

创建3个实例,2个选择vlan100网络,1个选择vlan101网络。  
其中:test1、test3被调度到compute1节点,test2被调度到compute2节点。  
Neutron总结-openvswitch+vlan网络

查看网络拓扑。两个vlan网络均通过路由器连接到了外网,并且两个vlan网络也通过路由器连接。所以理论上test1、test2、test3能互通,并且也能连通外部网络。  
Neutron总结-openvswitch+vlan网络

为了保证外部能ping通以及能ssh登陆到实例,需要在安全组那加两条规则  
Neutron总结-openvswitch+vlan网络

下面测试网络的连通性:

同一VLAN:172.16.100.13 ping 172.16.100.14 
Neutron总结-openvswitch+vlan网络

不同VLAN:172.16.100.13 ping 172.16.101.13 
Neutron总结-openvswitch+vlan网络

外网:172.16.100.13 ping 10.10.10.100 (确保外网相同网段有一台机器)  
Neutron总结-openvswitch+vlan网络

查看各个节点上面的虚拟网络设备

controller节点  
Neutron总结-openvswitch+vlan网络

compute1节点  
Neutron总结-openvswitch+vlan网络

compute2节点  
Neutron总结-openvswitch+vlan网络

controller节点1个Router、2个DHCP分别在各自的namespace下  
可以通过exec查看router细节  
Neutron总结-openvswitch+vlan网络

router的iptables  
Neutron总结-openvswitch+vlan网络

可以通过exec查看dhcp细节  
Neutron总结-openvswitch+vlan网络

再看下详细的网络结构  
controller节点 
Neutron总结-openvswitch+vlan网络

compute节点  
Neutron总结-openvswitch+vlan网络

如果需要从外部网络访问虚拟机,则要添加Floating IP  
test1添加floating IP为10.10.10.11  
Neutron总结-openvswitch+vlan网络

测试网络连通:  
外网:10.10.10.100 ping 10.10.10.11  
Neutron总结-openvswitch+vlan网络

外网:10.10.10.100 ssh登录到 10.10.10.11  
Neutron总结-openvswitch+vlan网络

查看controller节点router的变化  
Neutron总结-openvswitch+vlan网络

iptables  
Neutron总结-openvswitch+vlan网络

了解OVS如何实现VLAN隔离

Open vSwitch 通过 flow rule(流规则)来指定如何对进出 br-int 的数据进行转发,进而实现 vlan 之间的隔离。当数据进出 br-int 时,flow rule 可以修改、添加或者剥掉数据包的 VLAN tag,Neutron 负责创建这些 flow rule 并将它们配置到 br-int,br-eth1 等 Open vSwitch 上。 
Neutron总结-openvswitch+vlan网络

br-eth1 上配置了四条 rule,每条 rule 有不少属性,其中比较重要的属性有:

  • priority:rule 的优先级,值越大优先级越高。Open vSwitch 会按照优先级从高到低应用规则。
  • in_port:inbound 端口编号,每个 port 在 Open vSwitch 中会有一个内部的编号。可以通过命令ovs-ofctl show 查看 port 编号。比如 br-eth1:eth1 编号为 1;phy-br-eth1 编号为 2。
  • dl_vlan:数据包原始的 VLAN ID。 
  • actions:对数据包进行的操作。 
    Neutron总结-openvswitch+vlan网络

br-eth1 跟 VLAN 相关的 flow rule 是前面两条。清晰起见,我们只保留重要的信息,如下: 
priority=4,in_port=2,dl_vlan=1 actions=mod_vlan_vid:100,NORMAL 
priority=4,in_port=2,dl_vlan=5 actions=mod_vlan_vid:101,NORMAL

Neutron总结-openvswitch+vlan网络

第一条的含义是:从 br-eth1 的端口 phy-br-eth1(in_port=2)接收进来的包,如果 VLAN ID 是 1(dl_vlan=1),那么需要将 VLAN ID 改为 100(actions=mod_vlan_vid:100)

再看br-int的 flow rule 
ovs-ofctl dump-flows br-int 
Neutron总结-openvswitch+vlan网络

priority=3,inport=2,dl_vlan=100 actions=mod_vlan_vid:1,NORMAL 
priority=3,inport=2,dl_vlan=101 actions=mod_vlan_vid:2,NORMAL 
Neutron总结-openvswitch+vlan网络 
含义:从物理网卡接收进来的数据包,如果 VLAN 为 100,则改为内部 VLAN 1;从物理网卡接收进来的数据包,如果 VLAN 为 101,则将为内部 VLAN 2

这样我们就创建并且测试了Open vSwitch+vlan网络,验证了网络的连通性。并对Neutron虚拟网络实现的细节进行了描述,希望对大家有帮助。

在Neutron的学习总结过程中,参考了网络上面的大量有价值的文档,在这里对无私分享的同学们表示衷心感谢!尤其是《每天5分钟学习OpenStack》,写的非常详细,本篇文档主要参考了里面的内容,在这里重点推荐:)。

相关文章:

  • 2022-01-07
  • 2021-12-30
  • 2021-08-05
  • 2022-12-23
  • 2021-12-09
  • 2021-05-29
猜你喜欢
  • 2021-10-19
  • 2021-05-15
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2021-09-30
相关资源
相似解决方案