4.5. 在 Red Hat Ansible Automation Platform Operator 上为自动化中心配置外部数据库
对于希望使用外部数据库部署 Ansible Automation Platform 的用户,可以通过使用实例凭证和连接信息配置 secret,然后使用 oc create
命令将其应用到其集群中。
默认情况下,Ansible Automation Platform Operator 会在与 Ansible Automation Platform 部署相同的命名空间中创建并配置受管 PostgreSQL pod。
如果用户更喜欢使用专用节点来确保专用资源或手动管理备份、升级或性能调整,则用户可能会选择使用外部数据库。
只要数据库名称不同,同一个外部数据库(PostgreSQL 实例)可用于自动化 hub 和自动化控制器。换句话说,您可以在一个 PostgreSQL 实例中,带有使用不同名称的多个数据库。
以下部分概述了在 Ansible Automation Platform Operator 上为您的自动化中心配置外部数据库的步骤。
前提条件
外部数据库必须是 PostgreSQL 数据库,这是 Ansible Automation Platform 当前发行版本支持的版本。
Ansible Automation Platform 2.4 支持 PostgreSQL 13。
流程
外部 postgres 实例凭证和连接信息需要存储在 secret 中,然后在自动化中心 spec 中设置。
按照下面的模板,创建一个
postgres_configuration_secret
.yaml 文件:apiVersion: v1 kind: Secret metadata: name: external-postgres-configuration namespace: <target_namespace> 1 stringData: host: "<external_ip_or_url_resolvable_by_the_cluster>" 2 port: "<external_port>" 3 database: "<desired_database_name>" username: "<username_to_connect_as>" password: "<password_to_connect_with>" 4 sslmode: "prefer" 5 type: "unmanaged" type: Opaque
使用
oc create
命令将external-postgres-configuration-secret.yml
应用到您的集群。$ oc create -f external-postgres-configuration-secret.yml
在创建
AutomationHub
自定义资源对象时,在 spec 中指定 secret,如下例所示:apiVersion: automationhub.ansible.com/v1beta1 kind: AutomationHub metadata: name: hub-dev spec: postgres_configuration_secret: external-postgres-configuration
4.5.1. 为自动化中心 PostgreSQL 数据库启用 hstore 扩展
在 Ansible Automation Platform 2.4 中,数据库迁移脚本使用 hstore
字段来存储信息,因此必须启用对自动化中心 PostgreSQL 数据库的 hstore
扩展。
使用 Ansible Automation Platform 安装程序和受管 PostgreSQL 服务器时,此过程是自动的。
如果 PostgreSQL 数据库是外部的,则必须在自动化中心安装前手动为自动化中心 PostreSQL 数据库启用 hstore
扩展。
如果在自动化中心安装前没有启用 hstore
扩展,在数据库迁移过程中会引发故障。
流程
检查 PostgreSQL 服务器上是否有扩展(自动化 hub 数据库)。
$ psql -d <automation hub database> -c "SELECT * FROM pg_available_extensions WHERE name='hstore'"
其中
<automation hub database>
的默认值为automationhub
。带有
hstore
可用的输出示例 :name | default_version | installed_version |comment ------+-----------------+-------------------+--------------------------------------------------- hstore | 1.7 | | data type for storing sets of (key, value) pairs (1 row)
带有
hstore
不可用的输出示例 :name | default_version | installed_version | comment ------+-----------------+-------------------+--------- (0 rows)
在基于 RHEL 的服务器上,
hstore
扩展包含在postgresql-contrib
RPM 软件包中,该软件包在安装 PostgreSQL 服务器 RPM 软件包时不会自动安装。要安装 RPM 软件包,请使用以下命令:
dnf install postgresql-contrib
使用以下命令,在自动化中心数据库上创建
hstore
PostgreSQL 扩展:$ psql -d <automation hub database> -c "CREATE EXTENSION hstore;"
输出:
CREATE EXTENSION
在以下输出中,
installed_version
字段包含使用的hstore
扩展,表示启用了hstore
。name | default_version | installed_version | comment -----+-----------------+-------------------+------------------------------------------------------ hstore | 1.7 | 1.7 | data type for storing sets of (key, value) pairs (1 row)