openstack之kilo安装 网络服务

这周在折腾openstack,下面是过程小记。

参考:Chapter 6. Add a networking component

neutron服务安装在控制节点、网络节点、计算节点。

Install and configure controller node

创建数据库:

#
mysql -u root -p

MariaDB [(none)]>

CREATE DATABASE neutron;

GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'localhost' \
IDENTIFIED BY 'NEUTRON_DBPASS';
GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'%' \
IDENTIFIED BY 'NEUTRON_DBPASS';
EXIT

导入 admin身份凭证以执行管理员用户专有的命令:

#
source admin-openrc.sh

创建neutron user:

#
openstack user create neutron --password neutron

添加admin role to the neutron user:

#
openstack role add --project service --user neutron admin

创建neutron service entity:

#
openstack service create --name neutron \
--description "OpenStack Networking" network

创建Networking service API endpoint:

#
openstack endpoint create \
--publicurl http://controller:9696 \
--adminurl http://controller:9696 \
--internalurl http://controller:9696 \
--region RegionOne \
network

安装网络组件:

#
yum install -y openstack-neutron openstack-neutron-ml2 python-neutronclient which

编辑 /etc/neutron/neutron.conf 文件:

#
cp /etc/neutron/neutron.conf /etc/neutron/neutron.confbak
echo "[DEFAULT]
rpc_backend = rabbit
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
verbose = True
[database]
connection = mysql://neutron:NEUTRON_DBPASS@controller/neutron
[oslo_messaging_rabbit]
rabbit_host = controller
rabbit_userid = openstack
rabbit_password = RABBIT_PASS
[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:35357
auth_plugin = password
project_domain_id = default
user_domain_id = default
project_name = service
username = neutron
password = neutron
[nova]
auth_url = http://controller:35357
auth_plugin = password
project_domain_id = default
user_domain_id = default
region_name = RegionOne
project_name = service
username = nova
password = nova">/etc/neutron/neutron.conf

配置 Modular Layer 2 (ML2) 插件

ML2 插件使用 Open vSwitch (OVS)机制 (代理) 来为实例构建虚拟网络架构。但是,控制节点不需要 OVS 组件,因为它并不处理实例网络的传输。

编辑/etc/neutron/plugins/ml2/ml2_conf.ini 文件:

#
cp /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugins/ml2/ml2_conf.inibak
echo "[ml2]
type_drivers = flat,vlan,gre,vxlan
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">/etc/neutron/plugins/ml2/ml2_conf.ini

Networking 服务初始化脚本需要一个链接将 /etc/neutron/plugin.ini指向 ML2插件的配置文件 /etc/neutron/plugins/ml2/ml2_conf.ini。如果这个象征性的链接不存在,请用以下命令创建它:

#
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini

配置Compute to use Networking

默认情况下,发行版的包会配置 Compute 使用传统网络。您必需重新配置 Compute 来通过Networking 来管理网络。

在控制节点编辑/etc/nova/nova.conf file :

#
echo "[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">>/etc/nova/nova.conf

同步database:

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

重启 Compute services:

#
systemctl restart openstack-nova-api.service openstack-nova-scheduler.service \
openstack-nova-conductor.service

启动Networking service and configure it to start when the system boots:

#
systemctl enable neutron-server.service
systemctl start neutron-server.service

在控制节点验证:

#
source admin-openrc.sh
neutron ext-list

Install and configure network node

网络节点主要为虚拟网络处理内部和外部路由及 DHCP服务。
编辑 /etc/sysctl.conf 调整内核网络参数:

#
echo "
#For openstack
net.ipv4.ip_forward=1
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0" >> /etc/sysctl.conf
#
sysctl -p

安装 Networking components:

#
yum install -y openstack-neutron openstack-neutron-ml2 openstack-neutron-openvswitch

编辑 /etc/neutron/neutron.conf 文件完成网络通用组件配置:

#
cp /etc/neutron/neutron.conf /etc/neutron/neutron.confbak
echo "[DEFAULT]
rpc_backend = rabbit
[oslo_messaging_rabbit]
rabbit_host = controller
rabbit_userid = openstack
rabbit_password = RABBIT_PASS
auth_strategy = keystone
core_plugin = ml2
service_plugins = router
allow_overlapping_ips = True
verbose = True
[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:35357
auth_plugin = password
project_domain_id = default
user_domain_id = default
project_name = service
username = neutron
password = neutron" >/etc/neutron/neutron.conf

配置 Modular Layer 2 (ML2) 插件

ML2 插件使用 Open vSwitch (OVS)机制 (代理) 来为实例构建虚拟网络框架。

编辑/etc/neutron/plugins/ml2/ml2_conf.ini 文件:

#
cp /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugins/ml2/ml2_conf.inibak
echo "[ml2]
type_drivers = flat,vlan,gre,vxlan
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 = 10.0.1.21
#使用网络节点的tunnels network IP 地址
bridge_mappings = external:br-ex
[agent]
tunnel_types = gre">/etc/neutron/plugins/ml2/ml2_conf.ini

Networking 服务初始化脚本需要一个象征性的链接将 /etc/neutron/plugin.ini指向 ML2插件的配置文件/etc/neutron/plugins/ml2/ml2_conf.ini。如果这个象征性的链接不存在,请用以下命令创建它:

#
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini

配置 Layer-3 (L3) 代理

Layer-3 (L3) 代理为虚拟网络提供路由服务。

编辑/etc/neutron/l3_agent.ini 文件:

#
cp /etc/neutron/l3_agent.ini /etc/neutron/l3_agent.inibak
echo "[DEFAULT]
interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver

external_network_bridge = br-ex
router_delete_namespaces = True
verbose = True">/etc/neutron/l3_agent.ini

external_network_bridge指定网卡

配置 DHCP 代理

DHCP 代理为实例提供 DHCP 服务。

编辑/etc/neutron/dhcp_agent.ini 文件:

#
cp /etc/neutron/dhcp_agent.ini /etc/neutron/dhcp_agent.inibak
echo "[DEFAULT]
interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq
dhcp_delete_namespaces = True
verbose = True">/etc/neutron/dhcp_agent.ini

类似于GRE的隧道协议包含有额外的数据包头,这些数据包头增加了开销,减少了有效内容或是用户数据的可用空间。在不了解虚拟网络架构的情况下,实例尝试用默认的以太网maximum transmission unit (MTU)1500字节来发送数据包。 Internet protocol (IP)网络利用 path MTU discovery (PMTUD)机制来探测和调整数据包的大小。但是有些操作系统或者是网络阻塞、缺乏对PMTUD的支持等原因会造成性能下降或是连接错误。

理想情况下,你可以通过在包含有租户虚拟网络的物理网络上开启jumbo frames来避免这些问题。巨型帧(Jumbo frames)支持最大接近9000字节的MTU,它抵消了虚拟网络上GRE开销的影响。但是,很多网络设备缺乏对于巨型帧的支持,Openstack的管理员也经常缺乏对网络架构的控制。考虑到后续的复杂性,也可以选择降低带来GRE开销的实例的MTU大小来避免MTU的问题。确定恰当的MTU值通常需要实验,但是大多数环境下1454字节都可以工作。你可以配置给实例分配IP地址的DHCP服务器来同时调整MTU。

[Note] Note
一些云镜像会忽略 DHCP MTU 选项,在这种情况下,您要配置其使用metadata、一个脚本或其他合适方法。

编辑 /etc/neutron/dhcp_agent.ini 文件:

#
cp /etc/neutron/dhcp_agent.ini /etc/neutron/dhcp_agent.inibak
echo "dnsmasq_config_file = /etc/neutron/dnsmasq-neutron.conf">>/etc/neutron/dhcp_agent.ini

编辑/etc/neutron/dnsmasq-neutron.conf文件,启用 DHCP MTU 选项 (26) 并配置为 1454 字节:

#
echo "dhcp-option-force=26,1454">>/etc/neutron/dnsmasq-neutron.conf

Kill any existing dnsmasq processes:

#
pkill dnsmasq

配置 metadata 代理

metadata agent提供一些配置信息,如实例的凭据。

编辑/etc/neutron/metadata_agent.ini file and complete the following actions:

#
cp /etc/neutron/metadata_agent.ini /etc/neutron/metadata_agent.inibak
echo "[DEFAULT]
auth_uri = http://controller:5000
auth_url = http://controller:35357
auth_region = RegionOne
auth_plugin = password
project_domain_id = default
user_domain_id = default
project_name = service
username = neutron
password = neutron
nova_metadata_ip = controller
metadata_proxy_shared_secret = METADATA_SECRET
verbose = True">/etc/neutron/metadata_agent.ini

在控制节点,编辑/etc/nova/nova.conf file and complete the following action:

#
echo "[neutron]
service_metadata_proxy = True
metadata_proxy_shared_secret = METADATA_SECRET">>/etc/nova/nova.conf

在控制节点, 重启Compute API service:

#
systemctl restart openstack-nova-api.service

配置 Open vSwitch (OVS) 服务

OVS 服务为实例提供了底层的虚拟网络框架。整合的桥接 br-int处理内部实例网络在 OVS 中的传输。外部桥接 br-ex处理外部实例网络在 OVS 中的传输。外部桥接需要一个在物理外部网络接口上的端口来为实例提供外部网络的访问。本质上,这个端口连接了您环境中虚拟的和物理的外部网络。

启动OVS service and并配置开机自启动:

#
systemctl enable openvswitch.service
systemctl start openvswitch.service

创建ovs外部网络网桥:

#
echo "DEVICE=br-ex
ONBOOT=yes
BOOTPROTO=static
TYPE=OVSBridge
DEVICETYPE=ovs
USERCTL=yes
PEERDNS=yes
IPV6INIT=no
IPADDR=192.178.102.221
NETMASK=255.255.255.0
GATEWAY=192.178.102.254
DNS1=114.114.114.114">/etc/sysconfig/network-scripts/ifcfg-br-ex

(此处的IP网络等信息和你的ens224一样)
修改ens224配置:

#
echo "# Generated by dracut initrd
DEVICE=\"ens224\"
ONBOOT=yes
NM_CONTROLLED=no
TYPE=OVSPort
DEVICETYPE=ovs
OVS_BRIDGE=br-ex
HWADDR=\"00:50:56:ab:06:f0\"">/etc/sysconfig/network-scripts/ifcfg-ens224

添加 external bridge:

#
ovs-vsctl add-br br-ex

给一个连接到物理外部网络接口的外部桥接添加端口:

#
ovs-vsctl add-port br-ex ens224,systemctl restart network.service

[Note] Note
据您的网络接口驱动,您可能需要禁用 generic receive offload (GRO)来实现您实例和外部网络之间的合适吞吐量。

临时在外部网络接口上暂时地禁用 GRO:

#
ethtool -K ens224 gro off

由于一个包的缺陷,Open vSwitch 代理初始化脚本会寻找 Open vSwitch 插件的配置文件,而不是指向 ML2 配置文件的象征性链接 /etc/neutron/plugin.ini。执行以下命令来解决这个问题:

#
cp /usr/lib/systemd/system/neutron-openvswitch-agent.service \
/usr/lib/systemd/system/neutron-openvswitch-agent.service.orig
sed -i 's,plugins/openvswitch/ovs_neutron_plugin.ini,plugin.ini,g' \
/usr/lib/systemd/system/neutron-openvswitch-agent.service

启动 Networking 服务并将其配置为随系统启动:

#
systemctl enable neutron-openvswitch-agent.service neutron-l3-agent.service \
neutron-dhcp-agent.service neutron-metadata-agent.service \
neutron-ovs-cleanup.service
systemctl restart neutron-openvswitch-agent.service neutron-l3-agent.service \
neutron-dhcp-agent.service neutron-metadata-agent.service

[Note] Note
请勿直接地启动 neutron-ovs-cleanup服务。

在控制节点验证:

#
source admin-openrc.sh
neutron agent-list

Install and configure compute node

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

编辑 /etc/sysctl.conf 文件,修改网络内核参数:

#
echo "net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1">>/etc/sysctl.conf
#
sysctl -p

安装 Networking组件:

#
yum install -y openstack-neutron openstack-neutron-ml2 openstack-neutron-openvswitch

编辑/etc/neutron/neutron.conf文件,配置Networking common components:

#
cp /etc/neutron/neutron.conf /etc/neutron/neutron.confbak
echo "[DEFAULT]
core_plugin = ml2
service_plugins = router
allow_overlapping_ips = True
verbose = True
rpc_backend = rabbit
auth_strategy = keystone
[oslo_messaging_rabbit]
rabbit_host = controller
rabbit_userid = openstack
rabbit_password = RABBIT_PASS
[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:35357
auth_plugin = password
project_domain_id = default
user_domain_id = default
project_name = service
username = neutron
password = neutron">/etc/neutron/neutron.conf

配置 Modular Layer 2 (ML2) 插件

ML2 插件使用 Open vSwitch (OVS) 机制 (代理) 来为实例构建虚拟网络框架。

编辑/etc/neutron/plugins/ml2/ml2_conf.ini文件:

#
cp /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugins/ml2/ml2_conf.inibak
echo "[ml2]
type_drivers = flat,vlan,gre,vxlan
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 = 10.0.1.31
[agent]
tunnel_types = gre">/etc/neutron/plugins/ml2/ml2_conf.ini

注意
将其中的 INSTANCE_TUNNELS_INTERFACE_IP_ADDRESS替换为计算节点上的实例隧道网络接口的 IP 地址,即local_ip。

Networking 服务初始化脚本需要一个象征性的链接将 /etc/neutron/plugin.ini指向 ML2插件的配置文件/etc/neutron/plugins/ml2/ml2_conf.ini。如果这个象征性的链接不存在,请用以下命令创建它:

#
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini

配置 Open vSwitch (OVS) 服务

OVS 服务为实例提供了底层的虚拟网络框架。

启动 OVS 服务并将其配置为随系统启动:

#
systemctl enable openvswitch.service
systemctl start openvswitch.service

配置 Compute 以使用 Networking

默认情况下,发行版的包会配置 Compute 使用传统网络。您必需重新配置 Compute 来通过Networking 来管理网络。

编辑/etc/nova/nova.conf file and complete the following actions:

#
cp /etc/nova/nova.conf /etc/nova/nova.conf
echo "[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">>/etc/nova/nova.conf

Networking 服务初始化脚本需要一个象征性的链接将 /etc/neutron/plugin.ini指向 ML2插件的配置文件 /etc/neutron/plugins/ml2/ml2_conf.ini。如果这个象征性的链接不存在,请用以下命令创建它:

#
cp /usr/lib/systemd/system/neutron-openvswitch-agent.service \
/usr/lib/systemd/system/neutron-openvswitch-agent.service.orig
sed -i 's,plugins/openvswitch/ovs_neutron_plugin.ini,plugin.ini,g' \
/usr/lib/systemd/system/neutron-openvswitch-agent.service

重启Compute service:

#
systemctl restart openstack-nova-compute.service

启动 Open vSwitch (OVS) agent 并配置开机自启动:

#
systemctl enable neutron-openvswitch-agent.service
systemctl start neutron-openvswitch-agent.service

在控制节点验证:

#
source admin-openrc.sh
neutron agent-list

Create initial networks

启动您的第一台实例之前,您必须创建虚拟机要连接的必需的虚拟网络基础设施,包括外部网络和租户网络。创建好这些基础设施之后,我们建议您验证连接,并在继续执行之前解决
出现的问题。图 “初始网络”提供了一个组件的基本架构预览,网络实现了初始化网络,并展示了网络如何 从实例上流通到外部网络或内部网络中。

  • External network

外部网络为您的实例分配互联网连接。该网络一般仅允许通过使用网络地址转换 (NAT)的实例访问 Internet。您可以通过一个浮动IP地址和合适的安全组规则来启用 Internet 的访问到个别实例。admin租户拥有这个网络,因为它为多个租户提供了外部网络的访问。

[Note] Note
Perform these commands on the controller node.

创建external network

#
source admin-openrc.sh
neutron net-create ext-net --router:external \
--provider:physical_network external --provider:network_type flat

如同一个物理网络,一个虚拟网络需要为其分配一个子网。外部网络通过网络节点上的外部接口,分享与物理网络关联的相同的子网和网关。您需要为路由和浮动IP来指定一个此子网上的独有段,以免与外部网络上的其他设备相冲突。

创建subnet on the external network:

#
neutron subnet-create ext-net 192.168.56.0/24 --name ext-subnet \
--allocation-pool start=192.168.56.50,end=192.168.56.99 \
--disable-dhcp --gateway 192.168.56.254

使用您想用来分配给浮动IP的第一个和最后一个IP地址来替换起始IP地址。用和物理网络相关联的子网替换EXTERNAL_NETWORK_CIDR。 用和物理网络相关联的网关替换 EXTERNAL_NETWORK_GATEWAY常见的是 “.1” IP 地址。应该关闭此子网上的DHCP,因为实例不直接连接到外部网络,并且浮动IP需要手工分配。

  • Tenant network

租户网络为实例提供内部网络连接。架构确保这种网络在不同租户间分离。demo租户拥有这个网络因为其仅仅为其内的实例提供网络连接。

创建tenant network:

#
source demo-openrc.sh
neutron net-create demo-net

类似于外部网络,您的租户网络也需要附加子网。你可以指定任意有效的子网,因为架构分离了租户网络。默认情况下,这个子网会使用 DHCP,因此您的实例可以获取到 IP 地址。

Example using 192.168.1.0/24:

#
neutron subnet-create demo-net 192.168.1.0/24 \
--name demo-subnet --gateway 192.168.1.1

虚拟路由在两个或多个虚拟网络之间传递网络数据。每个路由需要一个或多个接口和/或提供到指定网络连接的网关。在如下部分,您将创建一个路由然后将您的租户网络和外部网络连接到其上。

在租户网络上创建路由并将外部网络和租户网络附加给它

创建router:

#
neutron router-create demo-router

附加router to the demo tenant subnet:

#
neutron router-interface-add demo-router demo-subnet

附加router to the external network by setting it as the gateway:

#
neutron router-gateway-set demo-router ext-net

  • Verify connectivity

我们建议您在继续进行前验证网络连通性和解决其他任何问题。沿袭外部网络子网使用203.0.113.0/24的例子,租户路由网关应该占用了浮动IP地址范围内的最小IP地址,203.0.113.101。如果您正确的配置了您的外部物理网络和虚拟网络,您应该能够从您的外部物理网络上的任意主机ping这个IP地址。

[Note] Note
如果您在虚拟机上配置您的OpenStack节点,您必须配置管理程序以允许外部网络上的混杂模式。

验证网络的连通性

Ping 租户路由网关:

$ ping -c 4 192.168.56.50
PING 192.168.56.50 (192.168.56.50) 56(84) bytes of data.
64 bytes from 192.168.56.50: icmp_req=1 ttl=64 time=0.619 ms
64 bytes from 192.168.56.50: icmp_req=2 ttl=64 time=0.189 ms
64 bytes from 192.168.56.50: icmp_req=3 ttl=64 time=0.165 ms
64 bytes from 192.168.56.50: icmp_req=4 ttl=64 time=0.216 ms

— 192.168.56.50 ping statistics —
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.165/0.297/0.619/0.187 ms