手机版
你好,游客 登录 注册
背景:
阅读新闻

在Ubuntu 14.04上部署OpenStack Juno

[日期:2015-12-13] 来源:www.renhl.com  作者:任怀林 [字体:大 中 小]

8 添加网络服务

OpenStack的网络服务是neutron,如果不安装neutron,nova-network也可以提供简单网络功能。neutron的功能更强大,所以我们使用neutron.

neutron应该是OpenStack最复杂的组件了。N多概念请参考OpenStack文档。我们在这里只验证它的安装过程。

8.1 安装配置控制节点

1 配置数据库 数据库安装在控制节点上。

$ mysql -u root -p

创建 neutron 数据库

CREATE DATABASE neutron;

/* 用户名和密码都是neutron/openstack */
GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'localhost' IDENTIFIED BY 'openstack';
GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'%' IDENTIFIED BY 'openstack';

2 切换到管理员身份

$ source admin-openrc.sh

3 To create the service credentials, complete these steps:

创建 neutron 用户:

$ keystone user-create --name neutron --pass openstack
+----------+----------------------------------+
| Property |              Value               |
+----------+----------------------------------+
|  email   |                                  |
| enabled  |               True               |
|    id    | d9ea6a6733934f139a42dfad12f1009a |
|   name   |             neutron              |
| username |             neutron              |
+----------+----------------------------------+

为 neutron 用户添加admin角色:

$ keystone user-role-add --user neutron --tenant service --role admin

创建 neutron 服务实体:

$ keystone service-create --name neutron --type network \
  --description "OpenStack Networking"
+-------------+----------------------------------+
|   Property  |              Value               |
+-------------+----------------------------------+
| description |       OpenStack Networking       |
|   enabled   |               True               |
|      id     | 8e45b333232e472c9bede063f71ffebb |
|     name    |             neutron              |
|     type    |             network              |
+-------------+----------------------------------+

创建计算服务API端点:

$ keystone endpoint-create \
  --service-id $(keystone service-list | awk '/ network / {print $2}') \
  --publicurl http://controller:9696 \
  --adminurl http://controller:9696 \
  --internalurl http://controller:9696 \
  --region regionOne
+-------------+----------------------------------+
|   Property  |              Value               |
+-------------+----------------------------------+
|   adminurl  |      http://controller:9696      |
|      id     | 0ec12e64cacf4eadac9421534b1d4028 |
| internalurl |      http://controller:9696      |
|  publicurl  |      http://controller:9696      |
|    region   |            regionOne             |
|  service_id | 8e45b333232e472c9bede063f71ffebb |
+-------------+----------------------------------+

4 安装 neutron 包

# apt-get install neutron-server neutron-plugin-ml2 Python-neutronclient

5 配置网络服务组件 编辑 /etc/neutron/neutron.conf 加入下面的内容

[DEFAULT]
...
rpc_backend = rabbit
rabbit_host = controller
rabbit_password = openstack
auth_strategy = keystone

core_plugin = ml2
service_plugins = router
allow_overlapping_ips = True

notify_nova_on_port_status_changes = True
notify_nova_on_port_data_changes = True
nova_url = http://controller:8774/v2
nova_admin_auth_url = http://controller:35357/v2.0
nova_region_name = regionOne
nova_admin_username = nova
nova_admin_tenant_id = SERVICE_TENANT_ID
nova_admin_password = openstack

verbose = True
[keystone_authtoken]

#Comment out any auth_host, auth_port, and auth_protocol options because the identity_uri option replaces them.
auth_uri = http://controller:5000/v2.0
identity_uri = http://controller:35357
admin_tenant_name = service
admin_user = neutron
admin_password = openstack

[database]
...
connection = mysql://neutron:openstack@controller/neutron

获得上述配置里的SERVICE_TENANT_ID

$ source admin-openrc.sh
$ keystone tenant-get service
+-------------+----------------------------------+
|   Property  |              Value               |
+-------------+----------------------------------+
| description |          Service Tenant          |
|   enabled   |               True               |
|      id     | ef36de18149b4c809c4b26b63b6dda37 |
|     name    |             service              |
+-------------+----------------------------------+

6 配置 Modular Layer 2 (ML2) 插件

编辑 /etc/neutron/plugins/ml2/ml2_conf.ini 加入下面的内容

[ml2]
...
type_drivers = flat,gre
tenant_network_types = gre
mechanism_drivers = openvswitch

[ml2_type_gre]
...
tunnel_id_ranges = 1:1000

[securitygroup]
...
enable_security_group = True
enable_ipset = True
firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver

7 配置计算来使用网络

编辑 /etc/nova/nova.conf 加入下面的内容

[DEFAULT]
...
network_api_class = nova.network.neutronv2.api.API
security_group_api = neutron
linuxnet_interface_driver = nova.network.linux_net.LinuxOVSInterfaceDriver
firewall_driver = nova.virt.firewall.NoopFirewallDriver

[neutron]
...
url = http://controller:9696
auth_strategy = keystone
admin_auth_url = http://controller:35357/v2.0
admin_tenant_name = service
admin_username = neutron
admin_password = NEUTRON_PASS

8完成安装

装载neutron数据库:

su -s /bin/sh -c "neutron-db-manage --config-file /etc/neutron/neutron.conf \
  --config-file /etc/neutron/plugins/ml2/ml2_conf.ini upgrade juno" neutron

重启计算服务

# service nova-api restart
# service nova-scheduler restart
# service nova-conductor restart

重启网络服务

# service neutron-server restart

9 验证安装

$ source admin-openrc.sh

列出已装载的扩展

$ neutron ext-list
+-----------------------+-----------------------------------------------+
| alias                 | name                                          |
+-----------------------+-----------------------------------------------+
| security-group        | security-group                                |
| l3_agent_scheduler    | L3 Agent Scheduler                            |
| ext-gw-mode           | Neutron L3 Configurable external gateway mode |
| binding               | Port Binding                                  |
| provider              | Provider Network                              |
| agent                 | agent                                         |
| quotas                | Quota management support                      |
| dhcp_agent_scheduler  | DHCP Agent Scheduler                          |
| l3-ha                 | HA Router extension                           |
| multi-provider        | Multi Provider Network                        |
| external-net          | Neutron external network                      |
| router                | Neutron L3 Router                             |
| allowed-address-pairs | Allowed Address Pairs                         |
| extraroute            | Neutron Extra Route                           |
| extra_dhcp_opt        | Neutron Extra DHCP opts                       |
| dvr                   | Distributed Virtual Router                    |
+-----------------------+-----------------------------------------------+

如果你运行这个命令是报下面的错误 unsupported locale setting 请设置LCALL为enUS.UTF-8

export LC_ALL=en_US.UTF-8

8.2 安装配置网络节点

8.2.1 准备工作

1 Edit the /etc/sysctl.conf file to contain the following parameters:

net.ipv4.ip_forward=1
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0

2 应用它

# sysctl -p

8.2.2 安装网络组件

# apt-get install neutron-plugin-ml2 neutron-plugin-openvswitch-agent \
  neutron-l3-agent neutron-dhcp-agent

8.2.3 配置网络公用组件

编辑 /etc/neutron/neutron.conf 加入下面的内容

  • 注释掉所有的数据库连接的选项,因为neutron不直接连接数据库
[DEFAULT]
rpc_backend = rabbit
rabbit_host = controller
rabbit_password = openstack

auth_strategy = keystone
core_plugin = ml2
service_plugins = router
allow_overlapping_ips = True
verbose = True

[keystone_authtoken]
#Comment out any auth_host, auth_port, and auth_protocol options because the identity_uri option replaces them.
auth_uri = http://controller:5000/v2.0
identity_uri = http://controller:35357
admin_tenant_name = service
admin_user = neutron
admin_password = openstack

8.2.3 配置Modular Layer 2 (ML2) 插件

编辑 /etc/neutron/plugins/ml2/ml2_conf.ini 加入下面的内容

[ml2]
...
type_drivers = flat,gre
tenant_network_types = gre
mechanism_drivers = openvswitch

[ml2_type_flat]
...
flat_networks = external

[ml2_type_gre]
...
tunnel_id_ranges = 1:1000

[securitygroup]
...
enable_security_group = True
enable_ipset = True
firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver

[ovs]
...
local_ip = INSTANCE_TUNNELS_INTERFACE_IP_ADDRESS
enable_tunneling = True
bridge_mappings = external:br-ex

[agent]
...
tunnel_types = gre

INSTANCETUNNELSINTERFACEIPADDRESS 在本文中是 10.0.1.21

8.2.4 配置Layer-3 (L3) agent

编辑 /etc/neutron/l3_agent.ini 加入下面的内容

[DEFAULT]
...
interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
use_namespaces = True
external_network_bridge = br-ex
router_delete_namespaces = True
...
verbose = True

8.2.5 配置DHCP agent

编辑 /etc/neutron/dhcp_agent.ini 加入下面的内容

[DEFAULT]
...
interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq
use_namespaces = True
dhcp_delete_namespaces = True

verbose = True

在官方手册里有一个可选的配置MTU的步骤,我们省略了.

8.2.6 配置metadata agent

编辑 /etc/neutron/metadata_agent.ini 加入下面的内容

[DEFAULT]
...
auth_url = http://controller:5000/v2.0
auth_region = regionOne
admin_tenant_name = service
admin_user = neutron
admin_password = NEUTRON_PASS

nova_metadata_ip = controller
metadata_proxy_shared_secret = openstack
verbose = True
  • 在控制节点上

请注意下面的操作在控制节点上进行

编辑 /etc/nova/nova.conf 加入下面的内容

[DEFAULT]
service_metadata_proxy = True
metadata_proxy_shared_secret = openstack

重启计算API服务

# service nova-api restart

8.2.7 配置Open vSwitch (OVS) 服务

下面的操作在网络节点上进行

# service openvswitch-switch restart
# ovs-vsctl add-br br-ex
# ovs-vsctl add-port br-ex eth0

如果你的network节点只配置了1个NIC,那你就会无法连接到这台network节点上,除非你通过方式如XenServer的console。 请看我的在这一步遇到的问题。

8.2.8 完成安装

重启网络服务

# service neutron-plugin-openvswitch-agent restart
# service neutron-l3-agent restart
# service neutron-dhcp-agent restart
# service neutron-metadata-agent restart

8.2.8 验证安装

*请在控制节点上运行下面的命令

$ source admin-openrc.sh

#查询所有的代理
$ neutron agent-list

+--------------------------------------+--------------------+-----------+-------+----------------+---------------------------+
| id                                   | agent_type         | host      | alive | admin_state_up | binary                    |
+--------------------------------------+--------------------+-----------+-------+----------------+---------------------------+
| 02e5b551-197e-4fa3-8489-d19cb40e3171 | DHCP agent         | network   | :-)   | True           | neutron-dhcp-agent        |
| 6ea0949b-e389-437b-9be7-eb32bc138ef1 | Metadata agent     | network   | :-)   | True           | neutron-metadata-agent    |
| cd82006e-a82d-4576-a7fa-183f68b4ae73 | L3 agent           | network   | :-)   | True           | neutron-l3-agent          |
| fbfc1f77-bee0-413f-a38d-eff804cc573f | Open vSwitch agent | network   | :-)   | True           | neutron-openvswitch-agent |
+--------------------------------------+--------------------+-----------+-------+----------------+---------------------------+

8.3 安装配置计算节点

计算节点处理实例的连接和安全规则组

8.3.1 准备工作

1 Edit the /etc/sysctl.conf file to contain the following parameters:

net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0

2 应用它

# sysctl -p

8.3.2 安装网络组件

# apt-get install neutron-plugin-ml2 neutron-plugin-openvswitch-agent

8.3.3 配置网络公用组件

编辑 /etc/neutron/neutron.conf 这个文件

  • 注释掉所有的数据库连接的选项,因为neutron不直接连接数据库

  • 加入下面的内容

[DEFAULT]
rpc_backend = rabbit
rabbit_host = controller
rabbit_password = openstack

auth_strategy = keystone

core_plugin = ml2
service_plugins = router
allow_overlapping_ips = True
verbose = True

[keystone_authtoken]
#Comment out any auth_host, auth_port, and auth_protocol options because the identity_uri option replaces them.
auth_uri = http://controller:5000/v2.0
identity_uri = http://controller:35357
admin_tenant_name = service
admin_user = neutron
admin_password = openstack

这个文件好像跟网络节点上的一模一样,:)

8.3.4 配置Modular Layer 2 (ML2) 插件

编辑 /etc/neutron/plugins/ml2/ml2_conf.ini 加入下面的内容

[ml2]
...
type_drivers = flat,gre
tenant_network_types = gre
mechanism_drivers = openvswitch

[ml2_type_gre]
...
tunnel_id_ranges = 1:1000

[securitygroup]
...
enable_security_group = True
enable_ipset = True
firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver

[ovs]
...
local_ip = INSTANCE_TUNNELS_INTERFACE_IP_ADDRESS
enable_tunneling = True
bridge_mappings = external:br-ex

[agent]
...
tunnel_types = gre

INSTANCETUNNELSINTERFACEIPADDRESS这个IP应该是计算节点的tunnel IP:10.0.1.31

8.3.5 配置Open vSwitch (OVS)服务

# service openvswitch-switch restart

8.3.6 配置计算来使用网络

默认安装包使用的是 legacy networking,也就nova-network。你必须重新配置计算节点使用neutron来管理网络。

编辑 /etc/nova/nova.conf 加入以下内容:

[DEFAULT]
# 注意: 默认计算组件nova使用了一个内部实现的防火墙服务,因为网络组件neutron包含了防火墙服务,所以你必须把nova的内部防火墙服务禁用,做法是设置firewall_driver = nova.virt.firewall.NoopFirewallDriver.

network_api_class = nova.network.neutronv2.api.API
security_group_api = neutron
linuxnet_interface_driver = nova.network.linux_net.LinuxOVSInterfaceDriver
firewall_driver = nova.virt.firewall.NoopFirewallDriver

[neutron]
...
url = http://controller:9696
auth_strategy = keystone
admin_auth_url = http://controller:35357/v2.0
admin_tenant_name = service
admin_username = neutron
admin_password = openstack

8.3.7 完成安装

# service nova-compute restart
# service neutron-plugin-openvswitch-agent restart

8.3.8 验证安装

*请在控制节点上运行下面的命令

$ source admin-openrc.sh
$ neutron agent-list
+--------------------------------------+--------------------+-----------+-------+----------------+---------------------------+              
| id                                   | agent_type         | host      | alive | admin_state_up | binary                    |              
+--------------------------------------+--------------------+-----------+-------+----------------+---------------------------+              
| 02e5b551-197e-4fa3-8489-d19cb40e3171 | DHCP agent         | network   | :-)   | True           | neutron-dhcp-agent        |              
| 6ea0949b-e389-437b-9be7-eb32bc138ef1 | Metadata agent     | network   | :-)   | True           | neutron-metadata-agent    |              
| cd82006e-a82d-4576-a7fa-183f68b4ae73 | L3 agent           | network   | :-)   | True           | neutron-l3-agent          |              
| e3fe92b0-afee-49e3-a783-e5900182fd5b | Open vSwitch agent | compute1  | :-)   | True           | neutron-openvswitch-agent |              
| fbfc1f77-bee0-413f-a38d-eff804cc573f | Open vSwitch agent | network   | :-)   | True           | neutron-openvswitch-agent |              
+--------------------------------------+--------------------+-----------+-------+----------------+---------------------------+

可以看到在host列有compute1,也就是计算节点上的Open vSwitch agent已启动。

8.4 创建初始网络

在启动虚拟机之前,你要先创建虚拟网络基本架构,实例会连接到它上。这个虚拟网络包含一个外部网络和租户网络。 installguide-neutron-initialnetworks.png

8.4.1 外部网络

外部网络向实例提供互联网访问支持。默认它允许实例以Network Address Translation (NAT)方式访问互联网。 使用浮动IP和适当安全规则组,你可以使单个实例访问Internet。管理员租户会拥有这个网络,因为它向所有的租户提供外部网络。

注意 请在控制节点上运行下面的命令

1 创建外部网络

# source admin-openrc.sh

$ neutron net-create ext-net --router:external True \
  --provider:physical_network external --provider:network_type flat

Created a new network:                                                                                                                      
+---------------------------+--------------------------------------+                                                                        
| Field                     | Value                                |                                                                        
+---------------------------+--------------------------------------+                                                                        
| admin_state_up            | True                                 |                                                                        
| id                        | c3b0a6f6-7bed-4058-9a20-1f33396e331f |                                                                        
| name                      | ext-net                              |                                                                        
| provider:network_type     | flat                                 |                                                                        
| provider:physical_network | external                             |
| provider:segmentation_id  |                                      |
| router:external           | True                                 |
| shared                    | False                                |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| tenant_id                 | 357abecb4def441eb7a36e7cf5d173c4     |
+---------------------------+--------------------------------------+

我们创建的这个外网,它跟网络节点的那个绑定外网地址的网卡在一个子网,共享网关。 跟物理网一样,我们需要给它创建一个子网。

2 在外网上创建子网

创建的命令如下:

$ neutron subnet-create ext-net --name ext-subnet \
  --allocation-pool start=FLOATING_IP_START,end=FLOATING_IP_END \
  --disable-dhcp --gateway EXTERNAL_NETWORK_GATEWAY EXTERNAL_NETWORK_CIDR

本文是外网的网段是192.168.234.0/24 ,我们分配浮动IP段为234.230~234.239

$ neutron subnet-create ext-net --name ext-subnet \
  --allocation-pool start=192.168.234.230,end=192.168.234.239 \
  --disable-dhcp --gateway 192.168.234.1 192.168.234.0/24

Created a new subnet:
+-------------------+--------------------------------------------------------+
| Field             | Value                                                  |
+-------------------+--------------------------------------------------------+
| allocation_pools  | {"start": "192.168.234.230", "end": "192.168.234.239"} |
| cidr              | 192.168.234.0/24                                       |
| dns_nameservers   |                                                        |
| enable_dhcp       | False                                                  |
| gateway_ip        | 192.168.234.1                                          |
| host_routes       |                                                        |
| id                | 33bc7923-789c-4453-9dd2-7853b4c69c5c                   |
| ip_version        | 4                                                      |
| ipv6_address_mode |                                                        |
| ipv6_ra_mode      |                                                        |
| name              | ext-subnet                                             |
| network_id        | c3b0a6f6-7bed-4058-9a20-1f33396e331f                   |
| tenant_id         | 357abecb4def441eb7a36e7cf5d173c4                       |
+-------------------+--------------------------------------------------------+

8.4.2 租户网络

The tenant network provides internal network access for instances. The architecture isolates this type of network from other tenants. The demo tenant owns this network because it only provides network access for instances within it.

注意 请在控制节点上运行下面的命令

1 创建租户网络

# source demo-openrc.sh


$ neutron net-create demo-net

Created a new network:
+-----------------+--------------------------------------+
| Field           | Value                                |
+-----------------+--------------------------------------+
| admin_state_up  | True                                 |
| id              | dba2bba4-c2a5-410a-9b6f-da8a1e9b887f |
| name            | demo-net                             |
| router:external | False                                |
| shared          | False                                |
| status          | ACTIVE                               |
| subnets         |                                      |
| tenant_id       | 6245a74d882e451c8d7663a46103b8b2     |
+-----------------+--------------------------------------+

2 在租户网络上创建子网

$ neutron subnet-create demo-net --name demo-subnet \
  --gateway 10.10.1.1 10.10.1.0/24

Created a new subnet:
+-------------------+----------------------------------------------+
| Field             | Value                                        |
+-------------------+----------------------------------------------+
| allocation_pools  | {"start": "10.10.1.2", "end": "10.10.1.254"} |
| cidr              | 10.10.1.0/24                                 |
| dns_nameservers   |                                              |
| enable_dhcp       | True                                         |
| gateway_ip        | 10.10.1.1                                    |
| host_routes       |                                              |
| id                | e07e263f-1cf8-4f60-adbb-424fbd22ed0d         |
| ip_version        | 4                                            |
| ipv6_address_mode |                                              |
| ipv6_ra_mode      |                                              |
| name              | demo-subnet                                  |
| network_id        | dba2bba4-c2a5-410a-9b6f-da8a1e9b887f         |
| tenant_id         | 6245a74d882e451c8d7663a46103b8b2             |
+-------------------+----------------------------------------------+

3 创建路由器 路由器用来连接租户网络和外部网络

创建路由器

$ neutron router-create demo-router

Created a new router:
+-----------------------+--------------------------------------+
| Field                 | Value                                |
+-----------------------+--------------------------------------+
| admin_state_up        | True                                 |
| external_gateway_info |                                      |
| id                    | 979f88e6-65e2-4d97-b468-4b1e95687da4 |
| name                  | demo-router                          |
| routes                |                                      |
| status                | ACTIVE                               |
| tenant_id             | 6245a74d882e451c8d7663a46103b8b2     |
+-----------------------+--------------------------------------+

把它加到租户网络内

$ neutron router-interface-add demo-router demo-subnet
Added interface 2e55f3dc-763f-4031-8011-b2b2dd9df5fe to router demo-router.

设置路由器的网关使它连接到外网

$ neutron router-gateway-set demo-router ext-net
Set gateway for router demo-router

8.5 验证安装

如果你的安装没问题,那么租户的路由会占用最低的那个IP:192.168.234.230,你在外网的任何一台机器上应该能ping通它。

9 安装控制台

The OpenStack dashboard, also known as Horizon,是它的web管理界面。

9.1 安装配置Horizon

我们把Horizon安装在控制节点上

# apt-get install openstack-dashboard apache2 libapache2-mod-wsgi memcached python-memcache

配置Horizon

编辑它 /etc/openstack-dashboard/local_settings.py 加入下面的内容。

OPENSTACK_HOST = "controller"
ALLOWED_HOSTS = ['*']
CACHES = {
   'default': {
       'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
       'LOCATION': '127.0.0.1:11211',
   }
}
TIME_ZONE = "Asia/Shanghai"

3 完成安装

# service apache2 restart
# service memcached restart

9.2 验证安装

在浏览器里输入:http://controller/horizon,来访问Horizon。

linux
相关资讯       OpenStack  OpenStack Juno 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站��理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款