这个部分将描述如何在控制节点上安装和配置 Compute 服务,即 nova。

一、前提条件

在你安装和配置计算服务前,你必须创建数据库,服务凭证和API端点。

1.完成下面的步骤以创建数据库:

[root@Controller-Node ~]# mysql -uroot -p123456
MariaDB [(none)]> CREATE DATABASE nova;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'localhost' IDENTIFIED BY 'nova';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' IDENTIFIED BY 'nova';

MariaDB [(none)]> CREATE DATABASE nova_api;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'localhost' IDENTIFIED BY 'nova';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'%' IDENTIFIED BY 'nova';

MariaDB [(none)]> CREATE DATABASE nova_cell0;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'localhost' IDENTIFIED BY 'nova';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'%' IDENTIFIED BY 'nova';
MariaDB [(none)]> exit

2.获得 admin 凭证来获取只有管理员能执行命令的访问权限

[root@Controller-Node ~]# source admin-openrc.sh

3.要创建服务证书,完成这些步骤:

1.> 创建 nova 用户,设置密码为nova:

$openstack user create --domain default --password-prompt nova

执行如下:
[root@Controller-Node ~]# openstack user create --domain default --password-prompt nova
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | c7fe14104af14064a862d45a8331837b |
| name                | nova                             |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
[root@Controller-Node ~]#

2.>添加admin 角色到 nova 用户:

[root@Controller-Node ~]# openstack role add --project service --user nova admin

3.>创建 nova 服务实体:

openstack service create --name nova \
  --description "OpenStack Compute" compute
  
执行如下:
[root@Controller-Node ~]# openstack service create --name nova \
>   --description "OpenStack Compute" compute
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Compute                |
| enabled     | True                             |
| id          | deec4fb34eb64f8f968d304a0bb85bd4 |
| name        | nova                             |
| type        | compute                          |
+-------------+----------------------------------+
[root@Controller-Node ~]#

4.>创建计算服务API端点:

$ openstack endpoint create --region RegionOne \
  compute public http://10.20.9.13:8774/v2/%\(tenant_id\)s
 
$ openstack endpoint create --region RegionOne \
  compute internal http://10.20.9.13:8774/v2/%\(tenant_id\)s

$ openstack endpoint create --region RegionOne \
  compute admin http://10.20.9.13:8774/v2/%\(tenant_id\)s

执行如下:

[root@Controller-Node ~]# openstack endpoint create --region RegionOne \
>   compute public http://10.20.9.13:8774/v2/%\(tenant_id\)s
+--------------+-----------------------------------------+
| Field        | Value                                   |
+--------------+-----------------------------------------+
| enabled      | True                                    |
| id           | 1ba627fcb3d145569fbb83c32c9c1e16        |
| interface    | public                                  |
| region       | RegionOne                               |
| region_id    | RegionOne                               |
| service_id   | deec4fb34eb64f8f968d304a0bb85bd4        |
| service_name | nova                                    |
| service_type | compute                                 |
| url          | http://10.20.9.13:8774/v2/%(tenant_id)s |
+--------------+-----------------------------------------+
[root@Controller-Node ~]# openstack endpoint create --region RegionOne \
>   compute internal http://10.20.9.13:8774/v2/%\(tenant_id\)s
+--------------+-----------------------------------------+
| Field        | Value                                   |
+--------------+-----------------------------------------+
| enabled      | True                                    |
| id           | efd5e04872954088b09f9474da5c46d5        |
| interface    | internal                                |
| region       | RegionOne                               |
| region_id    | RegionOne                               |
| service_id   | deec4fb34eb64f8f968d304a0bb85bd4        |
| service_name | nova                                    |
| service_type | compute                                 |
| url          | http://10.20.9.13:8774/v2/%(tenant_id)s |
+--------------+-----------------------------------------+
[root@Controller-Node ~]# openstack endpoint create --region RegionOne \
>   compute admin http://10.20.9.13:8774/v2/%\(tenant_id\)s
+--------------+-----------------------------------------+
| Field        | Value                                   |
+--------------+-----------------------------------------+
| enabled      | True                                    |
| id           | 0f21127572b94416bc6374edf6131c4b        |
| interface    | admin                                   |
| region       | RegionOne                               |
| region_id    | RegionOne                               |
| service_id   | deec4fb34eb64f8f968d304a0bb85bd4        |
| service_name | nova                                    |
| service_type | compute                                 |
| url          | http://10.20.9.13:8774/v2/%(tenant_id)s |
+--------------+-----------------------------------------+
[root@Controller-Node ~]#

5.新建另一个用户,密码设为nova

[root@Controller-Node ~]# openstack user create --domain default --password-prompt placement
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | ab033f42e4064f898886447d07891d22 |
| name                | placement                        |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+

加入管理员组

[root@Controller-Node ~]# openstack role add --project service --user placement admin

6.在服务目录中创建Placement API条目

[root@Controller-Node ~]# openstack service create --name placement --description "Placement API" placement
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | Placement API                    |
| enabled     | True                             |
| id          | cccfe79b58c346928b1c56c38fb3d4b3 |
| name        | placement                        |
| type        | placement                        |
+-------------+----------------------------------+
[root@Controller-Node ~]#

7.创建Placement API服务端点:

[root@Controller-Node ~]# openstack endpoint create --region RegionOne placement public http://10.20.9.13:8778
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | d80c7e76ff8f4a69a36c0f9cd891f734 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | cccfe79b58c346928b1c56c38fb3d4b3 |
| service_name | placement                        |
| service_type | placement                        |
| url          | http://10.20.9.13:8778           |
+--------------+----------------------------------+
[root@Controller-Node ~]# openstack endpoint create --region RegionOne placement internal http://10.20.9.13:8778
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | baafdcbb3cb2460e89b3dd62fbeeb9fc |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | cccfe79b58c346928b1c56c38fb3d4b3 |
| service_name | placement                        |
| service_type | placement                        |
| url          | http://10.20.9.13:8778           |
+--------------+----------------------------------+
[root@Controller-Node ~]# openstack endpoint create --region RegionOne placement admin http://10.20.9.13:8778
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 3c621088b21247679ce071bab4296dd1 |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | cccfe79b58c346928b1c56c38fb3d4b3 |
| service_name | placement                        |
| service_type | placement                        |
| url          | http://10.20.9.13:8778           |
+--------------+----------------------------------+
[root@Controller-Node ~]#

查看catalog列表

[root@Controller-Node ~]# openstack catalog list
+-----------+-----------+------------------------------------------------------------------------+
| Name      | Type      | Endpoints                                                              |
+-----------+-----------+------------------------------------------------------------------------+
| nova      | compute   | RegionOne                                                              |
|           |           |   internal: http://10.20.9.13:8774/v2/6effb77cf0ba48a7a65a2c2235bbb726 |
|           |           | RegionOne                                                              |
|           |           |   public: http://10.20.9.13:8774/v2/6effb77cf0ba48a7a65a2c2235bbb726   |
|           |           | RegionOne                                                              |
|           |           |   admin: http://10.20.9.13:8774/v2/6effb77cf0ba48a7a65a2c2235bbb726    |
|           |           |                                                                        |
| keystone  | identity  | RegionOne                                                              |
|           |           |   public: http://10.20.9.13:5000/v3/                                   |
|           |           | RegionOne                                                              |
|           |           |   admin: http://10.20.9.13:35357/v3/                                   |
|           |           | RegionOne                                                              |
|           |           |   internal: http://10.20.9.13:5000/v3/                                 |
|           |           |                                                                        |
| placement | placement | RegionOne                                                              |
|           |           |   public: http://10.20.9.13:8778                                       |
|           |           | RegionOne                                                              |
|           |           |   internal: http://10.20.9.13:8778                                     |
|           |           | RegionOne                                                              |
|           |           |   admin: http://10.20.9.13:8778                                        |
|           |           |                                                                        |
| glance    | image     | RegionOne                                                              |
|           |           |   admin: http://10.20.9.13:9292                                        |
|           |           | RegionOne                                                              |
|           |           |   public: http://10.20.9.13:9292                                       |
|           |           | RegionOne                                                              |
|           |           |   internal: http://10.20.9.13:9292                                     |
|           |           |                                                                        |
+-----------+-----------+------------------------------------------------------------------------+
[root@Controller-Node ~]#

二、安装并配置组件

1.安装软件包:

$ yum install openstack-nova-api openstack-nova-cert \
  openstack-nova-conductor openstack-nova-console \
  openstack-nova-novncproxy openstack-nova-scheduler \
  python-novaclient openstack-nova-placement-api

2.编辑/etc/nova/nova.conf文件并完成下面的操作: 

1.> 在 [DEFAULT] 选项中,开启计算和元数据API

[DEFAULT]

# ...

enabled_apis=osapi_compute,metadata

2.> 在 [DEFAULT] 选项中,配置消息队列连接。

[DEFAULT]

# ...
transport_url=rabbit://openstack:openstack@10.20.9.13

3.> 在[DEFAULT]选项中,配置my_ip

[DEFAULT]

# ...
my_ip=10.20.9.13

4.> 在 [DEFAULT] 选项中开启对网络服务的支持

[DEFAULT]

# ...
use_neutron=True
firewall_driver=nova.virt.firewall.NoopFirewallDriver

5.> 在 [api_database] 和 [database] 选项中,配置数据库连接

[api_database]

# ...
connection = mysql://nova:nova@10.20.9.13/nova_api

[database]

# ...
connection = mysql://nova:nova@10.20.9.13/nova

6.> 在 [api] 和 [keystone_authtoken] 选项中配置如下

[api]

# ...
auth_strategy=keystone

[keystone_authtoken]

# ...

auth_uri=http://10.20.9.13:5000
auth_url=http://10.20.9.13:35357
memcached_servers=10.20.9.13:11211
auth_type=password
project_domain_name=default
user_domain_name=default
project_name=service
username=nova
password=nova

7.> 在 [vnc] 选项中,配置VNC代理

[vnc]

# ...

enabled=true
vncserver_listen=$my_ip
vncserver_proxyclient_address=$my_ip

8.> 在 [glance] 选项中,配置镜像服务API的位置。

[glance]

# ...

api_servers=http://10.20.9.13:9292

9.> 在 [oslo_concurrency] 选项中,配置锁定路径

[oslo_concurrency]

# ...

lock_path=/var/lib/nova/tmp

10.> 在 [placement] 选项中配置

[placement]

# ...

os_region_name=RegionOne
project_domain_name=Default 
project_name=service
auth_type=password
user_domain_name=Default
auth_url=http://10.20.9.13:35357/v3
username=placement
password=nova

3.设置apache,在文件中追加如下内容,并重新启动服务

vim  /etc/httpd/conf.d/00-nova-placement-api.conf

<Directory /usr/bin>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
<IfVersion < 2.4>
Order allow,deny
Allow from all
</IfVersion>
</Directory>
[root@Controller-Node ~]# systemctl restart httpd

4.填充nova-api数据库:

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

5.注册cell0数据库:

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

6.创建cell1单元格:

[root@Controller-Node ~]# su -s /bin/sh -c "nova-manage cell_v2 create_cell --name=cell1 --verbose" nova
c57ab09d-7da7-4abb-af21-448b62548b43
[root@Controller-Node ~]#

7.填充nova数据库:

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

8.验证nova cell0和cell1是否正确注册:

[root@Controller-Node ~]# nova-manage cell_v2 list_cells
+-------+--------------------------------------+
|  Name |                 UUID                 |
+-------+--------------------------------------+
| cell0 | 00000000-0000-0000-0000-000000000000 |
| cell1 | c57ab09d-7da7-4abb-af21-448b62548b43 |
+-------+--------------------------------------+

9.完成安装,开启计算服务并设置开机启动;

$systemctl enable openstack-nova-api.service \
  openstack-nova-consoleauth.service \
  openstack-nova-scheduler.service \
  openstack-nova-conductor.service \
  openstack-nova-novncproxy.service

$systemctl start openstack-nova-api.service \
  openstack-nova-consoleauth.service \
  openstack-nova-scheduler.service \
  openstack-nova-conductor.service \
  openstack-nova-novncproxy.service

$systemctl status openstack-nova-api.service \
  openstack-nova-consoleauth.service \
  openstack-nova-scheduler.service \
  openstack-nova-conductor.service \
  openstack-nova-novncproxy.service

10.获取admin权限,并验证每个服务组件都是否成功运行

[root@Controller-Node ~]# source admin-openrc.sh 
[root@Controller-Node ~]# 
[root@Controller-Node ~]# openstack host list
+-----------------+-------------+----------+
| Host Name       | Service     | Zone     |
+-----------------+-------------+----------+
| Controller-Node | consoleauth | internal |
| Controller-Node | conductor   | internal |
| Controller-Node | scheduler   | internal |
+-----------------+-------------+----------+
[root@Controller-Node ~]# nova service-list
+----+------------------+-----------------+----------+---------+-------+----------------------------+-----------------+
| Id | Binary           | Host            | Zone     | Status  | State | Updated_at                 | Disabled Reason |
+----+------------------+-----------------+----------+---------+-------+----------------------------+-----------------+
| 1  | nova-consoleauth | Controller-Node | internal | enabled | up    | 2018-10-10T09:06:01.000000 | -               |
| 2  | nova-conductor   | Controller-Node | internal | enabled | up    | 2018-10-10T09:06:02.000000 | -               |
| 3  | nova-scheduler   | Controller-Node | internal | enabled | up    | 2018-10-10T09:06:01.000000 | -               |
+----+------------------+-----------------+----------+---------+-------+----------------------------+-----------------+
[root@Controller-Node ~]# openstack endpoint list
+----------------------------------+-----------+--------------+--------------+---------+-----------+-----------------------------------------+
| ID                               | Region    | Service Name | Service Type | Enabled | Interface | URL                                     |
+----------------------------------+-----------+--------------+--------------+---------+-----------+-----------------------------------------+
| 168ce73846e84b51aceb1d9fc043786a | RegionOne | nova         | compute      | True    | internal  | http://10.20.9.13:8774/v2/%(tenant_id)s |
| 19df26f63e994c8ba0c81fa263dc60cd | RegionOne | keystone     | identity     | True    | public    | http://10.20.9.13:5000/v3/              |
| 3ca232fd709f4e95b5a74ea074c5d341 | RegionOne | glance       | image        | True    | admin     | http://10.20.9.13:9292                  |
| 47a41ccb37d94396bf1878b0b4bf4910 | RegionOne | glance       | image        | True    | public    | http://10.20.9.13:9292                  |
| 5c1683647fe64bd19ddeeca2f44b4d29 | RegionOne | keystone     | identity     | True    | admin     | http://10.20.9.13:35357/v3/             |
| 67a2fddef3b64789a51d4f74183f3715 | RegionOne | nova         | compute      | True    | public    | http://10.20.9.13:8774/v2/%(tenant_id)s |
| 7d6ca6665b1b46e195aef4b0e264daf6 | RegionOne | keystone     | identity     | True    | internal  | http://10.20.9.13:5000/v3/              |
| c675270a56b545af97408788c63b89fd | RegionOne | glance       | image        | True    | internal  | http://10.20.9.13:9292                  |
| d04b4f1de2ff4e79ad97b0a18bee46da | RegionOne | nova         | compute      | True    | admin     | http://10.20.9.13:8774/v2/%(tenant_id)s |
+----------------------------------+-----------+--------------+--------------+---------+-----------+-----------------------------------------+
[root@Controller-Node ~]#

 三、在计算节点安装配置nova服务(10.20.9.14主机)

1.安装nova-compute软件包

[root@Compute-Node ~]# yum install openstack-nova-compute

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

1.> 在[DEFAULT]选项中,开启计算和元数据API

[DEFAULT]

#...

enabled_apis=osapi_compute,metadata

2.> 在[DEFAULT]选项中,配置消息队列权限

[DEFAULT]

#...

transport_url=rabbit://openstack:openstack@10.20.9.13

3.> 在[DEFAULT]选项中,配置my_ip参数,这个是本机IP地址

[DEFAULT]

#...

my_ip=10.20.9.14

4.> 在 [DEFAULT] 选项中,开启网络服务支持

[DEFAULT]

#...

use_neutron=True
firewall_driver=nova.virt.firewall.NoopFirewallDriver

5.> 在 [api] 和 [keystone_authtoken] 选项中,配置认证服务权限

[api]

#...

auth_strategy=keystone

[keystone_authtoken]

#...

auth_uri=http://10.20.9.13:5000
auth_url=http://10.20.9.13:35357
memcached_servers=10.20.9.13:11211
auth_type=password
project_domain_name=default
user_domain_name=default
project_name=service
username=nova
password=nova

6.> 在 [vnc] 选项中,开启并配置远程控制台权限

[vnc]

#...

enabled=True
vncserver_listen=0.0.0.0
vncserver_proxyclient_address=$my_ip
novncproxy_base_url=http://10.20.9.13:6080/vnc_auto.html

7.> 在 [glance] 选项中,配置镜像服务API地址

[glance]

#...

api_servers=http://10.20.9.13:9292

8.> 在  [oslo_concurrency] 选项,配置锁定路径

[oslo_concurrency]

#...
lock_path=/var/lib/nova/tmp

9.> 在 [placement] 段添加如下参数.

[placement]

#...

os_region_name=RegionOne
project_domain_name=Default
project_name=service
auth_type=password
user_domain_name=Default
auth_url=http://10.20.9.13:35357/v3
username=placement
password=nova

3. 检查是否需要硬件加速

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

如果为0则需要修改 #vi /etc/nova/nova.conf文件,[libvirt]段添加如下内容.

[libvirt]

# ...

virt_type=qemu

4.启动服务,并查看服务状态

# systemctl enable libvirtd.service openstack-nova-compute.service
# systemctl start libvirtd.service openstack-nova-compute.service
# systemctl status libvirtd.service openstack-nova-compute.service

 三、验证操作,在主控节点(10.20.9.13)上面操作.

1.获取admin权限

[root@Controller-Node ~]# source admin-openrc.sh

2.将计算节点添加到单元数据库,在控制节点上进行操作.

[root@Controller-Node ~]# 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 compute nodes from cell 'cell1': c57ab09d-7da7-4abb-af21-448b62548b43
Found 1 computes in cell: c57ab09d-7da7-4abb-af21-448b62548b43
Checking host mapping for compute host 'Compute-Node': 911f9117-ec3f-43fd-930e-b8571f04400f
Creating host mapping for compute host 'Compute-Node': 911f9117-ec3f-43fd-930e-b8571f04400f
[root@Controller-Node ~]#

3.查看 compute 节点

[root@Controller-Node ~]# openstack compute service list
+----+------------------+-----------------+----------+---------+-------+----------------------------+
| ID | Binary           | Host            | Zone     | Status  | State | Updated At                 |
+----+------------------+-----------------+----------+---------+-------+----------------------------+
|  1 | nova-consoleauth | Controller-Node | internal | enabled | up    | 2018-10-11T02:59:37.000000 |
|  2 | nova-conductor   | Controller-Node | internal | enabled | up    | 2018-10-11T02:59:35.000000 |
|  3 | nova-scheduler   | Controller-Node | internal | enabled | up    | 2018-10-11T02:59:31.000000 |
|  6 | nova-compute     | Compute-Node    | nova     | enabled | up    | 2018-10-11T02:59:38.000000 |
+----+------------------+-----------------+----------+---------+-------+----------------------------+
[root@Controller-Node ~]#

4.查看catalog

[root@Controller-Node ~]# openstack catalog list
+-----------+-----------+------------------------------------------------------------------------+
| Name      | Type      | Endpoints                                                              |
+-----------+-----------+------------------------------------------------------------------------+
|       |   |                                                                        |
| nova      | compute   | RegionOne                                                              |
|           |           |   internal: http://10.20.9.13:8774/v2/6effb77cf0ba48a7a65a2c2235bbb726 |
|           |           | RegionOne                                                              |
|           |           |   public: http://10.20.9.13:8774/v2/6effb77cf0ba48a7a65a2c2235bbb726   |
|           |           | RegionOne                                                              |
|           |           |   admin: http://10.20.9.13:8774/v2/6effb77cf0ba48a7a65a2c2235bbb726    |
|           |           |                                                                        |
| keystone  | identity  | RegionOne                                                              |
|           |           |   public: http://10.20.9.13:5000/v3/                                   |
|           |           | RegionOne                                                              |
|           |           |   admin: http://10.20.9.13:35357/v3/                                   |
|           |           | RegionOne                                                              |
|           |           |   internal: http://10.20.9.13:5000/v3/                                 |
|           |           |                                                                        |
| placement | placement | RegionOne                                                              |
|           |           |   admin: http://10.20.9.13:8778                                        |
|           |           | RegionOne                                                              |
|           |           |   internal: http://10.20.9.13:8778                                     |
|           |           | RegionOne                                                              |
|           |           |   public: http://10.20.9.13:8778                                       |
|           |           |                                                                        |
| glance    | image     | RegionOne                                                              |
|           |           |   admin: http://10.20.9.13:9292                                        |
|           |           | RegionOne                                                              |
|           |           |   public: http://10.20.9.13:9292                                       |
|           |           | RegionOne                                                              |
|           |           |   internal: http://10.20.9.13:9292                                     |
|           |           |                                                                        |
+-----------+-----------+------------------------------------------------------------------------+
[root@Controller-Node ~]#

5.列出Image服务中的图像以验证与Image服务的连接性:

[root@Controller-Node ~]# openstack image list
+--------------------------------------+--------+--------+
| ID                                   | Name   | Status |
+--------------------------------------+--------+--------+
| f7041b87-bd78-475c-a877-919543886dc0 | cirros | active |
+--------------------------------------+--------+--------+
[root@Controller-Node ~]#

6.检查单元格和放置API正在成功工作:

[root@Controller-Node ~]# nova-status upgrade check
+---------------------------+
| Upgrade Check Results     |
+---------------------------+
| Check: Cells v2           |
| Result: Success           |
| Details: None             |
+---------------------------+
| Check: Placement API      |
| Result: Success           |
| Details: None             |
+---------------------------+
| Check: Resource Providers |
| Result: Success           |
| Details: None             |
+---------------------------+
[root@Controller-Node ~]#

至此,主控和计算节点的nova服务都已经部署完成,两者的互通都没问题..