七、Networking(neutron)
7.1基本概念
网络
Neutron网络目的是(为OpenStack云更灵活地)划分物理网络,在多租户环境下提供给每个租户独立的网络环境。另外,Neutron提供API来实现这种目标。
Neutron中“网络”是一个可以被用户创建的对象,如果要和物理环境下的概念映射的话,这个对象相当于一个巨大的交换机,可以拥有无限多个动态可创建和销毁的虚拟端口。
端口
在物理网络环境中,端口是用于连接设备进入网络的地方。Neutron中的端口起着类似的功能,它是路由器和虚拟机挂接网络的着附点。
路由器
和物理环境下的路由器类似,Neutron中的路由器也是一个路由选择和转发部
件。只不过在Neutron中,它是可以创建和销毁的软部件。
子网 简单地说,子网是由一组IP地址组成的地址池。不同子网间的通信需要路由器
的支持,这个Neutron和物理网络下是一致的。Neutron中子网隶属于网络
neutron服务配置过程:
• 安装并配置controller节点
• 配置先决条件
• 安装网络服务组件
• 配置网络服务组件
• 配置Modular Layer2(ML2)插件
• 配置计算服务使用Neutron
• 完成安装
• 验证
7.2在controller上配置
7.2.1配置先决条件
7.2.1.1创建数据库,完成下列步骤:
a.使用root用户连接mysql数据库
mysql -u root -ppqjpqj
b.创建neutron数据库
CREATE DATABASE neutron;
c.创建数据库用户neutron,并授予neutron用户对neutron数据库完全控制权限
## 注意空格!!曾经我在这死过一次,就因为少写了一个空格,排查好几天好排查出来。
GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'localhost' IDENTIFIED BY 'NEUTRON_DBPASS';
GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'%' IDENTIFIED BY 'NEUTRON_DBPASS';
d. exit 退出数据库连接
7.2.1.2.source admin-openrc.sh7.2.1.3在认证服务中创建网络服务的认证信息,完成下列步骤:
a.创建neutron用户
keystone user-create --name neutron --pass NEUTRON_PASS
+----------+----------------------------------+
| Property | Value |
+----------+----------------------------------+
| email | |
| enabled | True |
| id | 854c37556b2a4007b717d838228ae4f0 |
| name | neutron |
| username | neutron |
+----------+----------------------------------+
b.连接neutron用户到serivce租户和admin角色
keystone user-role-add --user neutron --tenant service --role admin
c.创建neutron服务
keystone service-create --name neutron --type network --description "OpenStack Networking"
+-------------+----------------------------------+
| Property | Value |
+-------------+----------------------------------+
| description | OpenStack Networking |
| enabled | True |
| id | d08fe515a86c4f08a2f69f3993a16cb4 |
| name | neutron |
| type | network |
+-------------+----------------------------------+
d.创建neutron服务端点
keystone endpoint-create \
--service-id $(keystone service-list | awk '/ network / {print $2}') \
--publicurl http://controller.nice.com:9696 \
--adminurl http://controller.nice.com:9696 \
--internalurl http://controller.nice.com:9696 \
--region regionOne
#此段代码不可直接复制粘贴,需要一行一行复制粘贴
如果想一下复制粘贴,用下面调整好格式的
keystone endpoint-create --service-id $(keystone service-list | awk '/ network / {print $2}') --publicurl http://controller.nice.com:9696 --adminurl http://controller.nice.com:9696 --internalurl http://controller.nice.com:9696 --region regionOne
+-------------+----------------------------------+
| Property | Value |
+-------------+----------------------------------+
| adminurl | http://controller.nice.com:9696 |
| id | c9dbaf83e8a14a159350642d8673cebb |
| internalurl | http://controller.nice.com:9696 |
| publicurl | http://controller.nice.com:9696 |
| region | regionOne |
| service_id | d08fe515a86c4f08a2f69f3993a16cb4 |
+-------------+----------------------------------+
7.2.2安装网络服务组件
yum -y install openstack-neutron openstack-neutron-ml2 python-neutronclient which
7.2.3配置网络服务组件
7.2.3.1.vi /etc/neutron/neutron.conf
[database]
connection=mysql://neutron:NEUTRON_DBPASS@controller.nice.com/neutron +566
[DEFAULT]
verbose=True +3
rpc_backend=rabbit +444
rabbit_host=controller.nice.com +343
rabbit_password=guest +359
auth_strategy=keystone +80
[keystone_authtoken] 在小节后面粘贴 +562
auth_uri=http://controller.nice.com:5000/v2.0
dentity_uri=http://controller.nice.com:35357
admin_tenant_name=service
admin_user=neutron
admin_password=NEUTRON_PASS
core_plugin=ml2 +63
service_plugins=router +72
allow_overlapping_ips=True +117
notify_nova_on_port_status_changes=True +236
notify_nova_on_port_data_changes=True +240
nova_url=http://controller.nice.com:8774/v2 +243
nova_admin_auth_url=http://controller.nice.com:35357/v2.0 +258
nova_region_name=regionOne +246
nova_admin_username=nova +249
nova_admin_tenant_id=442be0a6c4794cf8b50efdb94179af22 租户ID +252 # 442be0a6c4794cf8b50efdb94179af22
#先退出文件编辑,通过命令:keystone tenant-get service,获取你自己服务器service租户ID再修改ID号,切不可盲目的、没有头脑的复制粘贴。
nova_admin_password=NOVA_PASS +255
7.2.4配置Modular Layer2(ML2)插件
vi /etc/neutron/plugins/ml2/ml2_conf.ini
[ml2]
type_drivers=flat,gre +5
tenant_network_types=gre +12
mechanism_drivers=openvswitch +17
[ml2_type_gre]
tunnel_id_ranges=1:1000 +49
[securitygroup]
enable_security_group=True +67
enable_ipset=True +71
firewall_driver=neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
#没有,在第72行添加 firewall_driver
7.2.5配置计算服务使用Neutron
vi /etc/nova/nova.conf
[DEFAULT]
network_api_class=nova.network.neutronv2.api.API +1149
security_group_api=neutron +1419
linuxnet_interface_driver=nova.network.linux_net.LinuxOVSInterfaceDriver +1267
firewall_driver=nova.virt.firewall.NoopFirewallDriver +1901
[neutron]
url=http://controller.nice.com:9696 +3143
auth_strategy=keystone +3193
admin_auth_url=http://controller.nice.com:35357/v2.0 +3184
admin_tenant_name=service +3174
admin_username=neutron +3157
admin_password=NEUTRON_PASS +3162
7.2.6完成配置
7.2.6.1为ML2插件配置文件创建连接文件。
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini
7.2.6.2初始化数据库
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
报错信息:
##sqlalchemy.exc.OperationalError: (OperationalError) (1045, "Access denied for user 'mysql'@'controller.nice.com' (using password: YES)") None None##
GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'%' IDENTIFIED BY'NEUTRON_DBPASS'; ##注意空格!!
connection=mysql://mysql://neutron:NEUTRON_DBPASS@controller.nice.com/neutron +566 # 复制粘贴出错
希望你不要犯我之前犯下的低级的错误!
GOOD LUCK!
#验证:
mysql -uroot -ppqjpqj
show databases;
use neutron;
show tables;
+-------------------------------------+
| Tables_in_neutron |
+-------------------------------------+
| agents |
| alembic_version |
| allowedaddresspairs |
| arista_provisioned_nets |
| arista_provisioned_tenants |
| arista_provisioned_vms |
| brocadenetworks |
| brocadeports |
| cisco_credentials |
| cisco_csr_identifier_map |
| cisco_hosting_devices |
| cisco_ml2_apic_contracts |
| cisco_ml2_apic_host_links |
| cisco_ml2_apic_names |
| cisco_ml2_nexusport_bindings |
| cisco_n1kv_multi_segments |
| cisco_n1kv_network_bindings |
| cisco_n1kv_port_bindings |
| cisco_n1kv_profile_bindings |
| cisco_n1kv_trunk_segments |
| cisco_n1kv_vlan_allocations |
| cisco_n1kv_vmnetworks |
| cisco_n1kv_vxlan_allocations |
| cisco_network_profiles |
| cisco_policy_profiles |
| cisco_port_mappings |
| cisco_provider_networks |
| cisco_qos_policies |
| cisco_router_mappings |
| consistencyhashes |
| csnat_l3_agent_bindings |
| dnsnameservers |
| dvr_host_macs |
| embrane_pool_port |
| externalnetworks |
| extradhcpopts |
| firewall_policies |
| firewall_rules |
| firewalls |
| floatingips |
| ha_router_agent_port_bindings |
| ha_router_networks |
| ha_router_vrid_allocations |
| healthmonitors |
| hyperv_network_bindings |
| hyperv_vlan_allocations |
| ikepolicies |
| ipallocationpools |
| ipallocations |
| ipavailabilityranges |
| ipsec_site_connections |
| ipsecpeercidrs |
| ipsecpolicies |
| lsn |
| lsn_port |
| maclearningstates |
| members |
| meteringlabelrules |
| meteringlabels |
| ml2_brocadenetworks |
| ml2_brocadeports |
| ml2_dvr_port_bindings |
| ml2_flat_allocations |
| ml2_gre_allocations |
| ml2_gre_endpoints |
| ml2_network_segments |
| ml2_port_bindings |
| ml2_vlan_allocations |
| ml2_vxlan_allocations |
| ml2_vxlan_endpoints |
| mlnx_network_bindings |
| multi_provider_networks |
| network_bindings |
| network_states |
| networkconnections |
| networkdhcpagentbindings |
| networkflavors |
| networkgatewaydevicereferences |
| networkgatewaydevices |
| networkgateways |
| networkqueuemappings |
| networks |
| networksecuritybindings |
| neutron_nsx_network_mappings |
| neutron_nsx_port_mappings |
| neutron_nsx_router_mappings |
| neutron_nsx_security_group_mappings |
| nexthops |
| nuage_net_partition_router_mapping |
| nuage_net_partitions |
| nuage_provider_net_bindings |
| nuage_subnet_l2dom_mapping |
| ofcfiltermappings |
| ofcnetworkmappings |
| ofcportmappings |
| ofcroutermappings |
| ofctenantmappings |
| ovs_network_bindings |
| ovs_tunnel_allocations |
| ovs_tunnel_endpoints |
| ovs_vlan_allocations |
| packetfilters |
| poolloadbalanceragentbindings |
| poolmonitorassociations |
| pools |
| poolstatisticss |
| port_profile |
| portbindingports |
| portinfos |
| portqueuemappings |
| ports |
| portsecuritybindings |
| providerresourceassociations |
| qosqueues |
| quotas |
| router_extra_attributes |
| routerflavors |
| routerl3agentbindings |
| routerports |
| routerproviders |
| routerroutes |
| routerrules |
| routers |
| routerservicetypebindings |
| securitygroupportbindings |
| securitygrouprules |
| securitygroups |
| segmentation_id_allocation |
| servicerouterbindings |
| sessionpersistences |
| subnetroutes |
| subnets |
| tunnelkeylasts |
| tunnelkeys |
| tz_network_bindings |
| vcns_edge_monitor_bindings |
| vcns_edge_pool_bindings |
| vcns_edge_vip_bindings |
| vcns_firewall_rule_bindings |
| vcns_router_bindings |
| vips |
| vpnservices |
+-------------------------------------+
142 rows in set (0.00 sec)
exit 退出数据库
7.2.6.3重新启动计算服务
systemctl restart openstack-nova-api.service openstack-nova-scheduler.service openstack-nova-conductor.service
7.2.6.4启动网络服务并配置开机自动启动
systemctl enable neutron-server.service
systemctl start neutron-server.service
7.2.7验证
7.2.7.1、执行admin环境变量脚本
source /root/admin-open
7.2.7.2、列出加载的扩展模块,确认成功启动neutron-server进程。
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 |
+-----------------------+-----------------------------------------------+
7.3 network节点
•安装并配置network节点
• 配置先决条件
• 安装网络组件
• 配置网络通用组件
• 配置Modular Layer 2 (ML2) plug-in
• 配置Layer-3 (L3) agent
• 配置DHCP agent
• 配置metadata agent
• 配置Open vSwitch (OVS)服务
• 完成安装
• 验证
7.3.1配置先决条件
7.3.1.1.vi /etc/sysctl.conf #增加下列参数
net.ipv4.ip_forward=1
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
7.3.1.2.sysctl -p #刷新 使更改生效
7.3.2安装网络组件
yum -y install openstack-neutron openstack-neutron-ml2 openstack-neutron-openvswitch
7.3.3配置网络通用组件
7.3.3.1.vi /etc/neutron/neutron.conf
[DEFAULT]
rpc_backend=rabbit +444
rabbit_host=controller.nice.com +343
rabbit_password=guest +359
auth_strategy=keystone +80
core_plugin=ml2 +63
service_plugins=router +72
allow_overlapping_ips=True +117
verbose=True +3
[keystone_authtoken] 在模块下面直接复制、粘贴 +562
auth_uri=http://controller.nice.com:5000/v2.0
identity_uri=http://controller.nice.com:35357
admin_tenant_name=service
admin_user=neutron
admin_password=NEUTRON_PASS
7.3.4配置Modular Layer 2 (ML2) plug-in
vi /etc/neutron/plugins/ml2/ml2_conf.ini
[ml2]
type_drivers=flat,gre +5
tenant_network_types=gre +12
mechanism_drivers=openvswitch +17
[ml2_type_flat]
flat_networks=external +34
[ml2_type_gre]
tunnel_id_ranges=1:1000 +49
[securitygroup]
enable_security_group=True +67
enable_ipset=True +71
firewall_driver=neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
firewall_driver直接粘贴在“enable_ipset = True”下方
[ovs] 在文档最后手动添加 【ovs】模块
[ovs]
local_ip=10.10.10.30
#实体网络ip(第二块网卡ip) 复制粘贴完之后删除!
tunnel_type=gre
enable_tunneling=True
bridge_mappings=external:br-ex
7.3.5配置Layer-3 (L3) agent
vi /etc/neutron/l3_agent.ini
[DEFAULT]
debug=True +3
interface_driver=neutron.agent.linux.interface.OVSInterfaceDriver +7
use_namespaces=True +23
external_network_bridge=br-ex +46
7.3.6配置DHCP agent
7.3.6.1. vi /etc/neutron/dhcp_agent.ini
[DEFAULT]
interface_driver=neutron.agent.linux.interface.OVSInterfaceDriver +12
dhcp_driver=neutron.agent.linux.dhcp.Dnsmasq +31
use_namespaces=True +35
debug=True +3
dnsmasq_config_file=/etc/neutron/dnsmasq-neutron.conf +63
7.3.6.2
vi /etc/neutron/dnsmasq-neutron.conf 新文件 #真实环境省略此步骤
dhcp-option-force=26,1454
user=neutron
group=neutron
7.3.6.3 杀死dnsmasq
pkill dnsmasq
7.3.7配置元数据代理:metadata agent
7.3.7.1 vi /etc/neutron/metadata_agent.ini
[DEFAULT]
debug=True +3
auth_url=http://controller.nice.com:5000/v2.0 +6
auth_region=regionOne +7
admin_tenant_name=service +12
admin_user=neutron +13
admin_password=NEUTRON_PASS +14
nova_metadata_ip=controller.nice.com +20
metadata_proxy_shared_secret=METADATA_SECRET +43
7.3.7.2 controller节点
7.3.7.2.1. vi /etc/nova/nova.conf
[neutron]
service_metadata_proxy=True +3129
metadata_proxy_shared_secret=METADATA_SECRET +3134
7.3.7.2.2.在controller 节点,重新启动compute API服务
systemctl restart openstack-nova-api.service
network节点
7.3.8配置Open vSwitch (OVS)服务
7.3.8.1启动VOS服务并配置开机自动启动:
systemctl enable openvswitch.service
systemctl start openvswitch.service
7.3.8.2添加外部网桥(external birdge)
ovs-vsctl add-br br-ex
7.3.8.3添加一个端口到外部网桥,用于连接外部物理网络
ovs-vsctl add-port br-ex eno50332184 #第三块网卡名-主管外部网络
#注:将INTERFACE_NAME换成实际连接外部网卡接口名。如:eth2或ens224 or eno50332184
#根据个人实际情况填写,切勿盲目照搬照抄!
7.3.9完成安装
7.3.9.1创建网络服务初始化脚本的符号连接
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /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
7.3.9.2启动网络服务并设置开机自动启动
systemctl enable neutron-openvswitch-agent.service neutron-l3-agent.service neutron-dhcp-agent.service neutron-metadata-agent.service neutron-ovs-cleanup.service
systemctl start neutron-openvswitch-agent.service neutron-l3-agent.service neutron-dhcp-agent.service neutron-metadata-agent.service
7.3.10验证:在controller节点执行
7.3.10.1执行admin环境变量脚本
source admin-open
7.3.10.2列出neutron代理,确认启动neutron agents成功。
[root@controller ~]# neutron agent-list
+-------------------+--------------------+------------------+-------+----------------+---------------------------+
| id | agent_type | host | alive | admin_state_up | binary |
+-------------------+--------------------+------------------+-------+----------------+---------------------------+
| 359bf10-4880-b93c-| Open vSwitch agent | network.nice.com | :-) | True | neutron-openvswitch-agent |
| 69adcbef-e7655h42 | Metadata agent | network.nice.com | :-) | True | neutron-metadata-agent |
| ee27f64e-1cd3b190 | L3 agent | network.nice.com | :-) | True | neutron-l3-agent |
| eeb78586-112e9239 | DHCP agent | network.nice.com | :-) | True | neutron-dhcp-agent |
+-------------------+--------------------+------------------+-------+----------------+---------------------------+
##四种类型,全部为True!!
7.4安装并配置compute节点
• 配置先决条件
• 安装网络组件
• 配置网络通用组件
• 配置Modular Layer 2 (ML2) plug-in
• 配置Open vSwitch (OVS) service
• 配置计算服务使用网络
• 完成安装
• 验证
#compute节点
7.4.1配置先决条件
7.4.1.1.vi /etc/sysctl.conf文件,添加下列参数:
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
7.4.1.2.使/etc/sysctl.conf文件中的更改生效:
sysctl -p
7.4.2安装网络组件
yum -y install openstack-neutron-ml2 openstack-neutron-openvswitch
7.4.3配置网络通用组件
7.4.3.1
vi /etc/neutron/neutron.conf
[DEFAULT]
rpc_backend=rabbit +444
rabbit_host=controller.nice.com +343
rabbit_password=guest +359
auth_strategy=keystone +80
core_plugin=ml2 +63
service_plugins=router +72
allow_overlapping_ips=True +117
verbose=True +3
[keystone_authtoken] 将下列内容粘贴在模块下面 +562
auth_uri=http://controller.nice.com:5000/v2.0
identity_uri=http://controller.nice.com:35357
admin_tenant_name=service
admin_user=neutron
admin_password=NEUTRON_PASS
7.4.4配置Modular Layer 2 (ML2) plug-in
7.4.4.1
vi /etc/neutron/plugins/ml2/ml2_conf.ini
[ml2]
type_drivers=flat,gre +5
tenant_network_types=gre +12
mechanism_drivers=openvswitch +17
[ml2_type_gre]
tunnel_id_ranges=1:1000 +49
[securitygroup]
enable_security_group=True +67
enable_ipset=True +71
添加 firewall_driver=neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver +72
[ovs] 模块添加到文件最下方
[ovs]
local_ip=10.10.10.10
#compute第二块网卡ip
tunnel_type=gre
enable_tunneling=True
7.4.4.2配置 Open vSwitch (OVS) service
启动OVS服务并设置开机自动启动:
systemctl enable openvswitch.service
systemctl start openvswitch.service
7.4.5配置计算服务使用网络
vi /etc/nova/nova.conf
[DEFAULT]
network_api_class=nova.network.neutronv2.api.API +1149
security_group_api=neutron +1419
linuxnet_interface_driver=nova.network.linux_net.LinuxOVSInterfaceDriver +1267
firewall_driver=nova.virt.firewall.NoopFirewallDriver +1901
[neutron]
url=http://controller.nice.com:9696 +3143
auth_strategy=keystone +3193
admin_auth_url=http://controller.nice.com:35357/v2.0 +3184
admin_tenant_name=service +3174
admin_username=neutron +3157
admin_password=NEUTRON_PASS +3162
7.4.6完成安装
7.4.6.1、创建网络服务初始化脚本的符号连接
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /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
7.4.6.2、重启计算服务:
systemctl restart openstack-nova-compute.service
7.4.6.3、启动OVS代理服务并设置开机自动启动:
systemctl enable neutron-openvswitch-agent.service
systemctl start neutron-openvswitch-agent.service
7.4.7验证:在controller节点执行
7.4.7.1.执行admin环境变量脚本
source admin-open
7.4.7.2.列出neutron代理,确认启动neutron agents成功。
neutron agent-list
+------------------------------+--------------------+-------------------+-------+----------------+---------------------------+
| id | agent_type | host | alive | admin_state_up | binary |
+------------------------------+--------------------+-------------------+-------+----------------+---------------------------+
| 0fe3c291-c4bd-419f-8b9a4cb7e | DHCP agent | network.nice.com | :-) | True | neutron-dhcp-agent |
| 1fe6b871-ad43-45a1-819042b3b | Open vSwitch agent | computer.nice.com | :-) | True | neutron-openvswitch-agent |
| 910e452a-bc06-44da-958a5a72b | Metadata agent | network.nice.com | :-) | True | neutron-metadata-agent |
| 96b303fe-5aef-4775-a4713ec28 | Open vSwitch agent | network.nice.com | :-) | True | neutron-openvswitch-agent |
| ac570911-c517-47a6-8a88bde7f | L3 agent | network.nice.com | :-) | True | neutron-l3-agent |
+------------------------------+--------------------+-------------------+-------+----------------+---------------------------+
总共五个,alive全部为笑脸,全部为True,缺一不可,如果少的话,翻工去吧!
7.5 实验 controller节点 创建一个外部网络
7.5.1执行admin环境变量脚本
source admin-open
7.5.2创建网络
neutron net-create ext-net --shared --router:external True --provider:physical_network external --provider:network_type flat
+---------------------------+--------------------------------------+
| Field | Value |
+---------------------------+--------------------------------------+
| admin_state_up | True |
| id | 8f121516-2b8d-4944-a64d-4f5df5dd156f |
| name | ext-net |
| provider:network_type | flat |
| provider:physical_network | external |
| provider:segmentation_id | |
| router:external | True |
| shared | True |
| status | ACTIVE |
| subnets | |
| tenant_id | 0f69c355df124daaaa2b58cbc32f05a5 |
+---------------------------+--------------------------------------+
7.5.3创建一个外部网络的子网
#172.16.253.216 network 10.10.10.30 20.20.20.30
创建子网: #一行一行复制粘贴!
neutron subnet-create ext-net --name ext-subnet \
--allocation-pool start=20.20.20.51,end=20.20.20.100 \
--disable-dhcp --gateway 20.20.20.30 20.20.20.0/24
neutron subnet-create ext-net --name ext-subnet --allocation-pool start=20.20.20.51,end=20.20.20.100 --disable-dhcp --gateway 20.20.20.30 20.20.20.0/24
+-------------------+-------------------------------------------------+
| Field | Value |
+-------------------+-------------------------------------------------+
| allocation_pools | {"start": "20.20.20.51", "end": "20.20.20.100"} |
| cidr | 20.20.20.0/24 |
| dns_nameservers | |
| enable_dhcp | False |
| gateway_ip | 20.20.20.30 |
| host_routes | |
| id | 275d740c-11e1-4998-9a8a-3922262487d3 |
| ip_version | 4 |
| ipv6_address_mode | |
| ipv6_ra_mode | |
| name | ext-subnet |
| network_id | 3d789340-6402-4192-beb6-786bb613e3cd |
| tenant_id | f6695c6795d749e19d9981c0f6522756 |
+-------------------+-------------------------------------------------+
#FLOATING_IP_STAR=起始IP
#FLOATING_IP_END=结束IP
#EXTERNAL_NETWORK_GATEWAY=外部网络网关
#EXTERNAL_NETWORK_CIDR=外部网络网段
7.5.4创建一个租户网络
7.5.4.1.执行demo环境变量脚本
source demo-open
7.5.4.2.创建租户网络
neutron net-create demo-net
+-----------------+--------------------------------------+
| Field | Value |
+-----------------+--------------------------------------+
| admin_state_up | True |
| id | 1a52958e-ae27-4601-897e-99e71fc4e589 |
| name | demo-net |
| router:external | False |
| shared | False |
| status | ACTIVE |
| subnets | |
| tenant_id | 3834f5f9a8384a008b6e8ad1effb705e |
+-----------------+--------------------------------------+
7.5.4.3创建一个租户网络的子网
创建子网: 可以是任意网段:我创建的10.68.88.0网段!
#模板:neutron subnet-create demo-net --name demo-subnet --gateway TENANT_NETWORK_GATEWAY TENANT_NETWORK_CIDR
# TENANT_NETWORK_GATEWAY=租户网的网关
命令:
neutron subnet-create demo-net --name demo-subnet --gateway 10.68.88.1 10.68.88.0/24
7.5.4.4在租户网络创建一个路由器,用来连接外部网和租户网
a.创建路由器
neutron router-create demo-router
+-----------------------+--------------------------------------+
| Field | Value |
+-----------------------+--------------------------------------+
| admin_state_up | True |
| external_gateway_info | |
| id | abeb4d55-7da9-4a2d-969a-7d651adf871f |
| name | demo-router |
| routes | |
| status | ACTIVE |
| tenant_id | 3834f5f9a8384a008b6e8ad1effb705e |
+-----------------------+--------------------------------------+
b.附加路由器到demo租户的子网
[root@controller ~]# neutron router-interface-add demo-router demo-subnet
#Added interface 979dc7f8-54d5-46b1-a3c6-4319204b6dfc to router demo-router.
c.通过设置网关,使路由器附加到外部网
[root@controller ~]# neutron router-gateway-set demo-router ext-net
#Set gateway for router demo-router
7.5.4.6确认连接
7.5.4.6.1查看路由器获取到的IP。
neutron router-list
+--------------------------------------+-------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id | name | external_gateway_info |
+--------------------------------------+-------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| abeb4d55-7da9-4a2d-969a-7d651adf871f | demo-router | {"network_id": "a30ed0fe-eebe-497b-8600-e484b0f76e26", "enable_snat": true, "external_fixed_ips": [{"subnet_id": "48bc8afb-c664-419f-a3eb-a6e3aa4e01f7", "ip_address": "20.20.20.51"}]} |
+--------------------------------------+-------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
#id:abeb4d55-7da9-4a2d-969a-7d651adf871f
#name:demo-router
#external_gateway_info:
{"network_id": "a30ed0fe-eebe-497b-8600-e484b0f76e26",
"enable_snat": true,
"external_fixed_ips": [{"subnet_id": "48bc8afb-c664-419f-a3eb-a6e3aa4e01f7", "ip_address": "20.20.20.51"}]}
7.5.4.6.2在任何一台外部主机上ping路由器获取到的外部地址
结语:如果到此,你仍能ping通路由器获取到的外部地址 ,恭喜你,neutron服务完全正常!
别忘了controller、computer、network做个快照! 保留住来之不易的成果。
至此,最大的难关你已经攻克,收拾一下心情,后面还有一些小困难,相信,对于现在的你来说那就是so easy!
加油,继续努力!