5 安装和配置Compute服务(Nova)

OpenStack Compute是基础设施即服务(IaaS)系统的主要组成部分,用于托管和管理云计算系统。OpenStack Compute与OpenStack Identity交互以进行身份验证,OpenStack Placement用于资源库存跟踪和选择,OpenStack Image服务用于磁盘和服务器映像,以及OpenStack Dashboard用于用户和管理界面。

本节操作会涉及控制节点和计算节点,请注意操作环境。

5.1 先决条件

本小节操作在控制节点上完成。

5.1.1 创建数据库并授权

[root@xgk-ctl ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 28
Server version: 10.5.16-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE nova_api;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> CREATE DATABASE nova;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> CREATE DATABASE nova_cell0;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'localhost' IDENTIFIED BY 'NOVA_DBPASS';
Query OK, 0 rows affected (0.002 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'%' IDENTIFIED BY 'NOVA_DBPASS';
Query OK, 0 rows affected (0.002 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'localhost' IDENTIFIED BY 'NOVA_DBPASS';
Query OK, 0 rows affected (0.002 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' IDENTIFIED BY 'NOVA_DBPASS';
Query OK, 0 rows affected (0.002 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'localhost' IDENTIFIED BY 'NOVA_DBPASS';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'%' IDENTIFIED BY 'NOVA_DBPASS';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> exit;
Bye

5.1.2 获得admin凭证

[root@xgk-ctl ~]# source /etc/keystone/admin-openrc

5.1.3 创建nova用户并设置密码

[root@xgk-ctl ~]# openstack user create --domain default --password-prompt nova
User Password:#设置nova用户密码,如NOVA_PASS
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | d39ec595453f4b72906a410b0bf0051b |
| name                | nova                             |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+

5.1.4 给nova用户添加admin角色

[root@xgk-ctl ~]# openstack role add --project service --user nova admin

5.1.5 创建 nova 服务实体

[root@xgk-ctl ~]# openstack service create --name nova --description "OpenStack Compute" compute
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Compute                |
| enabled     | True                             |
| id          | f2768bcaed69467383312201d0d737c5 |
| name        | nova                             |
| type        | compute                          |
+-------------+----------------------------------+

5.1.6 创建Nova API端点

1、创建public端点

[root@xgk-ctl ~]# openstack endpoint create --region RegionOne compute public http://xgk-ctl:8774/v2.1
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | be795af37e774101b255b72db20250fb |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | f2768bcaed69467383312201d0d737c5 |
| service_name | nova                             |
| service_type | compute                          |
| url          | http://xgk-ctl:8774/v2.1         |
+--------------+----------------------------------+

2、创建internal端点

[root@xgk-ctl ~]# openstack endpoint create --region RegionOne compute internal http://xgk-ctl:8774/v2.1
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | a2ba8848cd5a408a837580f2f4ee8d0c |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | f2768bcaed69467383312201d0d737c5 |
| service_name | nova                             |
| service_type | compute                          |
| url          | http://xgk-ctl:8774/v2.1         |
+--------------+----------------------------------+

3、创建admin端点

[root@xgk-ctl ~]# openstack endpoint create --region RegionOne compute admin http://xgk-ctl:8774/v2.1
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | f114d1be57354daaae2bcf140564f85b |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | f2768bcaed69467383312201d0d737c5 |
| service_name | nova                             |
| service_type | compute                          |
| url          | http://xgk-ctl:8774/v2.1         |
+--------------+----------------------------------+

5.2 在控制节点上安装和配置组件

5.2.1 安装软件包

[root@xgk-ctl ~]# dnf -y install openstack-nova-api openstack-nova-conductor openstack-nova-novncproxy openstack-nova-scheduler

5.2.2 配置/etc/nova/nova.conf文件

[root@xgk-ctl ~]# cp -a /etc/nova/nova.conf{,.bak}
[root@xgk-ctl ~]# grep -Ev '^$|#' /etc/nova/nova.conf.bak > /etc/nova/nova.conf
[root@xgk-ctl ~]# vim /etc/nova/nova.conf

#启用计算和元数据API,配置RabbitMQ消息队列条目,配置my_ip,并启用网络服务,禁用主机防火墙
[DEFAULT]
enabled_apis = osapi_compute,metadata
transport_url = rabbit://openstack:RABBIT_PASS@xgk-ctl:5672/
my_ip = 192.168.18.200
use_neutron = true
firewall_driver = nova.virt.firewall.NoopFirewallDriver

#配置identity服务访问
[api]
auth_strategy = keystone

#配置数据库条目
[api_database]
connection = mysql+pymysql://nova:NOVA_DBPASS@xgk-ctl/nova_api

……此处省略文件部分原有内容……

[database]
connection = mysql+pymysql://nova:NOVA_DBPASS@xgk-ctl/nova

……此处省略文件部分原有内容……
#配置镜像服务的API地址
[glance]
api_servers = http://xgk-ctl:9292

……此处省略文件部分原有内容……
[keystone_authtoken]
www_authenticate_uri = http://xgk-ctl:5000/
auth_url = http://xgk-ctl:5000/
memcached_servers = xgk-ctl:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = nova
password = NOVA_PASS

……此处省略文件部分原有内容……
[neutron]
auth_url = http://xgk-ctl:5000
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = neutron
password = NEUTRON_PASS
service_metadata_proxy = true
metadata_proxy_shared_secret = METADATA_SECRET

……此处省略文件部分原有内容……
#配置锁定路径
[oslo_concurrency]
lock_path = /var/lib/nova/tmp

……此处省略文件部分原有内容……
#配置Placement服务的条目
[placement]
region_name = RegionOne
project_domain_name = Default
project_name = service
auth_type = password
user_domain_name = Default
auth_url = http://xgk-ctl:5000/v3
username = placement
password = PLACEMENT_PASS

……此处省略文件部分原有内容……
#启用并配置远程控制台的条目
[vnc]
enabled = true
server_listen = $my_ip
server_proxyclient_address = $my_ip
……此处省略文件部分原有内容……

5.2.3 同步数据库

1、获得admin凭证

[root@xgk-ctl ~]# source /etc/keystone/admin-openrc 

2、同步nova-api数据库

[root@xgk-ctl ~]# su -s /bin/sh -c "nova-manage api_db sync" nova

3、注册cell0数据库

[root@xgk-ctl ~]# su -s /bin/sh -c "nova-manage cell_v2 map_cell0" nova

4、创建cell并命名为cell1

[root@xgk-ctl ~]# su -s /bin/sh -c "nova-manage cell_v2 create_cell --name=cell1 --verbose" nova 

5、同步nova数据库

[root@xgk-ctl ~]# su -s /bin/sh -c "nova-manage db sync" nova

6、验证cell0和cell1是否正确注册

[root@xgk-ctl ~]# su -s /bin/sh -c "nova-manage cell_v2 list_cells" nova
Modules with known eventlet monkey patching issues were imported prior to eventlet monkey patching: urllib3. This warning can usually be ignored if the caller is only importing and not executing nova code.
+-------+--------------------------------------+---------------------------------------+----------------------------------------------+----------+
|  名称 |                 UUID                 |             Transport URL             |                  数据库连接                  | Disabled |
+-------+--------------------------------------+---------------------------------------+----------------------------------------------+----------+
| cell0 | 00000000-0000-0000-0000-000000000000 |                 none:/                | mysql+pymysql://nova:****@xgk-ctl/nova_cell0 |  False   |
| cell1 | dbedc243-28af-4f35-a5ec-ff793e2a39c9 | rabbit://openstack:****@xgk-ctl:5672/ |    mysql+pymysql://nova:****@xgk-ctl/nova    |  False   |
+-------+--------------------------------------+---------------------------------------+----------------------------------------------+----------+

7、将计算节点添加到OpenStack集群

[root@xgk-ctl ~]# su -s /bin/sh -c "nova-manage cell_v2 discover_hosts --verbose" nova
……此处警告可以忽略……
Found 2 cell mappings.
Skipping cell0 since it does not contain hosts.
Getting computes from cell 'cell1': dbedc243-28af-4f35-a5ec-ff793e2a39c9
Checking host mapping for compute host 'xgk-cpt': e1da8ade-0f8c-45d5-9f4e-d293f7bc7a6a
Creating host mapping for compute host 'xgk-cpt': e1da8ade-0f8c-45d5-9f4e-d293f7bc7a6a
Found 1 unmapped computes in cell: dbedc243-28af-4f35-a5ec-ff793e2a39c9

5.2.4 启动服务,并设置为开机自启动

[root@xgk-ctl ~]# systemctl enable openstack-nova-api.service openstack-nova-scheduler.service openstack-nova-conductor.service openstack-nova-novncproxy.service

[root@xgk-ctl ~]# systemctl start openstack-nova-api.service openstack-nova-scheduler.service openstack-nova-conductor.service openstack-nova-novncproxy.service

5.3 在计算节点上安装和配置组件

本小节操作要求在计算节点上完成。

5.3.1 安装软件包

[root@xgk-cpt ~]# dnf -y install openstack-nova-compute

5.3.2 编辑/etc/nova/nova.conf文件

[root@xgk-cpt ~]# cp -a /etc/nova/nova.conf{,.bak}
[root@xgk-cpt ~]# grep -Ev '^$|#' /etc/nova/nova.conf.bak > /etc/nova/nova.conf
[root@xgk-cpt ~]# vim /etc/nova/nova.conf

[DEFAULT]
enabled_apis = osapi_compute,metadata        //仅启用计算和元数据API
transport_url = rabbit://openstack:RABBIT_PASS@xgk-ctl       //配置RabbitMQ消息队列访问
my_ip = 192.168.18.201        //本计算节点的管理接口IP地址
use_neutron = true            //启用对网络服务的支持
#默认情况下,计算节点使用内部防火墙服务。由于网络包含防火墙服务,因此必须通过nova.virt.firewall.NoopFirewallDriver防火墙驱动程序来禁用计算节点的防火墙服务。
firewall_driver = nova.virt.firewall.NoopFirewallDriver
compute_driver=libvirt.LibvirtDriver
instances_path = /var/lib/nova/instances/
lock_path = /var/lib/nova/tmp

[api]
auth_strategy = keystone    //配置Identity服务访问
……此处省略文件原有内容……

[glance]
api_servers = http://xgk-ctl:9292  //配置镜像服务API的位置
……此处省略文件原有内容……

#配置Identity服务访问
[keystone_authtoken]   
www_authenticate_uri = http://xgk-ctl:5000/
auth_url = http://xgk-ctl:5000/
memcached_servers = xgk-ctl:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = nova
password = NOVA_PASS

……此处省略文件原有内容……
[oslo_concurrency]
lock_path = /var/lib/nova/tmp   //配置锁定路径
……此处省略文件原有内容……

#配置placement API
[placement]
region_name = RegionOne
project_domain_name = Default
project_name = service
auth_type = password
user_domain_name = Default
auth_url = http://xgk-ctl:5000/v3
username = placement
password = PLACEMENT_PASS

……此处省略文件原有内容……
#启用和配置远程控制台访问
[vnc]
enabled = true
server_listen = 0.0.0.0
server_proxyclient_address = $my_ip
novncproxy_base_url = http://192.168.18.200:6080/vnc_auto.html  #此处的IP地址为控制节点的IP

……此处省略文件原有内容……

5.3.3 完成安装

1、确定计算节点是否支持虚拟机的硬件加速

[root@xgk-cpt ~]# egrep -c '(vmx|svm)' /proc/cpuinfo
0

此命令返回值若为非0,则表示计算节点支持硬件加速,通常不需要额外配置。

若此命令返回值为0,表示计算节点不支持硬件加速,则必须在/etc/nova/nova.conf配置文件中的【libvirt】节中,指定virt_type值为qemu而不是kvm,如下所示。

[root@xgk-cpt ~]# vim /etc/nova/nova.conf

……此处省略文件原有内容……
[libvirt]
virt_type = qemu

……此处省略文件原有内容……

2、启动libvirtd和openstack-nova-compute服务,并将其设置为开机自启动

[root@xgk-cpt ~]# systemctl enable libvirtd.service openstack-nova-compute.service
[root@xgk-cpt ~]# systemctl start libvirtd.service openstack-nova-compute.service

5.4 验证

1、确认数据库中有计算节点主机

[root@xgk-ctl ~]# openstack compute service list --service nova-compute
+--------------------------------------+--------------+-----------+------+---------+-------+----------------------------+
| ID                                   | Binary       | Host    | Zone | Status  | State | Updated At                 |
+--------------------------------------+--------------+-----------+------+---------+-------+----------------------------+
| 00f5a9e0-bfcf-42d8-8ee1-795ade8f5f0a | nova-compute | xgk-cpt | nova | enabled | up    | 2022-12-17T07:01:45.000000 |
+--------------------------------------+--------------+-----------+------+---------+-------+----------------------------+

2、列出服务组件,以验证每个进程是否已成功启动和注册

[root@xgk-ctl ~]# openstack compute service list
+--------------------------------------+----------------+-----------+----------+---------+-------+----------------------------+
| ID                                   | Binary         | Host    | Zone     | Status  | State | Updated At                 |
+--------------------------------------+----------------+-----------+----------+---------+-------+----------------------------+
| c4bafeae-cbeb-4671-852b-0033b9ff8a78 | nova-scheduler | xgk-ctl | internal | enabled | up    | 2022-12-17T03:11:25.000000 |
| ae34865a-a982-4e62-a62a-2ee81b887659 | nova-conductor | xgk-ctl | internal | enabled | up    | 2022-12-17T03:11:25.000000 |
| 00f5a9e0-bfcf-42d8-8ee1-795ade8f5f0a | nova-compute   | xgk-cpt | nova     | enabled | up    | 2022-12-17T03:11:22.000000 |
+--------------------------------------+----------------+-----------+----------+---------+-------+----------------------------+

3、列出标识服务中的API端点,以验证与标识服务的连接

[root@xgk-ctl ~]# openstack catalog list
+-----------+-----------+--------------------------------------+
| Name      | Type      | Endpoints                            |
+-----------+-----------+--------------------------------------+
| placement | placement | RegionOne                            |
|           |           |   public: http://xgk-ctl:8778        |
|           |           | RegionOne                            |
|           |           |   admin: http://xgk-ctl:8778         |
|           |           | RegionOne                            |
|           |           |   internal: http://xgk-ctl:8778      |
|           |           |                                      |
| glance    | image     | RegionOne                            |
|           |           |   admin: http://xgk-ctl:9292         |
|           |           | RegionOne                            |
|           |           |   internal: http://xgk-ctl:9292      |
|           |           | RegionOne                            |
|           |           |   public: http://xgk-ctl:9292        |
|           |           |                                      |
| keystone  | identity  | RegionOne                            |
|           |           |   public: http://xgk-ctl:5000/v3/    |
|           |           | RegionOne                            |
|           |           |   internal: http://xgk-ctl:5000/v3/  |
|           |           | RegionOne                            |
|           |           |   admin: http://xgk-ctl:5000/v3/     |
|           |           |                                      |
| nova      | compute   | RegionOne                            |
|           |           |   internal: http://xgk-ctl:8774/v2.1 |
|           |           | RegionOne                            |
|           |           |   public: http://xgk-ctl:8774/v2.1   |
|           |           | RegionOne                            |
|           |           |   admin: http://xgk-ctl:8774/v2.1    |
|           |           |                                      |
+-----------+-----------+--------------------------------------+

4、列出镜像服务中的镜像以验证连接

[root@xgk-ctl ~]# openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| 57ea2d66-8865-4900-b960-fb14b4c6a484 | cirros | active |
+--------------------------------------+--------+--------+

5、检查cells 是否正常运行,是否满足其他先决条件

[root@xgk-ctl ~]# nova-status upgrade check
Modules with known eventlet monkey patching issues were imported prior to eventlet monkey patching: urllib3. This warning can usually be ignored if the caller is only importing and not executing nova code.
JSON formatted policy_file support is deprecated since Victoria release. You need to use YAML format which will be default in future. You can use ``oslopolicy-convert-json-to-yaml`` tool to convert existing JSON-formatted policy file to YAML-formatted in backward compatible way: https://docs.openstack.org/oslo.policy/latest/cli/oslopolicy-convert-json-to-yaml.html.
JSON formatted policy_file support is deprecated since Victoria release. You need to use YAML format which will be default in future. You can use ``oslopolicy-convert-json-to-yaml`` tool to convert existing JSON-formatted policy file to YAML-formatted in backward compatible way: https://docs.openstack.org/oslo.policy/latest/cli/oslopolicy-convert-json-to-yaml.html.
+------------------------------------------------------------------+
| Upgrade Check Results                                            |
+------------------------------------------------------------------+
| Check: Cells v2                                                  |
| Result: Failure                                                  |
| Details: No host mappings found but there are compute nodes. Run |
|   command 'nova-manage cell_v2 simple_cell_setup' and then       |
|   retry.                                                         |
+------------------------------------------------------------------+
| Check: Placement API                                             |
| Result: Success                                                  |
| Details: None                                                    |
+------------------------------------------------------------------+
| Check: Cinder API                                                |
| Result: Success                                                  |
| Details: None                                                    |
+------------------------------------------------------------------+
| Check: Policy Scope-based Defaults                               |
| Result: Success                                                  |
| Details: None                                                    |
+------------------------------------------------------------------+
| Check: Policy File JSON to YAML Migration                        |
| Result: Success                                                  |
| Details: None                                                    |
+------------------------------------------------------------------+
| Check: Older than N-1 computes                                   |
| Result: Success                                                  |
| Details: None                                                    |
+------------------------------------------------------------------+
| Check: hw_machine_type unset                                     |
| Result: Success                                                  |
| Details: None                                                    |
+------------------------------------------------------------------+

 注:添加新计算节点时,必须在控制器节点上运行【nova manage cell_v2 discover_hosts】命令以注册这些新计算节点。或者,也可以在/etc/nova/nova.conf中设置适当的间隔

[scheduler]
discover_hosts_in_cells_interval = 300

下一篇:构建基于openEuler2209的OpenStack云平台(六)

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐