OpenStack部署6.0——网络服务(Neutron)

先放个链接,万一有人关注呢

优质文章推荐

↓ ↓ ↓ ↓ 

不会这条命令你还怎么玩Linux

ESXi虚拟化系统创建与应用

Linux网卡配置文件详解



书接上回:OpenStack部署5.0——计算服务(Nova)

概述

在OpenStack项目中,Neutron是负责提供网络连接能力的关键组件,它扮演着构建虚拟网络基础设施的重要角色。Neutron旨在为云环境中的虚拟机实例和其他资源提供高度灵活的网络配置和管理能力,从而满足不同应用场景下的需求。下面将详细介绍Neutron在OpenStack中的网络服务及其主要组件。
主要功能:
虚拟网络: Neutron允许用户创建虚拟网络,这些网络可以包括子网、端口、路由等网络构造。这使得在OpenStack云环境中可以轻松创建和管理多个虚拟网络,为不同的用户或应用提供隔离和定制的网络环境。
SDN服务: Neutron支持多种SDN(软件定义网络)服务,包括开放虚拟交换机(OVS)和VMware NSX等。这使得用户可以创建可编程的虚拟网络,以适应不同的网络需求和拓扑结构。
弹性伸缩: 结合Heat,Neutron可以实现网络配置的自动弹性伸缩。这意味着网络资源可以根据负载或需求自动调整,从而提高整体系统的弹性和性能。
网络访问控制: Neutron提供了网络连接策略的控制,如安全组和防火墙规则等。这使得管理员可以细粒度地控制虚拟机实例之间的网络通信,增强了安全性和隔离性。
负载均衡: 通过与负载均衡服务的集成,Neutron可以为虚拟网络提供负载均衡功能。这对于分布式应用和服务的性能优化至关重要。
API服务: Neutron为用户和管理员提供了基于REST的API接口,以便于配置和管理网络资源。通过这些API,用户可以编程性地创建、修改和删除虚拟网络,实现网络资源的自动化管理。
主要组件:
neutron-server: 这是Neutron提供API服务的核心组件,它接收来自用户和管理员的网络操作请求,并将其转化为底层的网络配置。
neutron-openvswitch-agent: 在计算节点上运行的代理,负责管理和操作开放虚拟交换机(OVS)。它实现了虚拟机实例和虚拟网络之间的连接。
neutron-l3-agent: 提供L3转发和NAT(网络地址转换)功能。它使虚拟机实例可以与外部网络进行通信。
neutron-dhcp-agent: 这个代理负责为虚拟机实例提供DHCP服务,自动分配IP地址和其他网络配置。
Neutron作为OpenStack中网络服务的核心组件,为用户提供了强大的网络配置和管理能力。从创建虚拟网络到实现SDN和负载均衡,再到网络访问控制和弹性伸缩,Neutron覆盖了众多网络方面的需求。通过其各个组件的协同工作,Neutron为OpenStack用户提供了灵活、可编程和安全的网络服务,成为构建虚拟化网络环境的不可或缺的一部分。

环境部署

进入控制节点的数据库中

 mysql -uroot -p123
创建neutron数据库
create database neutron;

授权数据库

grant all privileges on neutron.* to 'neutron'@'localhost' identified by '123';grant all privileges on neutron.* to 'neutron'@'%' identified by '123';

退出数据库

获得admin凭证用于获取管理员权限

source admin-openrc
创建一个网络服务neutron用户
penstack user create --domain default --password-prompt neutron

输出两次密码,创建成功。输出如下

User Password:Repeat User Password:+---------------------+----------------------------------+| Field               | Value                            |+---------------------+----------------------------------+| domain_id           | default                          || enabled             | True                             || id                  | c02d02e643094a06b7f4d2480a64eaab || name                | neutron                          || options             | {}                               || password_expires_at | None                             |+---------------------+----------------------------------+

将网络服务neutron用户添加到具有admin角色的服务项目

openstack role add --project service --user neutron admin
创建neutron服务实体
openstack service create --name neutron --description "OpenStack Networking" network

输出如下

+-------------+----------------------------------+| Field       | Value                            |+-------------+----------------------------------+| description | OpenStack Networking             || enabled     | True                             || id          | 9127b90902b343efa417ee93ea2a709a || name        | neutron                          || type        | network                          |+-------------+----------------------------------+
创建网络服务API端点public
openstack endpoint create --region RegionOne network public http://controller:9696

输出如下

+--------------+----------------------------------+| Field        | Value                            |+--------------+----------------------------------+| enabled      | True                             || id           | 5a3d8feb4aad4dfd98424dc112bcc151 || interface    | public                           || region       | RegionOne                        || region_id    | RegionOne                        || service_id   | 9127b90902b343efa417ee93ea2a709a || service_name | neutron                          || service_type | network                          || url          | http://controller:9696           |+--------------+----------------------------------+
创建网络服务API端点internal
openstack endpoint create --region RegionOne network internal http://controller:9696

输出如下

+--------------+----------------------------------+| Field        | Value                            |+--------------+----------------------------------+| enabled      | True                             || id           | c585760abb754b799466ef36f6945c24 || interface    | internal                         || region       | RegionOne                        || region_id    | RegionOne                        || service_id   | 9127b90902b343efa417ee93ea2a709a || service_name | neutron                          || service_type | network                          || url          | http://controller:9696           |+--------------+----------------------------------+
创建网络服务API端点admin
openstack endpoint create --region RegionOne network admin http://controller:9696

输出如下

+--------------+----------------------------------+| Field        | Value                            |+--------------+----------------------------------+| enabled      | True                             || id           | ee40f2aab2d64194b53247d1751f8f9e || interface    | admin                            || region       | RegionOne                        || region_id    | RegionOne                        || service_id   | 9127b90902b343efa417ee93ea2a709a || service_name | neutron                          || service_type | network                          || url          | http://controller:9696           |+--------------+----------------------------------+

在控制节点安装与配置网络

安装计算服务相关组件

yum install openstack-neutron openstack-neutron-ml2 openstack-neutron-linuxbridge ebtables
编辑/etc/neutron/neutron.conf文件
 vi /etc/neutron/neutron.conf
在database模块中,配置数据库访问
[database]# ...connection = mysql+pymysql://neutron:123@controller/neutron
在DEFAULT模块中,启用ML2(Modular Layer 2,模块化第2层)插件并禁止使用其他插件
[DEFAULT]# ...core_plugin = ml2service_plugins =
在DEFAULT部分,配置RabbitMQ消息队列访问
[DEFAULT]# ...transport_url = rabbit://openstack:123@controller
在DEFAULT和keystone_authtoken模块,配置身份认证服务访问
[DEFAULT]# ...auth_strategy = keystone
[keystone_authtoken]# ...www_authenticate_uri = http://controller:5000auth_url = http://controller:5000memcached_servers = controller:11211auth_type = passwordproject_domain_name = defaultuser_domain_name = defaultproject_name = serviceusername = neutronpassword = 123
在DEFAULT和nova模块中,配置网络服务用于通知计算节点的网络拓扑更改信息
[DEFAULT]# ...notify_nova_on_port_status_changes = truenotify_nova_on_port_data_changes = true
[nova]# ...auth_url = http://controller:5000auth_type = passwordproject_domain_name = defaultuser_domain_name = defaultregion_name = RegionOneproject_name = serviceusername = novapassword = 123
在oslo_concurrency部分中,配置锁定路径
[oslo_concurrency]# ...lock_path = /var/lib/neutron/tmp
编辑/etc/neutron/plugins/ml2/ml2_conf.ini文件
vi /etc/neutron/plugins/ml2/ml2_conf.ini
在ml2模块中,开启平面和VLAN网络
[ml2]# ...type_drivers = flat,vlan
在ml2模块中,禁止使用自助服务网络
[ml2]# ...tenant_network_types =
在ml2模块中,开启Linux桥接机制
[ml2]# ...mechanism_drivers = linuxbridge
在ml2模块中,开启端口安全扩展驱动程序
[ml2]# ...extension_drivers = port_security
在ml2_type_flat模块中,把公共虚拟网络配置为平面网络
[ml2_type_flat]# ...flat_networks = provider
在securitygroup模块中,启用ipset(iptables的一个扩展)以提高安全组规则的效率
[securitygroup]# ...enable_ipset = true
编辑/etc/neutron/plugins/ml2/linuxbridge_agent.ini文件
vi /etc/neutron/plugins/ml2/linuxbridge_agent.ini
在linux_bridge模块中,把公共虚拟网络和公共物理网络接口进行对接
[linux_bridge]physical_interface_mappings = provider:PROVIDER_INTERFACE_NAME

这里需要,将PROVIDER_INTERFACE_NAME替换为底层的公共物理网络接口的名称。

在vxlan模块中,禁止VXLAN覆盖网络
[vxlan]enable_vxlan = false
在securitygroup模块中,开启安全组并配置Linux桥接iptables防火墙驱动程序
[securitygroup]# ...enable_security_group = truefirewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
编辑/etc/neutron/dhcp_agent.ini文件
vi /etc/neutron/dhcp_agent.ini
在[DEFAULT]部分中,配置Linux桥接接口驱动程序、Dnsmasq DHCP驱动程序,并开启使用隔离元数据,以便在公共网络上的实例可以通过网络访问元数据
[DEFAULT]# ...interface_driver = linuxbridgedhcp_driver = neutron.agent.linux.dhcp.Dnsmasqenable_isolated_metadata = true
编辑/etc/neutron/metadata_agent.ini文件
vi /etc/neutron/metadata_agent.ini
在DEFAULT模块中,配置元数据主机和共享密钥
[DEFAULT]# ...nova_metadata_host = controllermetadata_proxy_shared_secret = 123
“metadata_proxy_shared_secret”表示元数据代理的密码。
编辑/etc/nova/nova.conf文件
vi /etc/nova/nova.conf
在neutron模块中,配置访问参数,启用元数据代理并配置密钥
[neutron]# ...auth_url = http://controller:5000auth_type = passwordproject_domain_name = defaultuser_domain_name = defaultregion_name = RegionOneproject_name = serviceusername = neutronpassword = 123service_metadata_proxy = truemetadata_proxy_shared_secret = 123

网络服务初始化脚本需要一个超链接/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
将信息同步到数据库
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
重启计算API服务
systemctl restart openstack-nova-api.service
开启网络服务并把它们配置为在系统启动时启动
systemctl enable neutron-server.service  neutron-linuxbridge-agent.service neutron-dhcp-agent.service  neutron-metadata-agent.servicesystemctl start neutron-server.service  neutron-linuxbridge-agent.service neutron-dhcp-agent.service  neutron-metadata-agent.service

在计算节点安装与配置网络服务

计算节点主要用于处理实例的连接和安全组。
在计算节点上安装相关组件
yum install openstack-neutron-linuxbridge ebtables ipset -y
编辑/etc/neutron/neutron.conf文件
vi /etc/neutron/neutron.conf
在database模块中,注释掉所有connection选项,因为计算节点不直接访问数据库。
在DEFAULT模块,配置RabbitMQ消息队列访问
[DEFAULT]# ...transport_url = rabbit://123@controller
在DEFAULT和keystone_authtoken模块,配置身份认证服务访问
[DEFAULT]# ...auth_strategy = keystone
[keystone_authtoken]# ...www_authenticate_uri = http://controller:5000auth_url = http://controller:5000memcached_servers = controller:11211auth_type = passwordproject_domain_name = defaultuser_domain_name = defaultproject_name = serviceusername = neutronpassword = 123
在oslo_concurrency模块中,配置锁定路径
[oslo_concurrency]# ...lock_path = /var/lib/neutron/tmp
配置Linux桥接代理,编辑/etc/neutron/plugins/ml2/linuxbridge_agent.ini文件
vi /etc/neutron/plugins/ml2/linuxbridge_agent.ini
在linux_bridge模块中,把公共虚拟网络和公共物理网络接口进行对接
[linux_bridge]physical_interface_mappings = provider:ens33
“ens33”表示底层的公共物理网络接口的名称。
在vxlan模块中,禁用VXLAN覆盖网络
[vxlan]enable_vxlan = false
在securitygroup模块中,开启使用安全组并配置Linux桥接iptables防火墙驱动程序
[securitygroup]# ...enable_security_group = truefirewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
编辑/etc/nova/nova.conf文件
vi /etc/nova/nova.conf
在neutron模块,配置访问参数
[neutron]# ...auth_url = http://controller:5000auth_type = passwordproject_domain_name = defaultuser_domain_name = defaultregion_name = RegionOneproject_name = serviceusername = neutronpassword = 123
重启计算服务
systemctl restart openstack-nova-compute.service
开启linux桥接代理并将其配置为在系统启动时启动
systemctl enable neutron-linuxbridge-agent.servicesystemctl start neutron-linuxbridge-agent.service

验证操作

获取管理员权限

source admin-openrc
使用以下命令列出加载的扩展,验证neutron-server进程是否成功启动
openstack extension list --network

输出如下

+----------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+| Name                                                                                                                                                           | Alias                          | Description                                                                                                                                              |+----------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+| Subnet Pool Prefix Operations                                                                                                                                  | subnetpool-prefix-ops          | Provides support for adjusting the prefix list of subnet pools                                                                                           || Default Subnetpools                                                                                                                                            | default-subnetpools            | Provides ability to mark and use a subnetpool as the default.                                                                                            || Network IP Availability                                                                                                                                        | network-ip-availability        | Provides IP availability data for each network and subnet.                                                                                               || Network Availability Zone                                                                                                                                      | network_availability_zone      | Availability zone support for network.                                                                                                                   || Subnet Onboard                                                                                                                                                 | subnet_onboard                 | Provides support for onboarding subnets into subnet pools                                                                                                || Network MTU (writable)                                                                                                                                         | net-mtu-writable               | Provides a writable MTU attribute for a network resource.                                                                                                || Port Binding                                                                                                                                                   | binding                        | Expose port bindings of a virtual port to external application                                                                                           || agent                                                                                                                                                          | agent                          | The agent management extension.                                                                                                                          || Subnet Allocation                                                                                                                                              | subnet_allocation              | Enables allocation of subnets from a subnet pool                                                                                                         || DHCP Agent Scheduler                                                                                                                                           | dhcp_agent_scheduler           | Schedule networks among dhcp agents                                                                                                                      || Neutron external network                                                                                                                                       | external-net                   | Adds external network attribute to network resource.                                                                                                     || Empty String Filtering Extension                                                                                                                               | empty-string-filtering         | Allow filtering by attributes with empty string value                                                                                                    || Neutron Service Flavors                                                                                                                                        | flavors                        | Flavor specification for Neutron advanced services.                                                                                                      || Network MTU                                                                                                                                                    | net-mtu                        | Provides MTU attribute for a network resource.                                                                                                           || Availability Zone                                                                                                                                              | availability_zone              | The availability zone extension.                                                                                                                         || Quota management support                                                                                                                                       | quotas                         | Expose functions for quotas management per tenant                                                                                                        || Tag support for resources with standard attribute: subnet, trunk, network_segment_range, router, network, policy, subnetpool, port, security_group, floatingip | standard-attr-tag              | Enables to set tag on resources with standard attribute.                                                                                                 || Availability Zone Filter Extension                                                                                                                             | availability_zone_filter       | Add filter parameters to AvailabilityZone resource                                                                                                       || If-Match constraints based on revision_number                                                                                                                  | revision-if-match              | Extension indicating that If-Match based on revision_number is supported.                                                                                || Filter parameters validation                                                                                                                                   | filter-validation              | Provides validation on filter parameters.                                                                                                                || Multi Provider Network                                                                                                                                         | multi-provider                 | Expose mapping of virtual networks to multiple physical networks                                                                                         || Quota details management support                                                                                                                               | quota_details                  | Expose functions for quotas usage statistics per project                                                                                                 || Address scope                                                                                                                                                  | address-scope                  | Address scopes extension.                                                                                                                                || Agent's Resource View Synced to Placement                                                                                                                      | agent-resources-synced         | Stores success/failure of last sync to Placement                                                                                                         || Subnet service types                                                                                                                                           | subnet-service-types           | Provides ability to set the subnet service_types field                                                                                                   || Neutron Port MAC address regenerate                                                                                                                            | port-mac-address-regenerate    | Network port MAC address regenerate                                                                                                                      || Add security_group type to network RBAC                                                                                                                        | rbac-security-groups           | Add security_group type to network RBAC                                                                                                                  || Provider Network                                                                                                                                               | provider                       | Expose mapping of virtual networks to physical networks                                                                                                  || Neutron Service Type Management                                                                                                                                | service-type                   | API for retrieving service providers for Neutron advanced services                                                                                       || Neutron Extra DHCP options                                                                                                                                     | extra_dhcp_opt                 | Extra options configuration for DHCP. For example PXE boot options to DHCP clients can be specified (e.g. tftp-server, server-ip-address, bootfile-name) || Port filtering on security groups                                                                                                                              | port-security-groups-filtering | Provides security groups filtering when listing ports                                                                                                    || Resource timestamps                                                                                                                                            | standard-attr-timestamp        | Adds created_at and updated_at fields to all Neutron resources that have Neutron standard attributes.                                                    || Resource revision numbers                                                                                                                                      | standard-attr-revisions        | This extension will display the revision number of neutron resources.                                                                                    || Pagination support                                                                                                                                             | pagination                     | Extension that indicates that pagination is enabled.                                                                                                     || Sorting support                                                                                                                                                | sorting                        | Extension that indicates that sorting is enabled.                                                                                                        || security-group                                                                                                                                                 | security-group                 | The security groups extension.                                                                                                                           || RBAC Policies                                                                                                                                                  | rbac-policies                  | Allows creation and modification of policies that control tenant access to resources.                                                                    || standard-attr-description                                                                                                                                      | standard-attr-description      | Extension to add descriptions to standard attributes                                                                                                     || IP address substring filtering                                                                                                                                 | ip-substring-filtering         | Provides IP address substring filtering when listing ports                                                                                               || Port Security                                                                                                                                                  | port-security                  | Provides port security                                                                                                                                   || Allowed Address Pairs                                                                                                                                          | allowed-address-pairs          | Provides allowed address pairs                                                                                                                           || project_id field enabled                                                                                                                                       | project-id                     | Extension that indicates that project_id field is enabled.                                                                                               || Port Bindings Extended                                                                                                                                         | binding-extended               | Expose port bindings of a virtual port to external application                                                                                           |+----------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
使用以下命令列出代理用来验证neutron代理是否成功转发
openstack network agent list

输出如下

+--------------------------------------+--------------------+------------+-------------------+-------+-------+---------------------------+   | ID                                   | Agent Type         | Host       | Availability Zone | Alive | State | Binary                    |   +--------------------------------------+--------------------+------------+-------------------+-------+-------+---------------------------+   | 04d08376-8e40-49b1-90a6-3db9949050df | DHCP agent         | controller | nova              | :-)   | UP    | neutron-dhcp-agent        |   | 3fabf2f2-869d-489c-b5cd-52a9bb2457a0 | Metadata agent     | controller | None              | :-)   | UP    | neutron-metadata-agent    |   | 4608ae34-7d72-4365-8db5-e4895b8386d6 | Linux bridge agent | compute    | None              | :-)   | UP    | neutron-linuxbridge-agent |   | 6ed003a1-d711-46c5-94f0-77acef42c0d6 | Linux bridge agent | controller | None              | :-)   | UP    | neutron-linuxbridge-agent |   +--------------------------------------+--------------------+------------+-------------------+-------+-------+---------------------------+

未完待续。。。。

来不及解释了,快上车!(进群看公告)

欢迎新的小伙伴加入!在这里,我们鼓励大家积极参与群内讨论和交流,分享自己的见解和经验,一起学习和成长。同时,也欢迎大家提出问题和建议,让我们不断改进和完善这个平台。

               点个在看,你最好看!

请使用浏览器的分享功能分享到微信等