一、实验目的
- 熟悉Linux基本服务配置;
- 理解OpenStack基本环境中各组件用途。
二、实验环境
- 实验资源 云主机Vultr、DigitalOCean等
- 软件环境 CentOS 7
三、实验内容
6.2.在 keystone 数据库中注册 neutron 相关服务
1)创建 neutron 数据库,授予权限 mysql -p123456 CREATE DATABASE neutron; GRANT ALL PRIVILEGES ON neutron.* TO ‘neutron’@‘localhost’ IDENTIFIED BY ‘neutron’; GRANT ALL PRIVILEGES ON neutron.* TO ‘neutron’@’%’ IDENTIFIED BY ‘neutron’; exit  2)在 keystone 上创建 neutron 用户 source admin-openrc openstack user create --domain default --password=neutron neutron openstack user list  3)将 neutron 添加到 service 项目并授予 admin 角色 该命令无输出 openstack role add --project service --user neutron admin  4)创建 neutron service openstack service create --name neutron --description “OpenStack Networking” network openstack service list  5)创建 neutron 网络服务的 API 端点 openstack endpoint create --region RegionOne network public http://controller:9696 openstack endpoint create --region RegionOne network internal http://controller:9696 openstack endpoint create --region RegionOne network admin http://controller:9696 openstack endpoint list     
6.3.在控制节点安装 neutron 网络组件 neutron 的网络提供了两种方式
https://docs.openstack.org/neutron/rocky/install/controller-install-option1-rdo.html 以下为第一种 Networking Option 1: Provider networks 1)安装 neutron 软件包 yum install openstack-neutron openstack-neutron-ml2 openstack-neutron-linuxbridge ebtables -y  2)快速配置 /etc/neutron/neutron.conf openstack-config --set /etc/neutron/neutron.conf database connection mysql+pymysql://neutron:neutron@controller/neutron openstack-config --set /etc/neutron/neutron.conf DEFAULT core_plugin ml2 openstack-config --set /etc/neutron/neutron.conf DEFAULT service_plugins openstack-config --set /etc/neutron/neutron.conf DEFAULT transport_url rabbit://openstack:openstack@controller openstack-config --set /etc/neutron/neutron.conf DEFAULT auth_strategy keystone openstack-config --set /etc/neutron/neutron.conf keystone_authtoken www_authenticate_uri http://controller:5000 openstack-config --set /etc/neutron/neutron.conf keystone_authtoken auth_url http://controller:5000 openstack-config --set /etc/neutron/neutron.conf keystone_authtoken memcached_servers controller:11211 openstack-config --set /etc/neutron/neutron.conf keystone_authtoken auth_type password openstack-config --set /etc/neutron/neutron.conf keystone_authtoken project_domain_name default openstack-config --set /etc/neutron/neutron.conf keystone_authtoken user_domain_name default openstack-config --set /etc/neutron/neutron.conf keystone_authtoken project_name service openstack-config --set /etc/neutron/neutron.conf keystone_authtoken username neutron openstack-config --set /etc/neutron/neutron.conf keystone_authtoken password neutron openstack-config --set /etc/neutron/neutron.conf DEFAULT notify_nova_on_port_status_changes True openstack-config --set /etc/neutron/neutron.conf DEFAULT notify_nova_on_port_data_changes True openstack-config --set /etc/neutron/neutron.conf nova auth_url http://controller:5000 openstack-config --set /etc/neutron/neutron.conf nova auth_type password openstack-config --set /etc/neutron/neutron.conf nova project_domain_name default openstack-config --set /etc/neutron/neutron.conf nova user_domain_name default openstack-config --set /etc/neutron/neutron.conf nova region_name RegionOne openstack-config --set /etc/neutron/neutron.conf nova project_name service openstack-config --set /etc/neutron/neutron.conf nova username nova openstack-config --set /etc/neutron/neutron.conf nova password nova openstack-config --set /etc/neutron/neutron.conf oslo_concurrency lock_path /var/lib/neutron/tmp 查看配置 egrep -v ‘($|#)’ /etc/neutron/neutron.conf   
3)快速配置/etc/neutron/plugins/ml2/ml2_conf.ini openstack-config --set /etc/neutron/plugins/ml2/ml2_conf.ini ml2 type_drivers flat,vlan openstack-config --set /etc/neutron/plugins/ml2/ml2_conf.ini ml2 tenant_network_types openstack-config --set /etc/neutron/plugins/ml2/ml2_conf.ini ml2 mechanism_drivers linuxbridge openstack-config --set /etc/neutron/plugins/ml2/ml2_conf.ini ml2 extension_drivers port_security openstack-config --set /etc/neutron/plugins/ml2/ml2_conf.ini ml2_type_flat flat_networks provider openstack-config --set /etc/neutron/plugins/ml2/ml2_conf.ini securitygroup enable_ipset True 查看配置 egrep -v ‘($|#)’ /etc/neutron/plugins/ml2/ml2_conf.ini  
4)快速配置/etc/neutron/plugins/ml2/linuxbridge_agent.ini openstack-config --set /etc/neutron/plugins/ml2/linuxbridge_agent.ini linux_bridge physical_interface_mappings provider:enp0s8 openstack-config --set /etc/neutron/plugins/ml2/linuxbridge_agent.ini vxlan enable_vxlan False openstack-config --set /etc/neutron/plugins/ml2/linuxbridge_agent.ini securitygroup enable_security_group True openstack-config --set /etc/neutron/plugins/ml2/linuxbridge_agent.ini securitygroup firewall_driver neutron.agent.linux.iptables_firewall.IptablesFirewallDriver 查看配置 egrep -v ‘($|#)’ /etc/neutron/plugins/ml2/linuxbridge_agent.ini
参数在启动 neutron-linuxbridge-agent.service 的时候会自动设置为 1 sysctl net.bridge.bridge-nf-call-iptables sysctl net.bridge.bridge-nf-call-ip6tables     5)快速配置/etc/neutron/dhcp_agent.ini openstack-config --set /etc/neutron/dhcp_agent.ini DEFAULT interface_driver linuxbridge openstack-config --set /etc/neutron/dhcp_agent.ini DEFAULT dhcp_driver neutron.agent.linux.dhcp.Dnsmasq openstack-config --set /etc/neutron/dhcp_agent.ini DEFAULT enable_isolated_metadata True 查看配置 egrep -v ‘($|#)’ /etc/neutron/dhcp_agent.ini  
6)快速配置/etc/neutron/metadata_agent.ini openstack-config --set /etc/neutron/metadata_agent.ini DEFAULT nova_metadata_host controller openstack-config --set /etc/neutron/metadata_agent.ini DEFAULT metadata_proxy_shared_secret neutron 查看配置 egrep -v ‘($|#)’ /etc/neutron/metadata_agent.ini  
7)配置计算服务使用网络服务 快速配置/etc/nova/nova.conf,将 neutron 添加到计算节点中 openstack-config --set /etc/nova/nova.conf neutron url http://controller:9696 openstack-config --set /etc/nova/nova.conf neutron auth_url http://controller:5000 openstack-config --set /etc/nova/nova.conf neutron auth_type password openstack-config --set /etc/nova/nova.conf neutron project_domain_name default openstack-config --set /etc/nova/nova.conf neutron user_domain_name default openstack-config --set /etc/nova/nova.conf neutron region_name RegionOne openstack-config --set /etc/nova/nova.conf neutron project_name service openstack-config --set /etc/nova/nova.conf neutron username neutron openstack-config --set /etc/nova/nova.conf neutron password neutron openstack-config --set /etc/nova/nova.conf neutron service_metadata_proxy true openstack-config --set /etc/nova/nova.conf neutron metadata_proxy_shared_secret neutron 查看配置 egrep -v ‘($|#)’ /etc/nova/nova.conf    8)初始化安装网络插件 创建网络插件的链接,初始化网络的脚本插件会用到/etc/neutron/plugin.ini,需要使用 ML2 的插件进行提供 ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini  9)同步数据库 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   10)重启 nova_api 服务 systemctl restart openstack-nova-api.service  11)启动 neutron 服务并设置开机启动 启动 4 个服务 systemctl start neutron-server.service neutron-linuxbridge-agent.service neutron-dhcp-agent.service neutron-metadata-agent.service systemctl status neutron-server.service neutron-linuxbridge-agent.service neutron-dhcp-agent.service neutron-metadata-agent.service systemctl enable neutron-server.service neutron-linuxbridge-agent.service neutron-dhcp-agent.service neutron-metadata-agent.service systemctl list-unit-files |grep neutron* |grep enabled   
6.4.在计算节点安装 neutron 网络组件
#Install and configure compute node https://docs.openstack.org/neutron/rocky/install/compute-install-rdo.html 1)安装 neutron 组件 yum install openstack-neutron-linuxbridge ebtables ipset -y  2)快速配置/etc/neutron/neutron.conf openstack-config --set /etc/neutron/neutron.conf DEFAULT transport_url rabbit://openstack:openstack@controller openstack-config --set /etc/neutron/neutron.conf DEFAULT auth_strategy keystone openstack-config --set /etc/neutron/neutron.conf keystone_authtoken www_authenticate_uri http://controller:5000 openstack-config --set /etc/neutron/neutron.conf keystone_authtoken auth_url http://controller:5000 openstack-config --set /etc/neutron/neutron.conf keystone_authtoken memcached_servers controller:11211 openstack-config --set /etc/neutron/neutron.conf keystone_authtoken auth_type password openstack-config --set /etc/neutron/neutron.conf keystone_authtoken project_domain_name default openstack-config --set /etc/neutron/neutron.conf keystone_authtoken user_domain_name default openstack-config --set /etc/neutron/neutron.conf keystone_authtoken project_name service openstack-config --set /etc/neutron/neutron.conf keystone_authtoken username neutron openstack-config --set /etc/neutron/neutron.conf keystone_authtoken password neutron openstack-config --set /etc/neutron/neutron.conf oslo_concurrency lock_path /var/lib/neutron/tmp 查看配置 egrep -v ‘($|#)’ /etc/neutron/neutron.conf   
3)快速配置/etc/neutron/plugins/ml2/linuxbridge_agent.ini openstack-config --set /etc/neutron/plugins/ml2/linuxbridge_agent.ini linux_bridge physical_interface_mappings provider:enp0s8 openstack-config --set /etc/neutron/plugins/ml2/linuxbridge_agent.ini vxlan enable_vxlan false openstack-config --set /etc/neutron/plugins/ml2/linuxbridge_agent.ini securitygroup enable_security_group true openstack-config --set /etc/neutron/plugins/ml2/linuxbridge_agent.ini securitygroup firewall_driver neutron.agent.linux.iptables_firewall.IptablesFirewallDriver 第一个选项 physical_interface_mappings 选项要配置计算节点自身的网卡名称 provider:enp0s8 查看配置 egrep -v ‘($|#)’ /etc/neutron/plugins/ml2/linuxbridge_agent.ini   
4)配置 nova 计算服务与 neutron 网络服务协同工作 快速配置/etc/nova/nova.conf openstack-config --set /etc/nova/nova.conf neutron url http://controller:9696 openstack-config --set /etc/nova/nova.conf neutron auth_url http://controller:5000 openstack-config --set /etc/nova/nova.conf neutron auth_type password openstack-config --set /etc/nova/nova.conf neutron project_domain_name default openstack-config --set /etc/nova/nova.conf neutron user_domain_name default openstack-config --set /etc/nova/nova.conf neutron region_name RegionOne openstack-config --set /etc/nova/nova.conf neutron project_name service openstack-config --set /etc/nova/nova.conf neutron username neutron openstack-config --set /etc/nova/nova.conf neutron password neutron 查看配置 egrep -v ‘($|#)’ /etc/nova/nova.conf    5)重启计算节点 systemctl restart openstack-nova-compute.service systemctl status openstack-nova-compute.service  6)启动 neutron 网络组件,并配置开机自启动 需启动 1 个服务 systemctl start neutron-linuxbridge-agent.service systemctl status neutron-linuxbridge-agent.service systemctl enable neutron-linuxbridge-agent.service systemctl list-unit-files |grep neutron* |grep enabled  
6.5.在控制节点检查确认 neutron 服务安装成功
#Verify operation https://docs.openstack.org/neutron/rocky/install/verify.html 以下命令在控制节点执行 1)获取管理权限 source admin-openrc  2)列表查看加载的网络插件 openstack extension list --network  3)查看网络代理列表 openstack network agent list  正常情况下:控制节点有 3 个服务,计算节点有 1 个服务
总结
一、Neutron概述 ??Neutron是 OpenStack项目中负责提供网络服务的组件,它基于软件定义网络的思想,实现了网络虚拟化下的资源管理。Neutron 的设计目标是实现“网络即服务(Networking as a Service)”,在设计上遵循了基于 SDN 实现网络虚拟化的原则,在实现上充分利用了 Linux 系统上的各种网络相关的技术。 二、Neutron功能
- 二层交换
Neutron支持多种虚拟交换机,一般使用Linux Bridge和Open vSwitch创建传统的VLAN网络,以及基于隧道技术的Overlay网络,如VxLAN和GRE(Linux Bridge 目前只支持 VxLAN)。 - 三层路由
Neutron从Juno版开始正式加入的DVR(Distributed Virtual Router)服务,它将原本集中在网络节点的部分服务分散到了计算节点上。可以通过namespace中使用ip route或者iptables实现路由或NAT,也可以通过openflow给OpenvSwitch下发流表来实现。 - 负载均衡
LBaaS 支持多种负载均衡产品和方案,不同的实现以 Plugin 的形式集成到 Neutron,通过HAProxy来实现。 - 防火墙
Neutron有两种方式来保障instance和网络的安全性,分别是安全组以及防火墙功能,均可以通过iptables来实现,前者是限制进出instance的网络包,后者是进出虚拟路由器的网络包。 三、Network - Local
Local网络,本地的一个Linux Bridge,除了虚拟机的虚拟网卡不连接其他的网络设备,实际场景很少使用,可以忽略。 - Flat
Flat网络,不带vlan tag的网络,相当于Local网络的Linux Bridge连接到一个物理网卡,该网络中的instance能与同网络的instance通信,且可以跨多个节点,实际场景也很少用到。 - VLAN
VlAN网络,可以跨节点,目前是私有云网络应用较多。 - VXALN
VXLAN网络,是基于隧道技术的 overlay 网络,通过唯一的VNI区分于其他 vxlan 网络。vxlan中数据包通过VNI封装成UPD包进行传输,因为二层的包通过封装在三层传输,能够克服vlan和物理网络基础设施的限制。 - GRE
GRE网络,与vxlan类似的一种overlay网络,使用IP包进行封装。 四、Neutron架构 Neutron采用分布式架构,由多个组件共同对外提供网络服务,如下图所示:  由上图可以看到Neutron有以下组件构成: 1.Neutron Server:对外提供OpenStack网络API,接收请求,并调用Plugin处理请求。 2.Plugin:处理Neutron Server发来的请求,维护OpenStack逻辑网络的状态,并调用Agent处理请求。 3.Agent:处理Plugin的请求,负责在Network Provider上真正实现各种网络功能。 4.Network Provider:提供网络服务的虚拟或者物理网络设备,比如Linux Bridge,OpenVSwitch或者其他支持Neutron的物理交换机。 5.Queue:Neutron Server,Plugin和Agent之间通过Messaging Queue通信和调用。 6.Database:存放OpenStack的网络状态信息,包括Network,Subnet,Port,Router等。  1.Neutron通过Plugin和Agent提供的网络服务。 2.Plugin位于Neutron Server,包括Core Plugin和Service Plugin。 3.Agent位于各个节点,负责实现网络服务。 4.Core Plugin提供L2功能,ML2是推荐的plugin。 5.使用最广泛的L2 Agent是Linux Bridage和OpenvSwitch。 6.Service Plugin和Agent提供扩展功能,包括DHCP, Routing, Load Balancer, Firewall, VPN等。
|