硬件环境:仍是使用四节点OpenStack部署环境,参见 http://www.cnblogs.com/sammyliu/p/4190843.htmlhtml
OpenStack配置:node
使用 http://www.cnblogs.com/sammyliu/p/4201143.html 中相同的方法,画出Neutron节点上网络组件图:算法
可见:数据库
(1). 关于Neutron上的三种Agent的做用:cookie
(2). Neutorn节点上一样有OVS Tunnel bridge br-tun和OVS Integration bridge br-int,多了br-ex来提供外部网络链接,br-ex和物理网卡eth0绑定。这里出现的一个问题是eth0的IP没法ping通,OVS提供的解决方法以下。究其缘由,一块物理以太网卡若是做为 OpenvSwitch bridge 的一部分,则它不能拥有 IP 地址,若是有,也会彻底不起做用。若是发生了上述状况,能够将 IP 地址绑定至某 OpenvSwitch “internal” 设备来恢复网络访问功能。网络
ifconfig eth0 0.0.0.0 ifconfig br-ex 192.168.1.19
(3). Neutron使用Linux network namespace来实现tenant之间的网络隔离。本例中有三个network namespace,每一个network namspace包括router,dhcp,interface,routing tables,iptable rules等。dom
root@network:/home/s1# ip netns qdhcp-d24963da-5221-481e-adf5-fe033d6e0b4e qrouter-e506f8fe-3260-4880-bd06-32246225aeae qdhcp-d04a0a06-7206-4d05-9432-3443843bc199 qrouter-33e2b1bf-04cb-4811-9c58-7e03856022c1 qrouter-9ba04071-f32b-435e-8f44-e32936568102 qdhcp-0a4cd030-d951-401a-8202-937b788bea43
(4). Neutron 为每个 network 分配一个本地的 VLAN ID,每一个 network 分配一个 network namespace,该DHCP 经过一个 tap 链接在 br-int 上,该 tap 的 tag 为该 local VLAN ID。H1/H2/H3端口上分布有不一样的VLAN ID。 tcp
#在存在多个 network 的状况下,br-int 上DHCP namespace 端口的 tag 状况 Port "tap0f45d165-9f" tag: 5 Interface "tap0f45d165-9f" type: internal Port "tap89874f55-97" tag: 4 Interface "tap89874f55-97" type: internal Port "tap5522533d-fe" tag: 3 Interface "tap5522533d-fe" type: internal Port "tap56c9730c-9c" tag: 4095 Interface "tap56c9730c-9c" type: internal Port "tap1fd04a93-09" tag: 4095 Interface "tap1fd04a93-09" type: internal Port "tap777c1047-ed" tag: 2 Interface "tap777c1047-ed" type: internal Port "tap3fca96e0-c6" tag: 1 Interface "tap3fca96e0-c6" type: internal
插播Mac地址的基础知识:分布式
root@network:/home/s1# ovs-ofctl dump-flows br-tunide
NXST_FLOW reply (xid=0x4):
cookie=0x0, duration=33.236s, table=0, n_packets=0, n_bytes=0, idle_age=33, priority=1,in_port=1 actions=resubmit(,2) //从H1进来的traffic,到table 2
cookie=0x0, duration=32.131s, table=0, n_packets=0, n_bytes=0, idle_age=32, priority=1,in_port=2 actions=resubmit(,3) //从GRE端口进来的traffic,到table 3
cookie=0x0, duration=33.178s, table=0, n_packets=6, n_bytes=480, idle_age=24, priority=0 actions=drop
cookie=0x0, duration=33.121s, table=2, n_packets=0, n_bytes=0, idle_age=33, priority=0,dl_dst=00:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,20) //目的地址为单播地址,到table 20
cookie=0x0, duration=33.066s, table=2, n_packets=0, n_bytes=0, idle_age=33, priority=0,dl_dst=01:00:00:00:00:00/01:00:00:00:00:00 actions=resubmit(,22) //目的地址为组播(包括广播)地址,到table 22
cookie=0x0, duration=30.614s, table=3, n_packets=0, n_bytes=0, idle_age=30, priority=1,tun_id=0x1 actions=mod_vlan_vid:1,resubmit(,10) //Tunnel 1的traffic,修改VLAN ID 为 1, 再到 table 10
cookie=0x0, duration=29.291s, table=3, n_packets=0, n_bytes=0, idle_age=29, priority=1,tun_id=0x2 actions=mod_vlan_vid:3,resubmit(,10) //Tunnel 2的traffic,修改VLAN ID 为 2, 再到 table 10
cookie=0x0, duration=30.241s, table=3, n_packets=0, n_bytes=0, idle_age=30, priority=1,tun_id=0x3 actions=mod_vlan_vid:2,resubmit(,10) //Tunnel 3的traffic,修改VLAN ID 为 3, 再到 table 10
cookie=0x0, duration=33.001s, table=3, n_packets=0, n_bytes=0, idle_age=33, priority=0 actions=drop
cookie=0x0, duration=32.932s, table=4, n_packets=0, n_bytes=0, idle_age=32, priority=0 actions=drop
cookie=0x0, duration=32.874s, table=10, n_packets=0, n_bytes=0, idle_age=32, priority=1 actions=learn(table=20,hard_timeout=300,priority=1,NXM_OF_VLAN_TCI[0..11],NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],load:0->NXM_OF_VLAN_TCI[],load:NXM_NX_TUN_ID[]->NXM_NX_TUN_ID[],output:NXM_OF_IN_PORT[]),output:1 //学习一条新的规则添加到table 20,发到端口1,进入br-int
cookie=0x0, duration=32.815s, table=20, n_packets=0, n_bytes=0, idle_age=32, priority=0 actions=resubmit(,22) //到table 22
cookie=0x0, duration=29.35s, table=22, n_packets=0, n_bytes=0, idle_age=29, dl_vlan=3 actions=strip_vlan,set_tunnel:0x2,output:2
cookie=0x0, duration=30.293s, table=22, n_packets=0, n_bytes=0, idle_age=30, dl_vlan=2 actions=strip_vlan,set_tunnel:0x3,output:2
cookie=0x0, duration=30.682s, table=22, n_packets=0, n_bytes=0, idle_age=30, dl_vlan=1 actions=strip_vlan,set_tunnel:0x1,output:2 //以上三条rule,根据目的VLAN ID,修改Tunnel ID,并去掉VLAN ID,发到GRE端口,通过GRE Tunnel到compute node
cookie=0x0, duration=32.752s, table=22, n_packets=0, n_bytes=0, idle_age=32, priority=0 actions=drop
总之,br-tun会:
root@network:/home/s1# ip netns exec qrouter-33e2b1bf-04cb-4811-9c58-7e03856022c1 ip addr 22: qr-d3d3e235-d4: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default link/ether fa:16:3e:b3:06:e8 brd ff:ff:ff:ff:ff:ff inet 10.0.11.1/24 brd 10.0.11.255 scope global qr-d3d3e235-d4 valid_lft forever preferred_lft forever inet6 fe80::f816:3eff:feb3:6e8/64 scope link valid_lft forever preferred_lft forever 26: qg-6c06581b-bd: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default link/ether fa:16:3e:0b:ac:82 brd ff:ff:ff:ff:ff:ff inet 192.168.1.114/24 brd 192.168.1.255 scope global qg-6c06581b-bd valid_lft forever preferred_lft forever inet 192.168.1.115/32 brd 192.168.1.115 scope global qg-6c06581b-bd valid_lft forever preferred_lft forever inet6 fe80::f816:3eff:fe0b:ac82/64 scope link valid_lft forever preferred_lft forever
可见:
再看看它的route规则:
root@network:/home/s1# ip netns exec qrouter-33e2b1bf-04cb-4811-9c58-7e03856022c1 route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 qg-6c06581b-bd
//默认路由,全部目的地址不在本网络中的traffic都要经过 qg-d3657c7f-28 interface 发到外网网关192.168.1.1
10.0.11.0 0.0.0.0 255.255.255.0 U 0 0 0 qr-d3d3e235-d4
//目的为本子网内的traffic 通过 qr-d3d3e235-d4 发到子网网关 10.0.11.1
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 qg-6c06581b-bd
//目的为 192.168.1.0/24 的traffic经过 qg-6c06581b-bd 发到网关192.168.1.100
Router namespace中的 netfilter NAT 表负责 Neutron Floating IP 的实现。下面是tenant-two (有两个虚机)的router的NAT表:
每个有DHCP的网络都在Neutron节点上有一个DHCP服务,每一个DHCP Server都是一个运行在一个network namespace中的dnsmasq进程。 dnsmasq是一个用在Linux上的轻型DNS和DHCP服务,具体见 http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html.
nobody 2049 1 0 06:43 ? 00:00:00 dnsmasq --no-hosts --no-resolv --strict-order --bind-interfaces --interface=tap15865c29-9b --except-interface=lo --pid-file=/var/lib/neutron/dhcp/d24963da-5221-481e-adf5-fe033d6e0b4e/pid --dhcp-hostsfile=/var/lib/neutron/dhcp/d24963da-5221-481e-adf5-fe033d6e0b4e/host --addn-hosts=/var/lib/neutron/dhcp/d24963da-5221-481e-adf5-fe033d6e0b4e/addn_hosts --dhcp-optsfile=/var/lib/neutron/dhcp/d24963da-5221-481e-adf5-fe033d6e0b4e/opts --leasefile-ro --dhcp-range=set:tag0,10.0.22.0,static,86400s --dhcp-lease-max=256 --conf-file= --domain=openstacklocal
说明:
1. --interface=tap15865c29-9b: 该process绑定/监听一个TAP设备,即上图中的 H3
2. --dhcp-hostsfile=/var/lib/neutron/dhcp/d24963da-5221-481e-adf5-fe033d6e0b4e/host:
root@network:/home/s1# cat /var/lib/neutron/dhcp/d24963da-5221-481e-adf5-fe033d6e0b4e/host
fa:16:3e:4d:6b:44,host-10-0-22-201.openstacklocal,10.0.22.201 //本子网DHCP Server本身(M3)的Mac地址以及IP
fa:16:3e:79:07:5e,host-10-0-22-1.openstacklocal,10.0.22.1 //本子网Router Server ( N3) 的Mac地址,名字和 IP
fa:16:3e:bf:69:36,host-10-0-22-200.openstacklocal,10.0.22.200 //本子网虚机1的Mac地址,虚机的主机名字,虚机的fixed IP
fa:16:3e:19:65:62,host-10-0-22-202.openstacklocal,10.0.22.202 //本子网虚机2的Mac地址,虚机的主机名字,虚机的fixed IP
fa:16:3e:88:99:c1,host-10-0-0-116.openstacklocal,10.0.0.116 //子网1的DHCP Server (H1)的Mac地址,以及IP地址。那么这里为何没H2的相应信息?
在虚机的建立过程当中,Neutron会把这些信息(应该是从neutron db中拿到一个可用的IP地址)写到该文件中,这样,当虚机使用Mac地址向DHCP Server查询IP地址的时候,dnsmasq会读取该文件把IP地址返回给它。
root@network:/home/s1# ip netns exec qdhcp-0a4cd030-d951-401a-8202-937b788bea43 ip addr
18: tap6356d532-32: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
link/ether fa:16:3e:88:99:c1 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.116/24 brd 10.0.0.255 scope global tap6356d532-32
valid_lft forever preferred_lft forever
inet6 fe80::f816:3eff:fe88:99c1/64 scope link
valid_lft forever preferred_lft forever
root@network:/home/s1# ip netns exec qdhcp-d04a0a06-7206-4d05-9432-3443843bc199 ip addr
17: tap8dfd0bd8-45: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
link/ether fa:16:3e:82:fd:26 brd ff:ff:ff:ff:ff:ff
inet 10.0.11.101/24 brd 10.0.11.255 scope global tap8dfd0bd8-45
valid_lft forever preferred_lft forever
inet6 fe80::f816:3eff:fe82:fd26/64 scope link
valid_lft forever preferred_lft forever
root@network:/home/s1# ip netns exec qdhcp-d24963da-5221-481e-adf5-fe033d6e0b4e ip addr 19: tap15865c29-9b: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default link/ether fa:16:3e:4d:6b:44 brd ff:ff:ff:ff:ff:ff inet 10.0.22.201/24 brd 10.0.22.255 scope global tap15865c29-9b valid_lft forever preferred_lft forever inet6 fe80::f816:3eff:fe4d:6b44/64 scope link valid_lft forever preferred_lft forever
DHCP使用fix ip range的第一个可用IP地址作为其IP地址。它的interface的MAC地址 fa:16:3e:4d:6b:44 会出如今br-tun的rules里面。
具体步骤在下一篇博文中详细描述。