OpenStack 安装:neutron服务

时间:2021-07-31 14:33:14

在上一篇中介绍了Nova的安装配置,这一篇介绍neutron

  • 首先,创建neutron用户并设置密码为neutron
[root@linux-node1 ~]# openstack user create --domain default --password-prompt neutron
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field | Value |
+---------------------+----------------------------------+
| domain_id | default |
| enabled | True |
| id | 0e2ce721eca14c688627df21da78cc4e |
| name | neutron |
| options | {} |
| password_expires_at | None |
+---------------------+----------------------------------+
  • 给neutron用户授予admin角色
[root@linux-node1 ~]# 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 | 98cc414411714278a541de8653eefcb0 |
| name | neutron |
| type | network |
+-------------+----------------------------------+
  • 创建neutron服务API端点
openstack endpoint create --region RegionOne \
network public http://192.168.56.11:9696

+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | fc0ce5260d50460399bd160db2034569 |
| interface | public |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 98cc414411714278a541de8653eefcb0 |
| service_name | neutron |
| service_type | network |
| url | http://192.168.56.11:9696 |
+--------------+----------------------------------+openstack endpoint create --region RegionOne \
network internal http://192.168.56.11:9696

+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | a1107a5752f149a0988ee2d63c3fce8e |
| interface | internal |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 98cc414411714278a541de8653eefcb0 |
| service_name | neutron |
| service_type | network |
| url | http://192.168.56.11:9696 |
+--------------+----------------------------------+openstack endpoint create --region RegionOne \
network admin http://192.168.56.11:9696

+--------------+----------------------------------+
| Field | Value |
+--------------+----------------------------------+
| enabled | True |
| id | 1e3729ff74bd4f59b6aa5f7c170e21d2 |
| interface | admin |
| region | RegionOne |
| region_id | RegionOne |
| service_id | 98cc414411714278a541de8653eefcb0 |
| service_name | neutron |
| service_type | network |
| url | http://192.168.56.11:9696 |
+--------------+----------------------------------+
  • 验证用户和服务
[root@linux-node1 ~]# openstack user list
+----------------------------------+-----------+
| ID | Name |
+----------------------------------+-----------+
| 0e2ce721eca14c688627df21da78cc4e | neutron |
| 27080769990347169fdc6bf81fe9ebd1 | placement |
| 291f02337e514343a09a92932a86fd22 | demo |
| 31a0d9b7dd5f47b4b30ed4a77500a307 | glance |
| 34c7be4d612a45b4830304af29eb010e | nova |
| d010fba89633421a800698b0e5300d50 | admin |
+----------------------------------+-----------+
[root@linux-node1 ~]# openstack service list
+----------------------------------+-----------+-----------+
| ID | Name | Type |
+----------------------------------+-----------+-----------+
| 325ab5f400f14fc485eb4231dab6d74d | keystone | identity |
| 344d25c79f1b412cb0c5958bd8242b2c | placement | placement |
| 4c4dd5eb35324b568cd9722f174a632b | glance | image |
| 98cc414411714278a541de8653eefcb0 | neutron | network |
| bf254b3182e04256897e925632f171d0 | nova | compute |
+----------------------------------+-----------+-----------+

在本示例中,我们选择网络为provider networks

  • 编辑/etc/neutron/neutron.conf,并修改如下配置:

[DEFAULT]
auth_strategy = keystone
core_plugin = ml2
service_plugins =
notify_nova_on_port_status_changes = true
notify_nova_on_port_data_changes = true
transport_url = rabbit://openstack:openstack@192.168.56.11
[database]
connection =  mysql+pymysql://neutron:neutron@192.168.56.11/neutron
[keystone_authtoken]
auth_uri = http://192.168.56.11:5000
auth_url = http://192.168.56.11:35357
memcached_servers = 192.168.56.11:
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = neutron
password = neutron
[nova]
auth_url = http://192.168.56.11:35357 
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = nova
password = nova
[oslo_concurrency]
lock_path = /var/lib/neutron/tmp

配置Linux桥接代理

  • 编辑/etc/neutron/plugins/ml2/linuxbridge_agent.ini,并作出如下修改:

[linux_bridge]
physical_interface_mappings = provider:eth0 
[securitygroup]
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver 
enable_security_group = true
[vxlan]
enable_vxlan = false
  • 编辑/etc/neutron/plugins/ml2/ml2_conf.ini并作出如下修改:

[ml2]
type_drivers = local,flat,vlan,gre,vxlan,geneve 
tenant_network_types =
mechanism_drivers = linuxbridge
extension_drivers = port_security
[ml2_type_flat]
flat_networks = provider 
[securitygroup]
enable_ipset = true
  • 编辑/etc/neutron/dhcp_agent.ini ,并作出如下修改:
[DEFAULT]

interface_driver = linuxbridge
dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq
enable_isolated_metadata = true

配置metadata代理

  • 编辑/etc/neutron/metadata_agent.ini并作出如下修改:

[DEFAULT]
nova_metadata_host = 192.168.56.11 
metadata_proxy_shared_secret = openstack

为neutron配置Nova服务

  • 编辑/etc/nova/nova.conf,并作出如下修改:
[neutron]
url = http://192.168.56.11:9696
auth_url = http://192.168.56.11:35357
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = neutron
password = neutron
service_metadata_proxy = true
metadata_proxy_shared_secret = openstack
  • 网络服务初始化脚本需要一个链接由/etc/neutron/plugin.ini指向ML2插件配置文件/etc/neutron/plugins/ml2/ml2_conf.ini
[root@linux-node1 ~]# 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

INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
.....
  • 因为修改过Nova文件,现在需要重启Nova服务
[root@linux-node1 ~]# systemctl restart openstack-nova-api.service
[root@linux-node1 ~]#
  • 启动neutron并设置为开机启动
systemctl enable neutron-server.service \
neutron-linuxbridge-agent.service neutron-dhcp-agent.service \
neutron-metadata-
agent.service
Created symlink from /etc/systemd/system/multi-user.target.wants/neutron-
server.service to /usr/lib/systemd/system/neutron-server.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/neutron-
linuxbridge-agent.service to /usr/lib/systemd/system/neutron-linuxbridge-
agent.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/neutron-dhcp-
agent.service to /usr/lib/systemd/system/neutron-dhcp-agent.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/neutron-
metadata-agent.service to /usr/lib/systemd/system/neutron-metadata-
agent.service.
systemctl start neutron-server.service \
neutron-linuxbridge-agent.service neutron-dhcp-agent.service \
neutron-metadata-agent.service
  • 验证配置是否正确
[root@linux-node1 ~]# openstack network agent list
+--------------------------------------+--------------------+-------------------------+-------------------+-------+-------+---------------------------+
| ID | Agent Type | Host | Availability Zone | Alive | State | Binary |
+--------------------------------------+--------------------+-------------------------+-------------------+-------+-------+---------------------------+
| 22e10474-f526-4b7c-bd41-2345e69255ee | DHCP agent | linux-node1.example.com | nova | :-) | UP | neutron-dhcp-agent |
| 796a0e3b-baa5-4ef5-b155-495f48857b43 | Linux bridge agent | linux-node1.example.com | None | :-) | UP | neutron-linuxbridge-agent |
| fb02118a-d96c-43e6-994a-971f0682ef3f | Metadata agent | linux-node1.example.com | None | :-) | UP | neutron-metadata-agent |
+--------------------------------------+--------------------+-------------------------+-------------------+-------+-------+---------------------------+

计算节点

  • 在node2上编辑/etc/neutron/neutron.conf并作出如下修改

[DEFAULT]
auth_strategy = keystone 
transport_url = rabbit://openstack:openstack@192.168.56.11
[keystone_authtoken]
auth_uri = http://192.168.56.11:5000 
auth_url = http://192.168.56.11:35357
memcached_servers = 192.168.56.11:
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = neutron
password = neutron
[oslo_concurrency]
lock_path = /var/lib/neutron/tmp

配置Linux桥接代理

  • 编辑/etc/neutron/plugins/ml2/linuxbridge_agent.ini并作出如下修改

[linux_bridge]
physical_interface_mappings = provider:eth0 
[securitygroup]
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver 
enable_security_group = true
[vxlan]
enable_vxlan = false

为neutron服务配置Nova服务

  • 编辑/etc/nova/nova.conf并作出如下修改:
[neutron]
url = http://192.168.56.11:9696
auth_url = http://192.168.56.11:35357
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = neutron
password = neutron
  • 重启Nova服务
[root@linux-node2 nova]# systemctl restart openstack-nova-compute.service
  • 启动neutron服务并设置为开机启动
[root@linux-node2 nova]# systemctl enable neutron-linuxbridge-agent.service
Created symlink from /etc/systemd/system/multi-
user.target.wants/neutron-linuxbridge-agent.service to
/usr/lib/systemd/system/neutron-linuxbridge-agent.service.
[root@linux-node2 nova]# systemctl start neutron-linuxbridge-agent.service
  • 验证配置是否正确
[root@linux-node1 ~]# openstack network agent list
+--------------------------------------+--------------------+-------------------------+-------------------+-------+-------+---------------------------+
| ID | Agent Type | Host | Availability Zone | Alive | State | Binary |
+--------------------------------------+--------------------+-------------------------+-------------------+-------+-------+---------------------------+
| 22e10474-f526-4b7c-bd41-2345e69255ee | DHCP agent | linux-node1.example.com | nova | :-) | UP | neutron-dhcp-agent |
| 796a0e3b-baa5-4ef5-b155-495f48857b43 | Linux bridge agent | linux-node1.example.com | None | :-) | UP | neutron-linuxbridge-agent |
| b0207456-29b8-4ff1-a9e9-4d4aa22e42fe | Linux bridge agent | linux-node2.example.com | None | :-) | UP | neutron-linuxbridge-agent |
| fb02118a-d96c-43e6-994a-971f0682ef3f | Metadata agent | linux-node1.example.com | None | :-) | UP | neutron-metadata-agent |
+--------------------------------------+--------------------+-------------------------+-------------------+-------+-------+---------------------------+
[root@linux-node1 ~]# openstack compute service list
+----+------------------+-------------------------+----------+---------+-------+----------------------------+
| ID | Binary | Host | Zone | Status | State | Updated At |
+----+------------------+-------------------------+----------+---------+-------+----------------------------+
| | nova-consoleauth | linux-node1.example.com | internal | enabled | up | --12T08::33.000000 |
| | nova-scheduler | linux-node1.example.com | internal | enabled | up | --12T08::31.000000 |
| | nova-conductor | linux-node1.example.com | internal | enabled | up | --12T08::40.000000 |
| | nova-compute | linux-node2.example.com | nova | enabled | up | --12T08::36.000000 |
+----+------------------+-------------------------+----------+---------+-------+----------------------------+
  • 创建网络
openstack network create  --share --external \
--provider-physical-network provider \
--provider-network-type flat provider
+---------------------------+--------------------------------------+
| Field | Value |
+---------------------------+--------------------------------------+
| admin_state_up | UP |
| availability_zone_hints | |
| availability_zones | |
| created_at | --12T08::03Z |
| description | |
| dns_domain | None |
| id | 59cd11d3-3d7b-4da3-8cbf-a5fece6be63b |
| ipv4_address_scope | None |
| ipv6_address_scope | None |
| is_default | None |
| is_vlan_transparent | None |
| mtu | |
| name | provider |
| port_security_enabled | True |
| project_id | fb6761ab3d3d43569d5fdfafcdfa5e28 |
| provider:network_type | flat |
| provider:physical_network | provider |
| provider:segmentation_id | None |
| qos_policy_id | None |
| revision_number | |
| router:external | External |
| segments | None |
| shared | True |
| status | ACTIVE |
| subnets | |
| tags | |
| updated_at | --12T08::03Z |
+---------------------------+--------------------------------------+
  • 验证网络是否创建
[root@linux-node1 ~]# openstack network list
+--------------------------------------+----------+---------+
| ID | Name | Subnets |
+--------------------------------------+----------+---------+
| 59cd11d3-3d7b-4da3-8cbf-a5fece6be63b | provider | |
+--------------------------------------+----------+---------+
  • 创建子网
openstack subnet create --network provider \
--allocation-pool start=192.168.56.100,end=192.168.56.200 \
--dns-nameserver 223.5.5.5 --gateway 192.168.56.2 \
--subnet-range 192.168.56.0/ provider
+-------------------------+--------------------------------------+
| Field | Value |
+-------------------------+--------------------------------------+
| allocation_pools | 192.168.56.100-192.168.56.200 |
| cidr | 192.168.56.0/ |
| created_at | --12T08::11Z |
| description | |
| dns_nameservers | 223.5.5.5 |
| enable_dhcp | True |
| gateway_ip | 192.168.56.2 |
| host_routes | |
| id | 50340b32-3f7f-4e8f-be72-673b9f701e4d |
| ip_version | |
| ipv6_address_mode | None |
| ipv6_ra_mode | None |
| name | provider |
| network_id | 59cd11d3-3d7b-4da3-8cbf-a5fece6be63b |
| project_id | fb6761ab3d3d43569d5fdfafcdfa5e28 |
| revision_number | |
| segment_id | None |
| service_types | |
| subnetpool_id | None |
| tags | |
| updated_at | --12T08::11Z |
| use_default_subnet_pool | None |
+-------------------------+--------------------------------------+
  • 验证子网是否创建
[root@linux-node1 ~]# openstack subnet list
+--------------------------------------+----------+--------------------------------------+-----------------+
| ID | Name | Network | Subnet |
+--------------------------------------+----------+--------------------------------------+-----------------+
| 50340b32-3f7f-4e8f-be72-673b9f701e4d | provider | 59cd11d3-3d7b-4da3-8cbf-a5fece6be63b | 192.168.56.0/ |
+--------------------------------------+----------+--------------------------------------+-----------------+
  • 创建虚拟机
[root@linux-node1 ~]# openstack flavor create --id  --vcpus  --ram  --disk  m1.nano
+----------------------------+---------+
| Field | Value |
+----------------------------+---------+
| OS-FLV-DISABLED:disabled | False |
| OS-FLV-EXT-DATA:ephemeral | |
| disk | |
| id | |
| name | m1.nano |
| os-flavor-access:is_public | True |
| properties | |
| ram | |
| rxtx_factor | 1.0 |
| swap | |
| vcpus | |
+----------------------------+---------+
  • 使用demo环境变量并创建key
[root@linux-node1 ~]# source demo-openstack.sh
[root@linux-node1 ~]# ssh-keygen -q -N ""

Enter file in which to save the key (/root/.ssh/id_rsa):
  • 创建keypair
[root@linux-node1 ~]# openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey
+-------------+-------------------------------------------------+
| Field | Value |
+-------------+-------------------------------------------------+
| fingerprint | :::bc:5e:dd:dc:::c7::9f:6a:::cd |
| name | mykey |
| user_id | 291f02337e514343a09a92932a86fd22 |
+-------------+-------------------------------------------------+
  • 验证keypair是否创建成功
[root@linux-node1 ~]# openstack keypair list
+-------+-------------------------------------------------+
| Name | Fingerprint |
+-------+-------------------------------------------------+
| mykey | :::bc:5e:dd:dc:::c7::9f:6a:::cd |
+-------+-------------------------------------------------+
  • 添加安全组规则并运行SSH接入
[root@linux-node1 ~]# openstack security group rule create --proto icmp default
+-------------------+--------------------------------------+
| Field | Value |
+-------------------+--------------------------------------+
| created_at | --12T08::51Z |
| description | |
| direction | ingress |
| ether_type | IPv4 |
| id | 245c084a-c503-4f23-a875-7a33c1eb442d |
| name | None |
| port_range_max | None |
| port_range_min | None |
| project_id | 1d5b969df6da43e69e4a956297404f5c |
| protocol | icmp |
| remote_group_id | None |
| remote_ip_prefix | 0.0.0.0/ |
| revision_number | |
| security_group_id | e46d2903-e800--a788-1923523ba4de |
| updated_at | --12T08::51Z |
+-------------------+--------------------------------------+
[root@linux-node1 ~]# openstack security group rule create --proto tcp --dst-port default
+-------------------+--------------------------------------+
| Field | Value |
+-------------------+--------------------------------------+
| created_at | --12T08::32Z |
| description | |
| direction | ingress |
| ether_type | IPv4 |
| id | 38f48887-e107---787a68191748 |
| name | None |
| port_range_max | |
| port_range_min | |
| project_id | 1d5b969df6da43e69e4a956297404f5c |
| protocol | tcp |
| remote_group_id | None |
| remote_ip_prefix | 0.0.0.0/ |
| revision_number | |
| security_group_id | e46d2903-e800--a788-1923523ba4de |
| updated_at | --12T08::32Z |
+-------------------+--------------------------------------+
  • 创建实例,使用openstack network list中的ID创建实例
[root@linux-node1 ~]# openstack network list
+--------------------------------------+----------+--------------------------------------+
| ID | Name | Subnets |
+--------------------------------------+----------+--------------------------------------+
| 59cd11d3-3d7b-4da3-8cbf-a5fece6be63b | provider | 50340b32-3f7f-4e8f-be72-673b9f701e4d |
+--------------------------------------+----------+--------------------------------------+openstack server create --flavor m1.nano --image cirros \
--nic net-id=59cd11d3-3d7b-4da3-8cbf-a5fece6be63b --security-group default \
--key-name mykey provider-instance
+-----------------------------+-----------------------------------------------+
| Field | Value |
+-----------------------------+-----------------------------------------------+
| OS-DCF:diskConfig | MANUAL |
| OS-EXT-AZ:availability_zone | |
| OS-EXT-STS:power_state | NOSTATE |
| OS-EXT-STS:task_state | scheduling |
| OS-EXT-STS:vm_state | building |
| OS-SRV-USG:launched_at | None |
| OS-SRV-USG:terminated_at | None |
| accessIPv4 | |
| accessIPv6 | |
| addresses | |
| adminPass | v7pgeGj7b5zC |
| config_drive | |
| created | --12T08::04Z |
| flavor | m1.nano () |
| hostId | |
| id | 46cc7aad---b067-919e736e07ac |
| image | cirros (24a1486b-d1b5--b2cc-3397fdf295cf) |
| key_name | mykey |
| name | provider-instance |
| progress | |
| project_id | 1d5b969df6da43e69e4a956297404f5c |
| properties | |
| security_groups | name='e46d2903-e800-4464-a788-1923523ba4de' |
| status | BUILD |
| updated | --12T08::04Z |
| user_id | 291f02337e514343a09a92932a86fd22 |
| volumes_attached | |
+-----------------------------+-----------------------------------------------+
  • 查看是否创建成功
[root@linux-node1 ~]# openstack server list
+--------------------------------------+-------------------+--------+-------------------------+--------+---------+
| ID | Name | Status | Networks | Image | Flavor |
+--------------------------------------+-------------------+--------+-------------------------+--------+---------+
|46cc7aad-6353-4399-b067-919e736e07ac | provider-instance | ACTIVE | provider=192.168.56.105 | cirros | m1.nano |
+--------------------------------------+-------------------+--------+-------------------------+--------+---------+
  • 查看console端口
[root@linux-node1 ~]# openstack console url show provider-instance
+-------+------------------------------------------------------------------------------------+
| Field | Value |
+-------+------------------------------------------------------------------------------------+
| type | novnc |
| url | http://192.168.56.11:6080/vnc_auto.html?token=e000ab58-4080-4adf-b588-59b6b86bcfa8 |
+-------+------------------------------------------------------------------------------------+