Openstack 网络服务Neutron [五]

Neutron介绍 
neutron是openstack重要组件之一,在以前是时候没有neutron项目

image_1b2kngmcvdjff1p1iv514b4jru9.png-90.5kB
早期的时候是没有neutron,早期所使用的网络的nova-network,经过版本改变才有个neutron

Openstack Networking 
网络: 
  在实际的物理环境下,我们使用交换机或者集线器把多个计算机连接起来形成了网络。在Neutron的世界里,网络也是将多个不同的云主机连接起来。 
子网: 
  在实际的物理环境下,在一个网络中。我们可以将网络划分成多为逻辑子网。在Neutron的世界里,子网也是隶属于网络下的。 
端口: 
  是实际的物理环境下,每个子网或者网络,都有很多的端口,比如交换机端口来供计算机连接。在Neutron的世界端口也是隶属于子网下,云主机的网卡会对应到一个端口上。 
路由器: 
  在实际的网络环境下,不同网络或者不同逻辑子网之间如果需要进行通信,需要通过路由器进行路由。在Neutron的实际里路由也是这个作用。用来连接不同的网络或者子网。


Neutron 架构介绍 
image_1b2knirjd1tf514ndcrsbtk1hc1m.png-67.4kB
Neutron也分为控制节点计算节点

openstack默认的网络是单一扁平网络(虚拟机跟宿主机在同一个网段)在官方文档上称为提供者网络

安装 
数据库我们在一开始就已经创建完成 
keystone用户我们也已经创建完成

配置网络选项 
  您可以部署网络服务使用选项1和选项2两种架构中的一种来部署网络服务。 
选项1采用尽可能简单的架构进行部署,只支持实例连接到公有网络(外部网络)。没有私有网络(个人网络),路由器以及浮动IP地址。只有admin或者其他特权用户才可以管理公有网络 
选项2在选项1的基础上多了layer-3服务,支持实例连接到私有网络。demo或者其他没有特权的用户可以管理自己的私有网络,包含连接公网和私网的路由器。另外,浮动IP地址可以让实例使用私有网络连接到外部网络,例如互联网 
  典型的私有网络一般使用覆盖网络。覆盖网络,例如VXLAN包含了额外的数据头,这些数据头增加了开销,减少了有效内容和用户数据的可用空间。在不了解虚拟网络架构的情况下,实例尝试用以太网 最大传输单元 (MTU) 1500字节发送数据包。网络服务会自动给实例提供正确的MTU的值通过DHCP的方式。但是,一些云镜像并没有使用DHCP或者忽视了DHCP MTU选项,要求使用元数据或者脚本来进行配置

我们先进行配置公共网络

控制节点安装组件

 
 
  1. [root@linux-node1 ~]#yum install openstack-neutron openstack-neutron-ml2 \
  2. openstack-neutron-linuxbridge ebtables

提示:neutron和其他组件的小区别是配置完数据库之后不可以马上进行同步,它还依赖其他配置文件

编辑/etc/neutron/neutron.conf文件并完成如下操作

 
 
  1. 在[database]配置数据库访问
  2. [root@linux-node1 ~]# vim /etc/neutron/neutron.conf
  3. 684 connection = mysql+pymysql://neutron:[email protected]/neutron

提示:不需要同步数据库,684为684行

在 [DEFAULT] 和 [keystone_authtoken] 部分,配置认证服务访问

 
 
  1. [DEFAULT]
  2. auth_strategy = keystone
  3. [keystone_authtoken]
  4. auth_uri = http://192.168.56.11:5000
  5. auth_url = http://192.168.56.11:35357
  6. memcached_servers = 192.168.56.11:11211
  7. auth_type = password
  8. project_domain_name = default
  9. user_domain_name = default
  10. project_name = service
  11. username = neutron
  12. password = neutron

rabbitmq(消息队列)配置

 
 
  1. rpc_backend = rabbit
  2. rabbit_host = 192.168.56.11
  3. rabbit_userid = openstack
  4. rabbit_password = openstack

neutron核心配置有2个 
启动ML2插件并禁用其他插件

 
 
  1. [DEFAULT]
  2. core_plugin = m12
  3. service_plugins =
  4. 提示:service_plugins等号后面什么都不写就是禁用其他插件

配置网络服务来通知计算节点的网络拓扑变化:(配置nova相关)

 
 
  1. [DEFAULT]
  2. notify_nova_on_port_status_changes = true
  3. notify_nova_on_port_data_changes = true

提示:简单的来说就是端口发生变化通知nova

 
 
  1. [nova]
  2. nova标签的配置其实就是keystone的配置
  3. auth_url = http://192.168.56.11:35357
  4. auth_type = password
  5. project_domain_name = default
  6. user_domain_name = default
  7. region_name = RegionOne
  8. project_name = service
  9. username = nova
  10. password = nova

配置锁路径

 
 
  1. [oslo_concurrency]
  2. lock_path = /var/lib/neutron/tmp

neutron配置小结:

 
 
  1. [root@linux-node1 ~]# grep '^[a-z]' /etc/neutron/neutron.conf
  2. auth_strategy = keystone #使用keystone进行验证
  3. core_plugin = ml2 #使用ml2插件
  4. service_plugins = #不使用其他插件
  5. notify_nova_on_port_status_changes = true #端口改变通知nova
  6. notify_nova_on_port_data_changes = true #端口改变通知nova
  7. rpc_backend = rabbit #使用rabbit
  8. connection = mysql+pymysql://neutron:[email protected]/neutron #数据库连接地址
  9. auth_uri = http://192.168.56.11:5000 #neutron keystone的配置
  10. auth_url = http://192.168.56.11:35357 #neutron keystone的配置
  11. memcached_servers = 192.168.56.11:11211 #neutron keystone的配置
  12. auth_type = password #neutron keystone的配置
  13. project_domain_name = default #neutron keystone的配置
  14. user_domain_name = default #neutron keystone的配置
  15. project_name = service #neutron keystone的配置
  16. username = neutron #neutron keystone的配置
  17. password = neutron #neutron keystone的配置
  18. auth_url = http://192.168.56.11:35357 #neutron nova的配置
  19. auth_type = password #neutron nova的配置
  20. project_domain_name = default #neutron nova的配置
  21. user_domain_name = default #neutron nova的配置
  22. region_name = RegionOne #neutron nova的配置
  23. project_name = service #neutron nova的配置
  24. username = nova #neutron nova的配置
  25. password = nova #neutron nova的配置
  26. lock_path = /var/lib/neutron/tmp #锁路径
  27. rabbit_host = 192.168.56.11 #rabbitmq配置
  28. rabbit_userid = openstack #rabbitmq配置
  29. rabbit_password = openstack #rabbitmq配置

配置Modular Layer 2 (ML2

ML2插件使用Linuxbridge机制来为实例创建layer-2虚拟网络基础设施 
编辑配置文件/etc/neutron/plugins/ml2/ml2_conf.ini

驱动的选择

 
 
  1. [ml2]
  2. type_drivers = flat,vlan,gre,vxlan,geneve

设置使用那几个插件来创建网络

 
 
  1. [ml2]
  2. mechanism_drivers = linuxbridge,openvswitch

提示:我们可以写多个,不管用不用都可以写上去

禁用私有网络

 
 
  1. [ml2]
  2. tenant_network_types =

启动端口安全扩展驱动

 
 
  1. [ml2]
  2. extension_drivers = port_security

[ml2_type_flat]部分,配置公共虚拟网络为flat网络

 
 
  1. [ml2_type_flat]
  2. flat_networks = public
  3. #配置公共的网络

在 [securitygroup]部分,启用 ipset增加安全组规则的高效性:

 
 
  1. [securitygroup]
  2. enable_ipset = true

提示:ml2_conf里面的网络类型很多,我们需要那种网络类型配置即可

ML2插件配置小结:

 
 
  1. [root@linux-node1 ~]# grep '^[a-z]' /etc/neutron/plugins/ml2/ml2_conf.ini
  2. type_drivers = flat,vlan,gre,vxlan,geneve #驱动类型
  3. tenant_network_types = #租户的网络类型
  4. mechanism_drivers = linuxbridge,openvswitch #创建网络插件
  5. extension_drivers = port_security #打开端口安全
  6. flat_networks = public #网络类型public
  7. enable_ipset = true #开启ipset

配置Linuxbridge代理 
编辑/etc/neutron/plugins/ml2/linuxbridge_agent.ini文件并且完成以下操作

 
 
  1. 在[linux_bridge]部分,将公共虚拟网络和公共物理网络接口对应起来:
  2. [linux_bridge]
  3. physical_interface_mappings = public:eth0
  4. #是什么网卡就修改什么网卡,如果不是eth0请修改对应网卡

[vxlan]部分,禁止VXLAN覆盖网络:

 
 
  1. [vxlan]
  2. enable_vxlan = false

[securitygroup]部分,启用安全组并配置 Linuxbridge iptables firewall driver:

 
 
  1. [securitygroup]
  2. ...
  3. enable_security_group = True
  4. firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
  5. #启动安全组并设置防火墙驱动

Linuxbridge代理总结如下:

 
 
  1. [root@linux-node1 ~]# grep '^[a-z]' /etc/neutron/plugins/ml2/linuxbridge_agent.ini
  2. physical_interface_mappings = public:eth0 #网络映射
  3. firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver #防火墙
  4. enable_security_group = true #打开安全组
  5. enable_vxlan = false #关闭vxlan

配置DHCP代理

编辑/etc/neutron/dhcp_agent.ini文件并完成下面的操作:

在[DEFAULT]部分,配置Linuxbridge驱动接口,DHCP驱动并启用隔离元数据,这样在公共网络上的实例就可以通过网络来访问元数据

 
 
  1. [DEFAULT]
  2. interface_driver = neutron.agent.linux.interface.BridgeInterfaceDriver
  3. #虚拟接口驱动,使用Linuxbridge
  4. dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq
  5. #dhcp驱动,默认使用Dnsmasq(是一个小的开源项目)来提供dhcp服务
  6. enable_isolated_metadata = false
  7. #刷新路由使用

DHCP配置小结

 
 
  1. [root@linux-node1 ~]# grep '^[a-z]' /etc/neutron/dhcp_agent.ini
  2. interface_driver = neutron.agent.linux.interface.BridgeInterfaceDriver #底层插件Linuxbridge
  3. dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq #DHCP
  4. enable_isolated_metadata = false #推送路由使用

配置元数据代理 
<Metadata agent>负责提供配置信息,例如:访问实例的凭证

编辑/etc/neutron/metadata_agent.ini文件并完成以下操作:

[DEFAULT]部分,配置元数据主机以及共享密码:

 
 
  1. nova_metadata_ip = 192.168.56.11 #元数据主机
  2. metadata_proxy_shared_secret = abcdocker #共享密钥

提示:这个共享密钥就是一个字符串

配置网络服务(nova-api) 
  编辑/etc/nova/nova.conf文件并完成以下操作: 
[neutron]部分,配置访问参数,启用元数据代理并设置密码:

 
 
  1. url = http://192.168.56.11:9696
  2. auth_url = http://192.168.56.11:35357
  3. auth_type = password
  4. project_domain_name = default
  5. user_domain_name = default
  6. region_name = RegionOne
  7. project_name = service
  8. username = neutron
  9. password = neutron

提示:9696neutron-server的端口

 
 
  1. [neutron]
  2. service_metadata_proxy=true
  3. metadata_proxy_shared_secret = abcdocker #共享密钥

网络服务初始化脚本需要一个超链接 /etc/neutron/plugin.ini指向ML2插件配置文件/etc/neutron/plugins/ml2/ml2_conf.ini 如果超链接不存在,使用下面的命令创建它:

 
 
  1. [root@linux-node1 ~]# ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini

提示:这里我们使用那个插件就用它做一个软连接即可

同步数据库

 
 
  1. [root@linux-node1 ~]# su -s /bin/sh -c "neutron-db-manage --config-file /etc/neutron/neutron.conf \
  2. --config-file /etc/neutron/plugins/ml2/ml2_conf.ini upgrade head" neutron

注:数据库的同步发生在 Networking 之后,因为脚本需要完成服务器和插件的配置文件。

重启计算API 服务:

 
 
  1. [root@linux-node1 ~]# systemctl restart openstack-nova-api.service

当系统启动时,启动Networking服务并配置它启动。

对于种网络选项:

 
 
  1. [root@linux-node1 ~]#systemctl enable neutron-server.service \
  2. neutron-linuxbridge-agent.service neutron-dhcp-agent.service \
  3. neutron-metadata-agent.service
  4. [root@linux-node1 ~]#systemctl start neutron-server.service \
  5. neutron-linuxbridge-agent.service neutron-dhcp-agent.service \
  6. neutron-metadata-agent.service

现在还需要将neutronkeystone上进行注册

创建neutron服务实体:

 
 
  1. [root@linux-node1 ~]# source admin-openstack.sh
  2. [root@linux-node1 ~]#openstack service create --name neutron \
  3. --description "OpenStack Networking" network

创建网络服务API端点:

 
 
  1. [root@linux-node1 ~]#openstack endpoint create --region RegionOne \
  2. network public http://192.168.56.11:9696
  3. [root@linux-node1 ~]# openstack endpoint create --region RegionOne network internal http://192.168.56.11:9696
  4. [root@linux-node1 ~]# openstack endpoint create --region RegionOne network admin http://192.168.56.11:9696

检查neutron是否安装成功

 
 
  1. [root@linux-node1 ~]# neutron agent-list
  2. +---------------------+--------------------+---------------------+-------------------+-------+----------------+-------------------------+
  3. | id | agent_type | host | availability_zone | alive | admin_state_up | binary |
  4. +---------------------+--------------------+---------------------+-------------------+-------+----------------+-------------------------+
  5. | b41a9731-2bff-4257- | DHCP agent | linux- | nova | :-) | True | neutron-dhcp-agent |
  6. | a3e9-91b13f568932 | | node1.abcdocker.com | | | | |
  7. | de108bab-f33a-4319 | Linux bridge agent | linux- | | :-) | True | neutron-linuxbridge- |
  8. | -8caf-dd5fbda74d7e | | node1.abcdocker.com | | | | agent |
  9. | f8286325-19ad-43ae- | Metadata agent | linux- | | :-) | True | neutron-metadata-agent |
  10. | a25a-c7c2ceca7aed | | node1.abcdocker.com | | | | |
  11. +---------------------+--------------------+---------------------+-------------------+-------+----------------+-------------------------+

image_1b2ko7ub51se1a091r308lg13ol13.png-37.3kB

配置neutron计算节点

安装组件,安装的服务器在192.168.56.12 linux-node2.com上面

 
 
  1. [root@linux-node2 ~]# yum install openstack-neutron-linuxbridge ebtables ipset -y

因为控制节点跟计算节点配置几乎一样,我们直接复制控制节点的文件进行修改控制节点拷贝

 
 
  1. [root@linux-node1 ~]# scp /etc/neutron/neutron.conf root@192.168.56.12:/etc/neutron

在计算节点进行修改配置文件权限

 
 
  1. [root@linux-node2 ~]# chown -R root:neutron /etc/neutron/neutron.conf
  2. [root@linux-node2 ~]# ll /etc/neutron/neutron.conf
  3. -rw-r----- 1 root neutron 53140 Nov 21 15:13 /etc/neutron/neutron.conf

计算节点设置

 
 
  1. [root@linux-node2 ~]# vim /etc/neutron/neutron.conf
  2. #connection = #删除mysql连接路径
  3. [nova] #删除nova标签下所有配置
  4. #notify_nova_on_port_status_changes = true #注释
  5. #notify_nova_on_port_data_changes = true #注释
  6. #core_plugin = ml2 #注释插件
  7. #service_plugins = #注释

计算节点跟控制节点进行对比

 
 
  1. [root@linux-node2 ~]# diff /etc/neutron/neutron.conf /tmp/neutron.conf
  2. 30c30
  3. < #core_plugin = ml2
  4. ---
  5. > core_plugin = ml2
  6. 33c33
  7. < #service_plugins =
  8. ---
  9. > service_plugins =
  10. 137c137
  11. < #notify_nova_on_port_status_changes = true
  12. ---
  13. > notify_nova_on_port_status_changes = true
  14. 141c141
  15. < #notify_nova_on_port_data_changes = true
  16. ---
  17. > notify_nova_on_port_data_changes = true
  18. 684c684
  19. < #connection =
  20. ---
  21. > connection = mysql+pymysql://neutron:[email protected]/neutron
  22. 936a937,944
  23. > auth_url = http://192.168.56.11:35357
  24. > auth_type = password
  25. > project_domain_name = default
  26. > user_domain_name = default
  27. > region_name = RegionOne
  28. > project_name = service
  29. > username = nova
  30. > password = nova

提示:不注释也没有问题,但是为了环境保持一致还是注释掉比较好

为计算节点配置网络服务 
我们可以直接复制控制节点的配置进行修改

 
 
  1. [root@linux-node1 ~]# vim /etc/nova/nova.conf
  2. [neutron]
  3. url = http://192.168.56.11:9696
  4. auth_url = http://192.168.56.11:35357
  5. auth_type = password
  6. project_domain_name = default
  7. user_domain_name = default
  8. region_name = RegionOne
  9. project_name = service
  10. username = neutron
  11. password = neutron

提示:在控制节点的时候我们在nova的配置文件中配置了neutron的节点选项,在neutron配置文件中配置了nova的选项。在计算节点的nova上要配置neutron

在计算节点配置Linuxbridge 
配置网络选项 
友情提示:这里的配置和控制节点配置一模一样 
这里我们还是直接拷贝控制节点的/etc/neutron/plugins/ml2/linuxbridge_agent.ini

拷贝

 
 
  1. [root@linux-node1 ~]# scp /etc/neutron/plugins/ml2/linuxbridge_agent.ini 192.168.56.12:/etc/neutron/plugins/ml2/
  2. root@192.168.56.12's password:
  3. linuxbridge_agent.ini

查看

 
 
  1. [root@linux-node2 ~]# ll /etc/neutron/plugins/ml2/linuxbridge_agent.ini
  2. -rw-r----- 1 root root 7924 Nov 21 16:26 /etc/neutron/plugins/ml2/linuxbridge_agent.ini
  3. [root@linux-node2 ~]# grep '^[a-z]' /etc/neutron/plugins/ml2/linuxbridge_agent.ini
  4. physical_interface_mappings = public:eth0
  5. firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
  6. enable_security_group = true
  7. enable_vxlan = false
  8. [root@linux-node2 ~]# chown -R root:neutron /etc/neutron/plugins/ml2/linuxbridge_agent.ini

重启计算节点nova-compute

 
 
  1. [root@linux-node2 ~]#systemctl restart openstack-nova-compute.service

启动Linuxbridge代理并设置开启启动

 
 
  1. [root@linux-node2 ~]# systemctl enable neutron-linuxbridge-agent.service
  2. Created symlink from /etc/systemd/system/multi-user.target.wants/neutron-linuxbridge-agent.service to /usr/lib/systemd/system/neutron-linuxbridge-agent.service.
  3. [root@linux-node2 ~]# systemctl start neutron-linuxbridge-agent.service

进入控制节点,进行检查

 
 
  1. [root@linux-node1 ~]# source admin-openstack.sh
  2. [root@linux-node1 ~]# neutron agent-list
  3. +---------------------+--------------------+---------------------+-------------------+-------+----------------+-------------------------+
  4. | id | agent_type | host | availability_zone | alive | admin_state_up | binary |
  5. +---------------------+--------------------+---------------------+-------------------+-------+----------------+-------------------------+
  6. | b41a9731-2bff-4257- | DHCP agent | linux- | nova | :-) | True | neutron-dhcp-agent |
  7. | a3e9-91b13f568932 | | node1.abcdocker.com | | | | |
  8. | de108bab-f33a-4319 | Linux bridge agent | linux- | | :-) | True | neutron-linuxbridge- |
  9. | -8caf-dd5fbda74d7e | | node1.abcdocker.com | | | | agent |
  10. | eb879cc3-ca1d-470b- | Linux bridge agent | linux- | | :-) | True | neutron-linuxbridge- |
  11. | 9fe6-b0e5c2fedf2a | | node2.abcdocker.com | | | | agent |
  12. | f8286325-19ad-43ae- | Metadata agent | linux- | | :-) | True | neutron-metadata-agent |
  13. | a25a-c7c2ceca7aed | | node1.abcdocker.com | | | | |
  14. +---------------------+--------------------+---------------------+-------------------+-------+----------------+-------------------------+

image_1b2koffje1mu3hk11jf31oqsm4p1g.png-52.8kB

提示:如果网络接口不是eth0,你的配置文件没有修改就会启动不起来

故障解决套路: 
1、netstat -lntup确认端口是否监听 
2、openstack service list确保服务创建 
openstack endpoint list确保三个endpoint创建无误 
3、vim修改配置文件debug=true 重启 – 执行命令 – 看日志

M版本中文文档:http://docs.openstack.org/mitaka/zh_CN/install-guide-rdo/keystone-install.html

猜你喜欢

转载自blog.csdn.net/shangyuanlang/article/details/80893855