搭建 OpenStack(Q 版)Cinder 组件

简介

  • 基于 Ubuntu/CentOS 系统,搭建 OpenStack(Q 版)Cinder 组件

在 Controller 节点

数据库

  • 进入数据库
1
$ mysql -u root -p
  • 创建数据库
1
2
3
MariaDB [(none)]> CREATE DATABASE nova_api;
MariaDB [(none)]> CREATE DATABASE nova;
MariaDB [(none)]> CREATE DATABASE nova_cell0;
  • 赋予数据库权限
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# <NOVA_DBPASS>为自定义密码
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'localhost' \
  IDENTIFIED BY 'NOVA_DBPASS';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'%' \
  IDENTIFIED BY 'NOVA_DBPASS';

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

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'localhost' \
  IDENTIFIED BY 'NOVA_DBPASS';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'%' \
  IDENTIFIED BY 'NOVA_DBPASS';
  • 退出数据库
1
MariaDB [(none)]> exit

安装 Nova 组件

CentOS/Ubuntu 系统

  • 重新加载 admin 用户的管理凭据
1
$ source /openstack/admin-openrc
  • 创建 nova 用户
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
$ openstack user create --domain default --password-prompt nova

User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | 8a7dbf5279404537b1c7b86c033620fe |
| name                | nova                             |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
  • 为项目 service 与用户 nova 添加角色 admin
1
$ openstack role add --project service --user nova admin
  • 创建 compute 服务实体
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
$ openstack service create --name nova \
  --description "OpenStack Compute" compute

+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | OpenStack Compute                |
| enabled     | True                             |
| id          | 060d59eac51b4594815603d75a00aba2 |
| name        | nova                             |
| type        | compute                          |
+-------------+----------------------------------+
  • 创建 compute 服务的访问端点 endpoint
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
$ openstack endpoint create --region RegionOne \
  compute public http://controller:8774/v2.1

+--------------+-------------------------------------------+
| Field        | Value                                     |
+--------------+-------------------------------------------+
| enabled      | True                                      |
| id           | 3c1caa473bfe4390a11e7177894bcc7b          |
| interface    | public                                    |
| region       | RegionOne                                 |
| region_id    | RegionOne                                 |
| service_id   | 060d59eac51b4594815603d75a00aba2          |
| service_name | nova                                      |
| service_type | compute                                   |
| url          | http://controller:8774/v2.1               |
+--------------+-------------------------------------------+

$ openstack endpoint create --region RegionOne \
  compute internal http://controller:8774/v2.1

+--------------+-------------------------------------------+
| Field        | Value                                     |
+--------------+-------------------------------------------+
| enabled      | True                                      |
| id           | e3c918de680746a586eac1f2d9bc10ab          |
| interface    | internal                                  |
| region       | RegionOne                                 |
| region_id    | RegionOne                                 |
| service_id   | 060d59eac51b4594815603d75a00aba2          |
| service_name | nova                                      |
| service_type | compute                                   |
| url          | http://controller:8774/v2.1               |
+--------------+-------------------------------------------+

$ openstack endpoint create --region RegionOne \
  compute admin http://controller:8774/v2.1

+--------------+-------------------------------------------+
| Field        | Value                                     |
+--------------+-------------------------------------------+
| enabled      | True                                      |
| id           | 38f7af91666a47cfb97b4dc790b94424          |
| interface    | admin                                     |
| region       | RegionOne                                 |
| region_id    | RegionOne                                 |
| service_id   | 060d59eac51b4594815603d75a00aba2          |
| service_name | nova                                      |
| service_type | compute                                   |
| url          | http://controller:8774/v2.1               |
+--------------+-------------------------------------------+
  • 创建 placement 用户
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
$ openstack user create --domain default --password-prompt placement

User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | fa742015a6494a949f67629884fc7ec8 |
| name                | placement                        |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+
  • 为项目 service 与用户 placement 添加角色 admin
1
$ openstack role add --project service --user placement admin
  • 创建 placement 服务实体
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ openstack service create --name placement --description "Placement API" placement
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | Placement API                    |
| enabled     | True                             |
| id          | 2d1a27022e6e4185b86adac4444c495f |
| name        | placement                        |
| type        | placement                        |
+-------------+----------------------------------+
  • 创建 placement 服务的访问端点 endpoint
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
$ openstack endpoint create --region RegionOne placement public http://controller:8778
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 2b1b2637908b4137a9c2e0470487cbc0 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 2d1a27022e6e4185b86adac4444c495f |
| service_name | placement                        |
| service_type | placement                        |
| url          | http://controller:8778           |
+--------------+----------------------------------+

$ openstack endpoint create --region RegionOne placement internal http://controller:8778
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 02bcda9a150a4bd7993ff4879df971ab |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 2d1a27022e6e4185b86adac4444c495f |
| service_name | placement                        |
| service_type | placement                        |
| url          | http://controller:8778           |
+--------------+----------------------------------+

$ openstack endpoint create --region RegionOne placement admin http://controller:8778
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 3d71177b9e0f406f98cbff198d74b182 |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | 2d1a27022e6e4185b86adac4444c495f |
| service_name | placement                        |
| service_type | placement                        |
| url          | http://controller:8778           |
+--------------+----------------------------------+

Ubuntu 系统

  • 安装软件包
1
2
$ apt install nova-api nova-conductor nova-consoleauth \
  nova-novncproxy nova-scheduler nova-placement-api

CentOS 系统

  • 安装软件包
1
2
3
$ yum install openstack-nova-api openstack-nova-conductor \
  openstack-nova-console openstack-nova-novncproxy \
  openstack-nova-scheduler openstack-nova-placement-api

CentOS/Ubuntu 系统

  • 配置 Nova 服务
1
$ vim /etc/nova/nova.conf
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
[DEFAULT]
enabled_apis = osapi_compute,metadata
# 配置 RabbitMQ 消息队列访问,<RABBIT_PASS>为 RabbitMQ 的密码
transport_url = rabbit://openstack:RABBIT_PASS@controller
# Controller 节点的 IP 地址
my_ip = <IP 地址>
# 启用对 Nerutron(网络)服务的支持
use_neutron = True
firewall_driver = nova.virt.firewall.NoopFirewallDriver

[api_database]
## <NOVA_DBPASS>为 Nova-api 数据库的密码
connection = mysql+pymysql://nova:NOVA_DBPASS@controller/nova_api

[database]
## <NOVA_DBPASS>为 Nova 数据库的密码
connection = mysql+pymysql://nova:NOVA_DBPASS@controller/nova

[api]
# 配置身份验证策略
auth_strategy = keystone

[keystone_authtoken]
# <NOVA_DBPASS>为 Nova 用户的密码
auth_url = http://controller:5000/v3
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = nova
password = NOVA_PASS

[vnc]
enabled = true
server_listen = $my_ip
server_proxyclient_address = $my_ip

[glance]
api_servers = http://controller:9292

[oslo_concurrency]
lock_path = /var/lib/nova/tmp

[placement]
# <PLACEMENT_PASS>为 Placement 用户的密码
os_region_name = RegionOne
project_domain_name = Default
project_name = service
auth_type = password
user_domain_name = Default
auth_url = http://controller:5000/v3
username = placement
password = PLACEMENT_PASS
  • 只有 CentOS 才进行这一步的配置
  • 由于 packaging bug,所以必须配置 /etc/httpd/conf.d/00-nova-placement-api.conf 启用 Placement API
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
> $ vim /etc/httpd/conf.d/00-nova-placement-api.conf
> ```
>
> ```xml
> <Directory /usr/bin>
>    <IfVersion >= 2.4>
>       Require all granted
>    </IfVersion>
>    <IfVersion < 2.4>
>       Order allow,deny
>       Allow from all
>    </IfVersion>
> </Directory>
> ```
>
> - 重启 httpd 服务
>
> ```bash
> $ systemctl restart httpd
> ```

- 同步数据库

```bash
$ su -s /bin/sh -c "nova-manage api_db sync" nova
  • 在数据库中注册 cell0
1
$ su -s /bin/sh -c "nova-manage cell_v2 map_cell0" nova
  • 创建 cell1
1
2
$ su -s /bin/sh -c "nova-manage cell_v2 create_cell --name=cell1 --verbose" nova
109e1d4b-536a-40d0-83c6-5f121b82b650
  • 同步 nova 数据库
1
$ su -s /bin/sh -c "nova-manage db sync" nova
  • 验证 nova cell0cell1 是否已正确注册
1
2
3
4
5
6
7
$ nova-manage cell_v2 list_cells
+-------+--------------------------------------+
| Name  | UUID                                 |
+-------+--------------------------------------+
| cell1 | 109e1d4b-536a-40d0-83c6-5f121b82b650 |
| cell0 | 00000000-0000-0000-0000-000000000000 |
+-------+--------------------------------------+

Ubuntu 系统

  • 重启 Nova 服务
1
2
3
4
5
$ service nova-api restart
$ service nova-consoleauth restart
$ service nova-scheduler restart
$ service nova-conductor restart
$ service nova-novncproxy restart

CentOS 系统

  • 重启 Nova 服务并设置开机自启
1
2
3
4
5
6
$ 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

在 Compute 节点

安装 Nova 组件

Ubuntu 系统

  • 安装软件包
1
$ apt install nova-compute

CentOS 系统

  • 安装软件包
1
$ yum install openstack-nova-compute

CentOS/Ubuntu 系统

  • 配置 Nova 服务
1
$ vim /etc/nova/nova.conf
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
[DEFAULT]
enabled_apis = osapi_compute,metadata
# <RABBIT_PASS>为 RabbitMQ 的密码
transport_url = rabbit://openstack:RABBIT_PASS@controller
# Compute 节点的 IP 地址
my_ip = MANAGEMENT_INTERFACE_IP_ADDRESS
# 启用对 Nerutron(网络)服务的支持
use_neutron = True
firewall_driver = nova.virt.firewall.NoopFirewallDriver

[api]
# 配置身份验证策略
auth_strategy = keystone

[keystone_authtoken]
# <NOVA_DBPASS>为 Nova 用户的密码
auth_url = http://controller:5000/v3
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = nova
password = NOVA_PASS

[vnc]
enabled = True
server_listen = 0.0.0.0
server_proxyclient_address = $my_ip
# 若控制台无法连接,请将<controller>换为<IP 地址>
novncproxy_base_url = http://controller:6080/vnc_auto.html

[glance]
api_servers = http://controller:9292

[oslo_concurrency]
lock_path = /var/lib/nova/tmp

[placement]
# <PLACEMENT_PASS>为 placement 用户的密码
os_region_name = RegionOne
project_domain_name = Default
project_name = service
auth_type = password
user_domain_name = Default
auth_url = http://controller:5000/v3
username = placement
password = PLACEMENT_PASS

Ubuntu 系统

  • 查看系统是否支持虚拟化
1
2
# 判断虚拟机是否支持硬件加速
$ egrep -c '(vmx|svm)' /proc/cpuinfo
  • 若输出为或<0>, 请修改配置
1
$ vim /etc/nova/nova-compute.conf
1
2
[libvirt]
virt_type = qemu
  • 重启 Nova 服务
1
$ service nova-compute restart

CentOS 系统

  • 查看系统是否支持虚拟化
1
2
# 判断虚拟机是否支持硬件加速
$ egrep -c '(vmx|svm)' /proc/cpuinfo
  • 若输出为或<0>, 请修改配置
1
$ vim /etc/nova/nova.conf
1
2
[libvirt]
virt_type = qemu
  • 启动 Nova 服务并设置开机自启
1
2
$ systemctl enable libvirtd.service openstack-nova-compute.service
$ systemctl start libvirtd.service openstack-nova-compute.service

在 Controller 节点

将计算节点添加到 cell 数据库

CentOS/Ubuntu 系统

  • 重新加载 admin 用户的管理凭据
1
$ source /openstack/admin-openrc
  • 列出 Nova 服务的组件
1
2
3
4
5
6
$ openstack compute service list --service nova-compute
+----+-------+--------------+------+-------+---------+----------------------------+
| ID | Host  | Binary       | Zone | State | Status  | Updated At                 |
+----+-------+--------------+------+-------+---------+----------------------------+
| 1  | node1 | nova-compute | nova | up    | enabled | 2017-04-14T15:30:44.000000 |
+----+-------+--------------+------+-------+---------+----------------------------+
  • 发现 compute 主机
1
2
3
4
5
6
7
8
$ 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': ad5a5985-a719-4567-98d8-8d148aaae4bc
Found 1 computes in cell: ad5a5985-a719-4567-98d8-8d148aaae4bc
Checking host mapping for compute host 'compute': fe58ddc1-1d65-4f87-9456-bc040dc106b3
Creating host mapping for compute host 'compute': fe58ddc1-1d65-4f87-9456-bc040dc106b3

When you add new compute nodes, you must run nova-manage cell_v2 discover_hosts on the controller node to register those new compute nodes. Alternatively, you can set an appropriate interval in /etc/nova/nova.conf:

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

1
2
[scheduler] 
discover_hosts_in_cells_interval  =  300

参考链接