5.6. 配置外部(客户提供)PostgreSQL 数据库
为容器化 Ansible Automation Platform 设置外部(客户提供)PostgreSQL 数据库,以使用您自己的数据库基础架构。
设置外部数据库时有两种场景:
- 具有 PostgreSQL 管理员凭证的外部数据库
- 没有 PostgreSQL 管理员凭证的外部数据库
- 将外部数据库与 Ansible Automation Platform 搭配使用时,您必须创建和支持该数据库。在卸载 Ansible Automation Platform 时,请确保清除外部数据库。
- Red Hat Ansible Automation Platform 要求客户提供(外部)数据库才能获得 ICU 支持。
- 在配置外部数据库期间,您必须检查外部数据库覆盖。如需更多信息,请参阅 Red Hat Ansible Automation Platform 数据库的支持覆盖范围。
5.6.1. 使用 PostgreSQL 管理员凭证设置外部数据库 复制链接链接已复制到粘贴板!
如果您有 PostgreSQL admin 凭证,您可以在清单文件中提供它们,安装程序会为您创建 PostgreSQL 用户和数据库。PostgreSQL admin 帐户必须具有 SUPERUSER 特权。
流程
要配置 PostgreSQL admin 凭证,请在
[all:vars]组下的清单文件中添加以下变量:postgresql_admin_username=<set your own> postgresql_admin_password=<set your own>
5.6.2. 设置没有 PostgreSQL 管理员凭证的外部数据库 复制链接链接已复制到粘贴板!
如果您没有 PostgreSQL admin 凭证,则需要在运行安装程序前为每个组件(平台网关、自动化控制器、自动化中心和 Ansible)创建 PostgreSQL 用户和密码。
流程
使用具有
SUPERUSER特权的用户连接到兼容 PostgreSQL 的数据库服务器。# psql -h <hostname> -U <username> -p <port_number>例如:
# psql -h db.example.com -U superuser -p 5432使用密码创建用户,并确保将
CREATEDB角色分配给该用户。如需更多信息,请参阅 数据库角色。CREATE USER <username> WITH PASSWORD <password> CREATEDB;创建数据库并添加您创建的用户作为所有者。
CREATE DATABASE <database_name> OWNER <username>;为各个组件创建 PostgreSQL 用户和数据库后,您可以在
[all:vars]组下的清单文件中提供它们。# Platform gateway gateway_pg_host=aap.example.org gateway_pg_database=<set your own> gateway_pg_username=<set your own> gateway_pg_password=<set your own> # Automation controller controller_pg_host=aap.example.org controller_pg_database=<set your own> controller_pg_username=<set your own> controller_pg_password=<set your own> # Automation hub hub_pg_host=aap.example.org hub_pg_database=<set your own> hub_pg_username=<set your own> hub_pg_password=<set your own> # Event-Driven Ansible eda_pg_host=aap.example.org eda_pg_database=<set your own> eda_pg_username=<set your own> eda_pg_password=<set your own>
5.6.3. 为自动化中心 PostgreSQL 数据库启用 hstore 扩展 复制链接链接已复制到粘贴板!
数据库迁移脚本使用 hstore 字段来存储信息,因此在自动化中心 PostgreSQL 数据库中必须启用 hstore 扩展。
使用 Ansible Automation Platform 安装程序和受管 PostgreSQL 服务器时,此过程是自动的。
如果 PostgreSQL 数据库是外部的,则必须在安装前在自动化中心 PostgreSQL 数据库中手动启用 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-contribRPM 软件包中,该软件包在安装 PostgreSQL 服务器 RPM 软件包时不会自动安装。要安装 RPM 软件包,请使用以下命令:
dnf install postgresql-contrib使用以下命令将
hstorePostgreSQL 扩展加载到自动化中心数据库中:$ psql -d <automation hub database> -c "CREATE EXTENSION hstore;"在以下输出中,
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)
5.6.4. 可选:为外部数据库配置 mutual TLS (mTLS)身份验证 复制链接链接已复制到粘贴板!
默认禁用 mTLS 身份验证。要使用 mTLS 身份验证配置每个组件的数据库,请将以下变量添加到 [all:vars] 组下,并确保每个组件都有不同的 TLS 证书和密钥:
流程
将以下变量添加到清单文件中的
[all:vars]组:# Platform gateway gateway_pg_cert_auth=true gateway_pg_tls_cert=/path/to/gateway.cert gateway_pg_tls_key=/path/to/gateway.key gateway_pg_sslmode=verify-full # Automation controller controller_pg_cert_auth=true controller_pg_tls_cert=/path/to/awx.cert controller_pg_tls_key=/path/to/awx.key controller_pg_sslmode=verify-full # Automation hub hub_pg_cert_auth=true hub_pg_tls_cert=/path/to/pulp.cert hub_pg_tls_key=/path/to/pulp.key hub_pg_sslmode=verify-full # Event-Driven Ansible eda_pg_cert_auth=true eda_pg_tls_cert=/path/to/eda.cert eda_pg_tls_key=/path/to/eda.key eda_pg_sslmode=verify-full