Learning Openstack Part 10 Neutron(2) - linux - bridge - local网络类型

在前面我们已经了解过Neutron网络服务的各种相关概念,仿佛如一团乱麻,一时难以理解。但是没关系,我们由简至繁来梳理一下,这里我们来了解一下基于linux bridge驱动的local network类型。


what?

local-network.png

local network 的特点是 不会与宿主机的任何物理网卡相连,也不关联任何的 VLAN ID。
对于每一个local network网络,都会单独起一个bridge,只有挂载在同一个bridge上的tap设备才能通讯。


how?(一次不太完美的实验)

光看上面的图也许逻辑概念并不太清楚,没关系,我们来动手实践一下。

  1. neutron 默认使用ml2做为core_plugins:
[root@openstack-compute ~]# grep ^core_plugin /etc/neutron/neutron.conf 
core_plugin = ml2
  1. 配置ml2使用linuxbridge做为驱动机制(mechanism driver)
openstack-config --set /etc/neutron/plugins/ml2/ml2_conf.ini ml2 mechanism_drivers linuxbridge
  1. 设置ml2加载5种网络type_drivers,只有加载的网络驱动类型才能调用
openstack-config --set /etc/neutron/plugins/ml2/ml2_conf.ini ml2 type_drivers local,flat,vlan,gre,vxlan
  1. 配置openstack普通用户创建的网络类型为local,只有admin可以自定义指定创建网络的类型,可以同时配置多种网络类型,用逗号连接.
openstack-config --set /etc/neutron/plugins/ml2/ml2_conf.ini ml2 tenant_network_types local
  1. 检查配置文件/etc/neutron/plugins/ml2/ml2_conf.ini
[root@openstack-compute ~]# grep -C1 "^[a-z]" /etc/neutron/plugins/ml2/ml2_conf.ini | grep -Ev "\-\-|^#|^$"
[ml2]
type_drivers = local,flat,vlan,gre,vxlan
tenant_network_types = local
mechanism_drivers = linuxbridge
extension_drivers = port_security
[ml2_type_flat]
flat_networks = physnet1
[securitygroup]
enable_ipset = True
  1. 重启neutron linuxbridge服务使之生效(所有网络节点)
    这里有个小bug,重启dhcp服务时,已经启动的dhcp的残余进程,导致重启修改失败,需要手动kill掉残余进程
# 控制节点
systemctl restart neutron-dhcp-agent.service neutron-linuxbridge-agent.service neutron-metadata-agent.service
# 计算节点
systemctl restart neutron-linuxbridge-agent.service
  1. 现在我们来cli创建local网络。
[root@openstack-controller tools]# source admin-openrc.sh 
[root@openstack-controller tools]# neutron net-create first-local
Created a new network:
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | True                                 |
| id                        | f31dc550-dfb4-4243-b109-15b6450d8682 |
| mtu                       | 0                                    |
| name                      | first-local                          |
| port_security_enabled     | True                                 |
| provider:network_type     | local                                |
| provider:physical_network |                                      |
| provider:segmentation_id  |                                      |
| router:external           | False                                |
| shared                    | False                                |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| tenant_id                 | 471592a4281e4223b2ad578b5c9b8442     |
+---------------------------+--------------------------------------+
  1. cli创建subnet
[root@openstack-controller tools]# neutron help subnet-create 
usage: neutron subnet-create [-h]
                             [-f {html,json,json,shell,table,value,yaml,yaml}]
                             [-c COLUMN] [--max-width <integer>] [--noindent]
                             [--prefix PREFIX] [--request-format {json,xml}]
                             [--tenant-id TENANT_ID] [--name NAME]
                             [--gateway GATEWAY_IP | --no-gateway]
                             [--allocation-pool start=IP_ADDR,end=IP_ADDR]
                             [--host-route destination=CIDR,nexthop=IP_ADDR]
                             [--dns-nameserver DNS_NAMESERVER]
                             [--disable-dhcp] [--enable-dhcp]
                             [--ip-version {4,6}]
                             [--ipv6-ra-mode {dhcpv6-stateful,dhcpv6-stateless,slaac}]
                             [--ipv6-address-mode {dhcpv6-stateful,dhcpv6-stateless,slaac}]
                             [--subnetpool SUBNETPOOL]
                             [--prefixlen PREFIX_LENGTH]
                             NETWORK [CIDR]

  Create a subnet for a given tenant.
positional arguments:
  NETWORK               Network ID or name this subnet belongs to.
  CIDR                  CIDR of subnet to create.
[root@openstack-controller tools]# neutron subnet-create --name subnet_192_168_1 \
--gateway 192.168.1.1 \
--enable-dhcp --allocation-pool start=192.168.1.100,end=192.168.1.150 \
f31dc550-dfb4-4243-b109-15b6450d8682 192.168.1.0/24
Created a new subnet:
+-------------------+----------------------------------------------------+
| Field             | Value                                              |
+-------------------+----------------------------------------------------+
| allocation_pools  | {"start": "192.168.1.100", "end": "192.168.1.150"} |
| cidr              | 192.168.1.0/24                                     |
| dns_nameservers   |                                                    |
| enable_dhcp       | True                                               |
| gateway_ip        | 192.168.1.1                                        |
| host_routes       |                                                    |
| id                | 24158244-3732-4456-9d8d-338dee2a1c70               |
| ip_version        | 4                                                  |
| ipv6_address_mode |                                                    |
| ipv6_ra_mode      |                                                    |
| name              | subnet_192_168_1                                   |
| network_id        | f31dc550-dfb4-4243-b109-15b6450d8682               |
| subnetpool_id     |                                                    |
| tenant_id         | 471592a4281e4223b2ad578b5c9b8442                   |
+-------------------+----------------------------------------------------+
  1. 我们来检查一下openstack创建local网络时做了些什么:
[root@openstack-controller tools]# brctl show  # 检查网桥
bridge name bridge id       STP enabled interfaces
brqf31dc550-df      8000.72dde96c7459   no      tapcca9852b-1d
[root@openstack-controller tools]# ip netns list # 检查namespace
qdhcp-f31dc550-dfb4-4243-b109-15b6450d8682 (id: 0)
[root@openstack-controller tools]# ip netns exec qdhcp-f31dc550-dfb4-4243-b109-15b6450d8682 ip a # 检查namespace中启动的ip地址
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    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: ns-cca9852b-1d@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether fa:16:3e:ac:30:9f brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 192.168.1.100/24 brd 192.168.1.255 scope global ns-cca9852b-1d                        # dhcp网关ip接口
       valid_lft forever preferred_lft forever
    inet 169.254.169.254/16 brd 169.254.255.255 scope global ns-cca9852b-1d                 # metadata服务的ip接口
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:feac:309f/64 scope link 
       valid_lft forever preferred_lft forever
  1. 我们在来使用这个网络创建两个实例:
[root@openstack-controller tools]# nova help flavor-create 
usage: nova flavor-create [--ephemeral <ephemeral>] [--swap <swap>]
                          [--rxtx-factor <factor>] [--is-public <is-public>]
                          <name> <id> <ram> <disk> <vcpus>
Create a new flavor
[root@openstack-controller tools]# nova flavor-create cirros auto 200 1 1
+--------------------------------------+--------+-----------+------+-----------+------+-------+-------------+-----------+
| ID                                   | Name   | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+--------------------------------------+--------+-----------+------+-----------+------+-------+-------------+-----------+
| 45243282-df65-4a7f-81e3-094f704a0e4f | cirros | 200       | 1    | 0         |      | 1     | 1.0         | True      |
+--------------------------------------+--------+-----------+------+-----------+------+-------+-------------+-----------+
[root@openstack-controller tools]# nova image-list
+--------------------------------------+--------------+--------+--------+
| ID                                   | Name         | Status | Server |
+--------------------------------------+--------------+--------+--------+
| 4d890feb-3c24-4425-8311-61c41a582a56 | cirros       | ACTIVE |        |
| cafc3188-54a0-4f51-8286-0fb2b44d81f5 | ubuntu-16.04 | ACTIVE |        |
+--------------------------------------+--------------+--------+--------+
[root@openstack-controller tools]# nova net-list
+--------------------------------------+-------------+------+
| ID                                   | Label       | CIDR |
+--------------------------------------+-------------+------+
| f31dc550-dfb4-4243-b109-15b6450d8682 | first-local | None |
+--------------------------------------+-------------+------+
[root@openstack-controller tools]# nova keypair-list
+-------+-------------------------------------------------+
| Name  | Fingerprint                                     |
+-------+-------------------------------------------------+
| mykey | 82:e9:3f:2d:e8:41:7b:7e:32:bd:76:3a:7a:ce:ce:07 |
+-------+-------------------------------------------------+
[root@openstack-controller tools]# nova help boot
usage: nova boot [--flavor <flavor>] [--image <image>]
                 [--image-with <key=value>] [--boot-volume <volume_id>]
                 [--snapshot <snapshot_id>] [--min-count <number>]
                 [--max-count <number>] [--meta <key=value>]
                 [--file <dst-path=src-path>] [--key-name <key-name>]
                 [--user-data <user-data>]
                 [--availability-zone <availability-zone>]
                 [--security-groups <security-groups>]
                 [--block-device-mapping <dev-name=mapping>]
                 [--block-device key1=value1[,key2=value2...]]
                 [--swap <swap_size>]
                 [--ephemeral size=<size>[,format=<format>]]
                 [--hint <key=value>]
                 [--nic <net-id=net-uuid,v4-fixed-ip=ip-addr,v6-fixed-ip=ip-addr,port-id=port-uuid>]
                 [--config-drive <value>] [--poll] [--admin-pass <value>]
                 <name>

Boot a new server.
[root@openstack-controller nova]# nova boot --flavor m1.small --image ubuntu-16.04 --key-name mykey --security-groups default --nic net-id=f31dc550-dfb4-4243-b109-15b6450d8682 ubuntu-1
+--------------------------------------+-----------------------------------------------------+
| Property                             | Value                                               |
+--------------------------------------+-----------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                              |
| OS-EXT-AZ:availability_zone          |                                                     |
| OS-EXT-SRV-ATTR:host                 | -                                                   |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | -                                                   |
| OS-EXT-SRV-ATTR:instance_name        | instance-0000000b                                   |
| OS-EXT-STS:power_state               | 0                                                   |
| OS-EXT-STS:task_state                | scheduling                                          |
| OS-EXT-STS:vm_state                  | building                                            |
| OS-SRV-USG:launched_at               | -                                                   |
| OS-SRV-USG:terminated_at             | -                                                   |
| accessIPv4                           |                                                     |
| accessIPv6                           |                                                     |
| adminPass                            | hWpVXMSx7kRd                                        |
| config_drive                         |                                                     |
| created                              | 2017-07-06T03:55:59Z                                |
| flavor                               | m1.small (2)                                        |
| hostId                               |                                                     |
| id                                   | 07066ac7-304e-4916-a891-47da3d0998a9                |
| image                                | ubuntu-16.04 (cafc3188-54a0-4f51-8286-0fb2b44d81f5) |
| key_name                             | mykey                                               |
| metadata                             | {}                                                  |
| name                                 | ubuntu-1                                            |
| os-extended-volumes:volumes_attached | []                                                  |
| progress                             | 0                                                   |
| security_groups                      | default                                             |
| status                               | BUILD                                               |
| tenant_id                            | 471592a4281e4223b2ad578b5c9b8442                    |
| updated                              | 2017-07-06T03:55:59Z                                |
| user_id                              | 60814f1c1e6a400e83b629465672ddf4                    |
+--------------------------------------+-----------------------------------------------------+
[root@openstack-controller nova]# nova boot --flavor m1.small --image ubuntu-16.04 --key-name mykey --security-groups default --nic net-id=f31dc550-dfb4-4243-b109-15b6450d8682 ubuntu-2
+--------------------------------------+-----------------------------------------------------+
| Property                             | Value                                               |
+--------------------------------------+-----------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                              |
| OS-EXT-AZ:availability_zone          |                                                     |
| OS-EXT-SRV-ATTR:host                 | -                                                   |
| OS-EXT-SRV-ATTR:hypervisor_hostname  | -                                                   |
| OS-EXT-SRV-ATTR:instance_name        | instance-0000000c                                   |
| OS-EXT-STS:power_state               | 0                                                   |
| OS-EXT-STS:task_state                | scheduling                                          |
| OS-EXT-STS:vm_state                  | building                                            |
| OS-SRV-USG:launched_at               | -                                                   |
| OS-SRV-USG:terminated_at             | -                                                   |
| accessIPv4                           |                                                     |
| accessIPv6                           |                                                     |
| adminPass                            | jsLhP4nnsGfu                                        |
| config_drive                         |                                                     |
| created                              | 2017-07-06T03:56:04Z                                |
| flavor                               | m1.small (2)                                        |
| hostId                               |                                                     |
| id                                   | 60308795-613f-4921-918e-4aecb9373c3f                |
| image                                | ubuntu-16.04 (cafc3188-54a0-4f51-8286-0fb2b44d81f5) |
| key_name                             | mykey                                               |
| metadata                             | {}                                                  |
| name                                 | ubuntu-2                                            |
| os-extended-volumes:volumes_attached | []                                                  |
| progress                             | 0                                                   |
| security_groups                      | default                                             |
| status                               | BUILD                                               |
| tenant_id                            | 471592a4281e4223b2ad578b5c9b8442                    |
| updated                              | 2017-07-06T03:56:04Z                                |
| user_id                              | 60814f1c1e6a400e83b629465672ddf4                    |
+--------------------------------------+-----------------------------------------------------+

这样两台虚拟机已经运行起来了,但是我们发现虽然在dashbard可以看到这个instance已经获取了ip,实际在vm上却检查不到ip,what a xxxx?

这是因为我们采取的是控制节点和计算节点(网络节点)分开部署的模式,local网络中bridge不会和物理网卡连接起来,这样的话运行在计算节点上的instance就无法连接到控制节点上namespace里运行的metadata服务和dhcp服务,自然也就无法获取到初始化设置。虽然这是一个失败的实验,但是我们应该对local network有了更深的了解。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,732评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,496评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,264评论 0 338
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,807评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,806评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,675评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,029评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,683评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 41,704评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,666评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,773评论 1 332
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,413评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,016评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,978评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,204评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,083评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,503评论 2 343

推荐阅读更多精彩内容