您好,欢迎访问一九零五行业门户网

深入理解openstack网络架构(2)

https://blogs.oracle.com/ronen/entry/diving_into_openstack_network_architecture1 在这些use case中,我们会了解整个网络配置和他们如何一起运行。use case如下: 创建网络——我们创建网络时,发生了什么。如何创建多个隔离的网络。 创建虚拟机——一旦
https://blogs.oracle.com/ronen/entry/diving_into_openstack_network_architecture1
在这些use case中,我们会了解整个网络配置和他们如何一起运行。use case如下:
创建网络——我们创建网络时,发生了什么。如何创建多个隔离的网络。
创建虚拟机——一旦我们有了网络,我们可以创建虚拟机并将其接入网络。
虚拟机的dhcp请求——opensack可以自动为虚拟机配置ip。通过openstack neutron控制的dhcp服务完成。我们来了解这个服务如何运行,dhcp请求和回应是什么样子的?
这篇文章中,我们会展示网络连接的原理,我们会了解网络包如何从a到b。我们先了解已经完成的网络配置是什么样子的?然后我们讨论这些网络配置是如何以及何时创建的?我个人认为,通过例子和具体实践看到真实的网络接口如何工作以及如何将他们连接起来是非常有价值的。然后,一切真相大白,我们知道网络连接如何工作,在后边的文章中,我将进一步解释neutron如何配置这些组件,从而提供这样的网络连接能力。
我推荐在你自己的环境上尝试这些例子或者使用oracle openstack tech preview。完全理解这些网络场景,对我们调查openstack环境中的网络问题非常有帮助。
use case #1: create network创建network的操作非常简单。我们可以使用gui或者命令行完成。openstack的网络仅供创建该网络的租户使用。当然如果这个网络是“shared”,它也可以被其他所有租户使用。一个网络可以有多个subnets,但是为了演示目的和简单,我们仅为每一个network创建一个subnet。通过命令行创建network:
# neutron net-create net1created a new network:+---------------------------+--------------------------------------+| field | value |+---------------------------+--------------------------------------+| admin_state_up | true || id | 5f833617-6179-4797-b7c0-7d420d84040c || name | net1 || provider:network_type | vlan || provider:physical_network | default || provider:segmentation_id | 1000 || shared | false || status | active || subnets | || tenant_id | 9796e5145ee546508939cd49ad59d51f |+---------------------------+--------------------------------------+
为这个network创建subnet::
# neutron subnet-create net1 10.10.10.0/24created a new subnet:+------------------+------------------------------------------------+| field | value |+------------------+------------------------------------------------+| allocation_pools | {start: 10.10.10.2, end: 10.10.10.254} || cidr | 10.10.10.0/24 || dns_nameservers | || enable_dhcp | true || gateway_ip | 10.10.10.1 || host_routes | || id | 2d7a0a58-0674-439a-ad23-d6471aaae9bc || ip_version | 4 || name | || network_id | 5f833617-6179-4797-b7c0-7d420d84040c || tenant_id | 9796e5145ee546508939cd49ad59d51f |+------------------+------------------------------------------------+
现在我们有了一个network和subnet,网络拓扑像这样:
现在让我们深入看下到底发生了什么?在控制节点,我们一个新的namespace被创建:
# ip netns listqdhcp-5f833617-6179-4797-b7c0-7d420d84040c
这个namespace的名字是qdhcp- (参见上边),让我们深入namespace中看看有什么?
# ip netns exec qdhcp-5f833617-6179-4797-b7c0-7d420d84040c ip addr1: lo: mtu 65536 qdisc noqueue state unknown link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever12: tap26c9b807-7c: mtu 1500 qdisc noqueue state unknown link/ether fa:16:3e:1d:5c:81 brd ff:ff:ff:ff:ff:ff inet 10.10.10.3/24 brd 10.10.10.255 scope global tap26c9b807-7c inet6 fe80::f816:3eff:fe1d:5c81/64 scope link valid_lft forever preferred_lft forever
我们发下在namespace下有两个网络接口,一个是loop设备,另一个叫“tap26c9b807-7c”。这个接口设置了ip地址10.10.10.3,他会接收dhcp请求(后边会讲)。接下来我们来跟踪下“tap26c9b807-7c”的网络连接性。我们从ovs上看下这个接口所连接的ovs网桥br-int。
# ovs-vsctl show8a069c7c-ea05-4375-93e2-b9fc9e4b3ca1 bridge br-eth2 port br-eth2 interface br-eth2 type: internal port eth2 interface eth2 port phy-br-eth2 interface phy-br-eth2 bridge br-ex port br-ex interface br-ex type: internal bridge br-int port int-br-eth2 interface int-br-eth2 port tap26c9b807-7c tag: 1 interface tap26c9b807-7c type: internal port br-int interface br-int type: internal ovs_version: 1.11.0
# ethtool -s int-br-eth2nic statistics: peer_ifindex: 10.. #ip link..10: phy-br-eth2: mtu 1500 qdisc pfifo_fast state up qlen 1000..
注意“phy-br-eth2”连接到网桥br-eth2,这个网桥的一个网口是物理网卡eth2。这意味着我们创建的网络创建了一个连接到了物理网卡eth2的namespace。eth2所在的虚拟机网络会连接所有的虚拟机的。
关于网络隔离:
# ovs-ofctl dump-flows br-eth2nxst_flow reply (xid=0x4): cookie=0x0, duration=18669.401s, table=0, n_packets=857, n_bytes=163350, idle_age=25, priority=4,in_port=2,dl_vlan=1 actions=mod_vlan_vid:1000,normal cookie=0x0, duration=165108.226s, table=0, n_packets=14, n_bytes=1000, idle_age=5343, hard_age=65534, priority=2,in_port=2 actions=drop cookie=0x0, duration=165109.813s, table=0, n_packets=1671, n_bytes=213304, idle_age=25, hard_age=65534, priority=1 actions=normal
# ovs-ofctl dump-flows br-intnxst_flow reply (xid=0x4): cookie=0x0, duration=18690.876s, table=0, n_packets=1610, n_bytes=210752, idle_age=1, priority=3,in_port=1,dl_vlan=1000 actions=mod_vlan_vid:1,normal cookie=0x0, duration=165130.01s, table=0, n_packets=75, n_bytes=3686, idle_age=4212, hard_age=65534, priority=2,in_port=1 actions=drop cookie=0x0, duration=165131.96s, table=0, n_packets=863, n_bytes=160727, idle_age=1, hard_age=65534, priority=1 actions=normal
use case #2: launch a vm从horizon或者命令行创建并启动一个虚拟机,下图是从horzion创建的例子:
挂载网络并启动虚拟机:
一旦虚拟机启动并运行,我们发下nova支持给虚拟机绑定ip:
# nova list+--------------------------------------+--------------+--------+------------+-------------+-----------------+| id | name | status | task state | power state | networks |+--------------------------------------+--------------+--------+------------+-------------+-----------------+| 3707ac87-4f5d-4349-b7ed-3a673f55e5e1 | oracle linux | active | none | running | net1=10.10.10.2 |+--------------------------------------+--------------+--------+------------+-------------+-----------------+
nova list命令显示虚拟机在运行中,并被分配了ip 10.10.10.2。我们通过虚拟机定义文件,查看下虚拟机与虚拟机网络之间的连接性。虚拟机的配置文件在目录/var/lib/nova/instances//下可以找到。通过查看虚拟机定义文件,libvirt.xml,我们可以看到虚拟机连接到网络接口“tap53903a95-82”,这个网络接口连接到了linux网桥 “qbr53903a95-82”:

通过brctl查看网桥信息如下:
# brctl showbridge name bridge id stp enabled interfacesqbr53903a95-82 8000.7e7f3282b836 no qvb53903a95-82 tap53903a95-82
网桥有两个网络接口,一个连接到虚拟机(“tap53903a95-82 “),另一个( “qvb53903a95-82”)连接到ovs网桥”br-int。
# ovs-vsctl show83c42f80-77e9-46c8-8560-7697d76de51c bridge br-eth2 port br-eth2 interface br-eth2 type: internal port eth2 interface eth2 port phy-br-eth2 interface phy-br-eth2 bridge br-int port br-int interface br-int type: internal port int-br-eth2 interface int-br-eth2 port qvb53903a95-82 tag: 3 interface qvb53903a95-82 ovs_version: 1.11.0
我们之前看过,ovs网桥“br-int连接到br-eth2,通过veth pair(int-br-eth2,phy-br-eth2 ),br-eth2连接到物理网卡eth2。整个流入如下:
vm -> tap53903a95-82 (virtual interface) -> qbr53903a95-82 (linux bridge) -> qvb53903a95-82 (interface connected from linux bridge to ovs bridge br-int) -> int-br-eth2 (veth one end) -> phy-br-eth2 (veth the other end) -> eth2 physical interface.
与虚拟机相连的linux bridage主要用于基于iptables的安全组设置。安全组用于对虚拟机的网络隔离进行增强,由于iptables不能用于ovs网桥,因此我们使用了linux网桥。后边我们会看到linux网桥的规则设置。 use case #3: serving a dhcp request coming from the virtual machine
namespace与虚拟机之间连通,并且可以互相ping通,对于定位问题非常有用。我们可以从虚拟机ping通namespace,可以使用tcpdump或其他工具定位网络中断问题。
为了响应虚拟机的dhcp请求,neutron使用了”dnsmasq“的linux工具,这个工具是一个轻量的dns、dhcp服务,更多的信息请查看(http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html)。我们可以在控制节点通过ps命令看到:
dnsmasq --no-hosts --no-resolv --strict-order --bind-interfaces --interface=tap26c9b807-7c --except-interface=lo --pid-file=/var/lib/neutron/dhcp/5f833617-6179-4797-b7c0-7d420d84040c/pid --dhcp-hostsfile=/var/lib/neutron/dhcp/5f833617-6179-4797-b7c0-7d420d84040c/host --dhcp-optsfile=/var/lib/neutron/dhcp/5f833617-6179-4797-b7c0-7d420d84040c/opts --leasefile-ro --dhcp-range=tag0,10.10.10.0,static,120s --dhcp-lease-max=256 --conf-file= --domain=openstacklocal
dhcp服务在namespace中连接到了一个tap接口(“--interface=tap26c9b807-7c”),从hosts文件我们可以看到:
# cat /var/lib/neutron/dhcp/5f833617-6179-4797-b7c0-7d420d84040c/hostfa:16:3e:fe:c7:87,host-10-10-10-2.openstacklocal,10.10.10.2
之前的console输出可以看到虚拟机mac为fa:16:3e:fe:c7:87 。这个mac地址与ip 10.10.10.2 关联,当包含该mac的dhcp请求到达,dnsmasq返回10.10.10.2。在这个初始过程(可以重启网络服务触发)中从namespace中看,可以看到如下的dhcp请求:# ip netns exec qdhcp-5f833617-6179-4797-b7c0-7d420d84040c tcpdump -n19:27:12.191280 ip 0.0.0.0.bootpc > 255.255.255.255.bootps: bootp/dhcp, request from fa:16:3e:fe:c7:87, length 31019:27:12.191666 ip 10.10.10.3.bootps > 10.10.10.2.bootpc: bootp/dhcp, reply, length 325
总之,dhcp服务由dnsmasq提供,这个服务由neutron配置,监听在dhcp namespace中的网络接口上。neutron还配置dnsmasq中的mac/ip映射关系,所以当dhcp请求时会受到分配给它的ip。 总结本文,我们基于之前讲解的各种网络组件,分析了三种use case下网络如何连通的。这些use cases对了解整个网络栈以及了解虚拟机/计算节点/dhcp namespace直接如何连通很有帮助。
根据我们的分析,我们确信启动虚拟机、虚拟机发出dhcp请求、虚拟机收到正确的ip后这个网络按照我们预想的工作。我们看到一个包经过一长串路径最终到达目的地,如果这一切成功,意味着这些组件功能正常。
其它类似信息

推荐信息