本文目的:  在基于openstack构建的海航云上面搭建一个包含基本组件的openstack服务,并让该openstack里启动的实例直接通过弹性公网ip被访问。

一、背景知识:

1、海航云:https://www.haihangyun.com  一个基于纯openstack构建的公有云,在我来腾讯之前工作的地方。

2、安全组: openstack对于每个虚拟网卡都提供安全组,在不添加规则情况下,所有流量都是禁止通过。

3、port address pairs。openstack默认只允许从port上发出 IP 和 MAC 地址与其 IP 和 MAC 地址都相同的网络包。举例:系统给我的云主机的dhcp的ip是 192.168.0.10,默认开启安全组情况下情况如果我将虚拟机的ip由dhcp改为 192.168.0.11,云主机将无法对外通信。此时需要在在neutron的port 设置上添加 address pairs规则,让系统允许他以 192.168.0.11对外通讯。详见http://superuser.openstack.org/articles/managing-port-level-security-openstack/


二,环境搭建

1 网络

       创建 两个私有网络:Provider,Management。其中Provider需要开启公网网关。关闭两个网络的安全组功能。目前海航云需要人工提交工单关闭安全组。在社区版的openstack中。ocata之前的neutron client 并不支持创建创建不开启安全组功能的网络,需要直接调用api来进行操作。


最新的pike的neutron client已经支持。

openstack in openstack(在openstack公有云上面搭建openstack 服务)_第1张图片


api示例 

 curl -g -i -X POST http://controller:9696/v2.0/networks  -H "X-Auth-Token: bdd45bb441ec1816dcb56a9c90a6a8ae84aac9ec" -d '{"network": {"port_security_enabled": false, "name": "test", "admin_state_up": true}}'


成功创建的截图

openstack in openstack(在openstack公有云上面搭建openstack 服务)_第2张图片





2 启动两个实例 controller compute1,并将他们同时加入Provider,Management 两个私有网络

wKiom1nS7YGDkgSRAAA46PbJrg0222.png-wh_50





3、因为云主机加入了两个网络,并且只有一个网络添加了公网接口,所以需要设置默认网关,确保

192.168.11.1的优先级高



[root@host-192-168-11-4 cloud-user]#route add default gw 192.168.11.1
[root@host-192-168-11-4 cloud-user]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.11.1    0.0.0.0         UG    100    0        0 eth0
0.0.0.0         192.168.1.1     0.0.0.0         UG    101    0        0 eth1
192.168.1.0     0.0.0.0         255.255.255.0   U     100    0        0 eth1
192.168.11.0    0.0.0.0         255.255.255.0   U     100    0        0 eth0


4、网路拓扑


openstack in openstack(在openstack公有云上面搭建openstack 服务)_第3张图片


三 安装过程

安装过程参考官网文档

https://docs.openstack.org/install-guide/openstack-services.html#minimal-deployment

几个不同地方

1、在nova装过程中,指定vnc的url为 controller节点的弹性公网ip

[root@compute1 cloud-user]# grep novncproxy_base_url  /etc/nova/nova.conf|grep -v ^#
novncproxy_base_url = http://*.*.*.*:6080/vnc_auto.html

2 在neutro安装中

指定vxlan网络的localip 和provider网络的网卡

[root@controller ~]# cat /etc/neutron/plugins/ml2/linuxbridge_agent.ini |grep local_ip|grep -v ^#
local_ip = 192.168.1.9
[root@controller ~]# cat /etc/neutron/plugins/ml2/linuxbridge_agent.ini |grep physical_interface_mappings |grep -v ^#
physical_interface_mappings = provider:eth0

 四 运行实例并通过弹性公网ip访问

1 创建provider网络

[root@controller ~]#openstack network create  --share --external --provider-physical-network provider --provider-network-type flat provider
[root@controller ~]openstack subnet create --network provider \
  --allocation-pool start=192.168.11.100,end=192.168.11.200 \
  --dns-nameserver 114.114.114.114 --gateway 192.168.11.1 \
  --subnet-range 192.168.11.0/24 provider

2 创建pravite 网络

[root@controller ~]#  openstack subnet create --network pravite --dns-nameserver 114.114.114.114 --gateway 172.16.1.1 --subnet-range 172.16.1.0/24 pravite

3 创建vrouter

[root@controller ~]#  openstack router create router

4 关联vrouter

[root@controller ~]# neutron router-interface-add router pravite
Added interface 18b2181a-ce8f-4a05-97a0-90793a980a28 to router router.
[root@controller ~]# neutron router-gateway-set router provider
Set gateway for router router
[root@controller ~]#

5 创建虚拟机 

openstack server create --flavor m1.nano --p_w_picpath cirros --nic net-id=e73b625b-edf8-43f0-b314-682f3b59e5a0--security-group default

6 创建并绑定浮动 ip 

[root@controller nova]# openstack  floating ip create d958d877-d3f8-4c9d-9154-459e2df872b9
[root@controller nova]# neutron  floatingip-associate   40663c10-a44d-4538-a1aa-b8daf34fb9f6  38d433b1-dd8f-4504-967c-17ef9da7eb9e

此时 我们已经可以在控制节点ping通该虚拟机

[root@controller nova]# ping 192.168.11.111
PING 192.168.11.111 (192.168.11.111) 56(84) bytes of data.
64 bytes from 192.168.11.111: icmp_seq=1 ttl=63 time=6.25 ms
64 bytes from 192.168.11.111: icmp_seq=2 ttl=63 time=1.46 ms
[root@controller nova]# openstack server show e9aea2f8-da7b-44e7-bcb0-274154e20cae
+-------------------------------------+----------------------------------------------------------+
| Field                               | Value                                                    |
+-------------------------------------+----------------------------------------------------------+
| OS-DCF:diskConfig                   | AUTO                                                     |
| OS-EXT-AZ:availability_zone         | nova                                                     |
| OS-EXT-SRV-ATTR:host                | compute1                                                 |
| OS-EXT-SRV-ATTR:hypervisor_hostname | compute1                                                 |
| OS-EXT-SRV-ATTR:instance_name       | instance-00000001                                        |
| OS-EXT-STS:power_state              | Running                                                  |
| OS-EXT-STS:task_state               | None                                                     |
| OS-EXT-STS:vm_state                 | active                                                   |
| OS-SRV-USG:launched_at              | 2017-10-03T05:23:36.000000                               |
| OS-SRV-USG:terminated_at            | None                                                     |
| accessIPv4                          |                                                          |
| accessIPv6                          |                                                          |
| addresses                           | pravite=172.16.1.5, 192.168.11.111                       |
| config_drive                        |                                                          |
| created                             | 2017-10-03T05:23:21Z                                     |
| flavor                              | m1.nano (0)                                              |
| hostId                              | 93d1abb30f3702fa13e7d7ec74de6b3a4a56e7e4b763c9182fa8e256 |
| id                                  | e9aea2f8-da7b-44e7-bcb0-274154e20cae                     |
| p_w_picpath                               | cirros (b9768af8-8bb0-4ab8-8159-462d44d00e4f)            |
| key_name                            | None                                                     |
| name                                | 222                                                      |
| progress                            | 0                                                        |
| project_id                          | f521e63a95c74fbfa67d014b84b5e0c4                         |
| properties                          |                                                          |
| security_groups                     | name='default'                                           |
| status                              | ACTIVE                                                   |
| updated                             | 2017-10-03T05:23:36Z                                     |
| user_id                             | a19a38e5f3f348e78cf7170f712bf3eb                         |
| volumes_attached                    |                                                          |
+-------------------------------------+----------------------------------------------------------+

7 给虚拟机中的虚拟机绑定弹性ip

 1、在海航云创建一个虚拟网卡

    网卡地址为

192.168.11.111

2 目前海航云前端并不支持将公网ip直接绑定给虚拟网卡,采用曲线的办法

 新建一台测试机,关机,将改虚拟网卡挂载到该测试机,拆除测试机原来的网卡,在给该测试机绑定公网ip,最后将虚拟网卡从测试机中拆除

最后成果为

wKiom1nTNHjR7jI2AAAcwnv16yU115.png-wh_50

3 设置安全组规则并,通过该公网ip访问云主机中的云主机

openstack in openstack(在openstack公有云上面搭建openstack 服务)_第4张图片