OpenStack——编排(Heat)服务介绍与安装

OpenStack Heat 是一个基于模板的编排服务,用于自动化部署和管理基础设施资源。它允许用户通过编写模板文件来描述所需的基础设施资源和配置,然后使用 Heat 引擎来解析和执行这些模板,自动创建、配置和管理云环境中的资源。

例如,假设我们有一个Web应用程序,它需要一个虚拟机作为Web服务器、一个存储卷用于存储数据、一个网络用于连接虚拟机和存储卷。我们可以使用Heat模板来描述这些资源和它们之间的关系。在模板中,我们可以指定虚拟机的镜像、网络的子网、存储卷的大小等属性,并定义资源之间的依赖关系,比如虚拟机需要在存储卷创建完成后才能启动。 一旦我们创建了这个模板,就可以使用Heat服务来部署和管理这个应用程序。Heat会根据模板中的描述,自动创建和配置虚拟机、存储卷和网络等资源。而当我们需要更新或删除这些资源时,只需要修改模板并重新执行Heat命令,它会根据模板中的变化来自动更新或删除相应的资源。

安装和配置(controller)

准备

官方文档

配置Heat服务组件之前,需要先创建数据库、服务证书和API endpoint。

(1)创建数据库

①在操作系统终端连接数据库

[root@controller ~]# mysql -uroot -p000000

②创建heat数据库

MariaDB [(none)]> CREATE DATABASE heat;

③Heat数据库访问权限设置

MariaDB [(none)]> GRANT ALL PRIVILEGES ON heat.* TO 'heat'@'%'  IDENTIFIED BY '000000';

④退出数据库

(2)加载admin user 的环境变量

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

(3)创建服务凭证

①创建Heat用户

[root@controller ~]# openstack user create --domain default --password 000000 heat
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | default                          |
| enabled             | True                             |
| id                  | c2774323d7e04a529d1fcdc18d6549f9 |
| name                | heat                             |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+

②admin为用户添加角色heat

[root@controller ~]# openstack role add --project service --user heat admin

③创建Heat和heat-cfn service entity

[root@controller ~]# openstack service create --name heat  --description "Orchestration" orchestration
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | Orchestration                    |
| enabled     | True                             |
| id          | 7ce739d29f3841ad9bed4d286f546bd7 |
| name        | heat                             |
| type        | orchestration                    |
+-------------+----------------------------------+
[root@controller ~]# openstack service create --name heat-cfn --description "Orchestration"  cloudformation
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | Orchestration                    |
| enabled     | True                             |
| id          | f1c9a2b146b94d75b19a13f1b806e4d8 |
| name        | heat-cfn                         |
| type        | cloudformation                   |
+-------------+----------------------------------+

(4)创建Heat编排服务组件的API endpoint

[root@controller ~]# openstack endpoint create --region RegionOne  orchestration public http://controller:8004/v1/%\(tenant_id\)s
+--------------+-----------------------------------------+
| Field        | Value                                   |
+--------------+-----------------------------------------+
| enabled      | True                                    |
| id           | 56d9afe212be479394529d2e5b33e9bc        |
| interface    | public                                  |
| region       | RegionOne                               |
| region_id    | RegionOne                               |
| service_id   | 7ce739d29f3841ad9bed4d286f546bd7        |
| service_name | heat                                    |
| service_type | orchestration                           |
| url          | http://controller:8004/v1/%(tenant_id)s |
+--------------+-----------------------------------------+

[root@controller ~]# openstack endpoint create --region RegionOne  orchestration internal http://controller:8004/v1/%\(tenant_id\)s
+--------------+-----------------------------------------+
| Field        | Value                                   |
+--------------+-----------------------------------------+
| enabled      | True                                    |
| id           | b77211d055ac468094a1834318a24341        |
| interface    | internal                                |
| region       | RegionOne                               |
| region_id    | RegionOne                               |
| service_id   | 7ce739d29f3841ad9bed4d286f546bd7        |
| service_name | heat                                    |
| service_type | orchestration                           |
| url          | http://controller:8004/v1/%(tenant_id)s |
+--------------+-----------------------------------------+

[root@controller ~]# openstack endpoint create --region RegionOne orchestration admin http://controller:8004/v1/%\(tenant_id\)s
+--------------+-----------------------------------------+
| Field        | Value                                   |
+--------------+-----------------------------------------+
| enabled      | True                                    |
| id           | 02f7ab4296a94dc1ac909cf7e83b91bc        |
| interface    | admin                                   |
| region       | RegionOne                               |
| region_id    | RegionOne                               |
| service_id   | 7ce739d29f3841ad9bed4d286f546bd7        |
| service_name | heat                                    |
| service_type | orchestration                           |
| url          | http://controller:8004/v1/%(tenant_id)s |
+--------------+-----------------------------------------+
 [root@controller ~]# openstack endpoint create --region RegionOne cloudformation public http://controller:8000/v1
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 26264981dd3a414aa18fd64e4ec2ba84 |
| interface    | public                           |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | f1c9a2b146b94d75b19a13f1b806e4d8 |
| service_name | heat-cfn                         |
| service_type | cloudformation                   |
| url          | http://controller:8000/v1        |
+--------------+----------------------------------+

[root@controller ~]# openstack endpoint create --region RegionOne cloudformation internal http://controller:8000/v1
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 9b4f604bb0984b63ad050655762a7d41 |
| interface    | internal                         |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | f1c9a2b146b94d75b19a13f1b806e4d8 |
| service_name | heat-cfn                         |
| service_type | cloudformation                   |
| url          | http://controller:8000/v1        |
+--------------+----------------------------------+

[root@controller ~]# openstack endpoint create --region RegionOne cloudformation admin http://controller:8000/v1
+--------------+----------------------------------+
| Field        | Value                            |
+--------------+----------------------------------+
| enabled      | True                             |
| id           | 9c8c76a1b03a44a8a7728fa47670410e |
| interface    | admin                            |
| region       | RegionOne                        |
| region_id    | RegionOne                        |
| service_id   | f1c9a2b146b94d75b19a13f1b806e4d8 |
| service_name | heat-cfn                         |
| service_type | cloudformation                   |
| url          | http://controller:8000/v1        |
+--------------+----------------------------------+

(5)创建Orchestration服务需要在Identity服务中添加信息,用以操作Stack

①创建Heat域

[root@controller ~]# openstack domain create --description "Stack projects and users" heat
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | Stack projects and users         |
| enabled     | True                             |
| id          | 3fb118462aa344ba8c0fb36fc0296fa7 |
| name        | heat                             |
| options     | {}                               |
| tags        | []                               |
+-------------+----------------------------------+

②创建heat_domain_admin用户,管理Heat域中的project和user

[root@controller ~]# openstack user create --domain heat --password-prompt heat_domain_admin
User Password:
Repeat User Password:
+---------------------+----------------------------------+
| Field               | Value                            |
+---------------------+----------------------------------+
| domain_id           | 3fb118462aa344ba8c0fb36fc0296fa7 |
| enabled             | True                             |
| id                  | 2632b29ed7a746e4bf01466c475fcf57 |
| name                | heat_domain_admin                |
| options             | {}                               |
| password_expires_at | None                             |
+---------------------+----------------------------------+

③将admin角色添加到heat_domain_admin域中的用户 heat以启用heat_domain_admin用户的管理堆栈管理权限

[root@controller ~]# openstack role add --domain heat --user-domain heat --user heat_domain_admin admin

④创建 heat_stack_owner 角色

[root@controller ~]# openstack role create heat_stack_owner
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | None                             |
| domain_id   | None                             |
| id          | 816798fab0bf4825a4a71d36ade47f44 |
| name        | heat_stack_owner                 |
| options     | {}                               |
+-------------+----------------------------------+

⑤将heat_stack_owner角色添加到demoproject和user,使demo user 可以管理 Stack

[root@controller ~]# openstack role add --project demo --user demo heat_stack_owner

⑥创建heat_stack_user_role

[root@controller ~]# openstack role create heat_stack_user
+-------------+----------------------------------+
| Field       | Value                            |
+-------------+----------------------------------+
| description | None                             |
| domain_id   | None                             |
| id          | a1b8a79460f04f28ba5c12bc372304d3 |
| name        | heat_stack_user                  |
| options     | {}                               |
+-------------+----------------------------------+

安装和配置Heat编排服务组件

(1)安装软件包

[root@controller ~]# yum install -y openstack-heat-api openstack-heat-api-cfn openstack-heat-engine openstack-heat-ui

(2)配置文件

编辑/etc/heat/heat.conf文件并完成以下操作

①在[database]部分中,配置数据库访问

[database]
connection = mysql+pymysql://heat:000000@controller/heat

②在[DEFAULT]部分中,配置RabbitMQ消息队列访问

[DEFAULT]
transport_url = rabbit://openstack:000000@controller

③在[keystone_authtoken][trustee]、 和[clients_keystone]部分中,配置身份服务访问

[keystone_authtoken]
www_authenticate_uri = http://controller:5000
auth_url = http://controller:5000
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = heat
password = 000000

[trustee]
auth_type = password
auth_url = http://controller:5000
username = heat
password = 000000
user_domain_name = default

[clients_keystone]
auth_uri = http://controller:5000

④在[DEFAULT]部分中,配置元数据和等待条件 URL

[DEFAULT]
heat_metadata_server_url = http://controller:8000
heat_waitcondition_server_url = http://controller:8000/v1/waitcondition

⑤在[DEFAULT]部分中,配置堆栈域和管理凭据

[DEFAULT]
stack_domain_admin = heat_domain_admin
stack_domain_admin_password = 000000
stack_user_domain_name = heat

(3)同步数据库

[root@controller ~]#  su -s /bin/sh -c "heat-manage db_sync" heat

完成安装

启动 Orchestration 服务并将其配置为开机自启

[root@controller ~]# systemctl start openstack-heat-api.service  openstack-heat-api-cfn.service openstack-heat-engine.service &&  systemctl enable openstack-heat-api.service  openstack-heat-api-cfn.service openstack-heat-engine.service
# 自行查看log文件是否报错

验证

(1)加载环境变量

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

(2)列出Heat编排服务组件进程是否成功启动和注册

[root@controller ~]# openstack orchestration service list
+------------+-------------+--------------------------------------+------------+--------+----------------------------+--------+
| Hostname   | Binary      | Engine ID                            | Host       | Topic  | Updated At                 | Status |
+------------+-------------+--------------------------------------+------------+--------+----------------------------+--------+
| controller | heat-engine | 4c0919cf-a36b-449c-8fa6-4dad9f355a43 | controller | engine | 2023-07-01T01:53:55.000000 | up     |
| controller | heat-engine | acc70835-f179-44c7-9ae6-e900cdda1fa8 | controller | engine | 2023-07-01T01:53:55.000000 | up     |
| controller | heat-engine | f9dc47f6-06ad-4dbb-afc5-7f4138b58d3b | controller | engine | 2023-07-01T01:53:55.000000 | up     |
| controller | heat-engine | 7c95fd77-74f8-4cd9-ac8e-984c36554ad8 | controller | engine | 2023-07-01T01:53:55.000000 | up     |
+------------+-------------+--------------------------------------+------------+--------+----------------------------+--------+

编写 Heat 模板执行 yaml 文件可以创建名为 heat-swift 的容器

[root@controller ~]# vim swift.yaml 
heat_template_version: 2014-10-16
description: "创建容器"
resources:
  user:
    type: OS::Swift::Container
    properties:
      name: heat-swift
[root@controller ~]# openstack stack create csqstack -t create_container.yaml 
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| id                  | 82f6fda4-fa1c-4cc7-b8f1-340f6e13d266 |
| stack_name          | csqstack                             |
| description         | 创建容器                             |
| creation_time       | 2023-07-01T11:49:09Z                 |
| updated_time        | None                                 |
| stack_status        | CREATE_IN_PROGRESS                   |
| stack_status_reason | Stack CREATE started                 |
+---------------------+--------------------------------------+
[root@controller ~]# swift list
heat-swift
Logo

数据库是今天社会发展不可缺少的重要技术,它可以把大量的信息进行有序的存储和管理,为企业的数据处理提供了强大的保障。

更多推荐