4.4. 配置 Hive metastore

Hive metastore 负责存储所有在 Presto 和 Hive 中创建的数据库表的元数据。metastore 默认会将这些信息存储在附加到 Pod 上的 PersistentVolume 中的本地嵌入式 Derby 数据库中。

通常,Hive metastore 的默认配置适用于小型集群,但用户可能希望通过使用专用 SQL 数据库存储 Hive metastore 数据来提高性能或从集群中移出存储要求。

4.4.1. 配置 PersistentVolume

Hive 默认需要一个 PersistentVolume 才可运行。

hive-metastore-db-data 为默认需要的主 PersistentVolumeClaim (PVC)。Hive metastore 使用该 PVC 存储与表相关的元数据,如表名称、列和位置。处理查询时,Presto 和 Hive 服务器可使用 Hive metastore 来查找表元数据。如果使用 MySQL 或 PostgreSQL 作为 Hive metastore 的数据库,则不需要这个要求。

为了进行安装,Hive metastore 要求通过一个 StoreClass 启用动态卷置备功能,一个有正确容量的持久性卷需要预先被手动创建,或使用已存在的 MySQL 或 PostgreSQL 数据库。

4.4.1.1. 为 Hive metastore 配置存储类

要为 hive-metastore-db-data PVC 配置和指定 StorageClass,请在 MeteringConfig 中指定 StorageClass。以下 metastore-storage.yaml 文件包含 StorageClass 部分的示例。

apiVersion: metering.openshift.io/v1
kind: MeteringConfig
metadata:
  name: "operator-metering"
spec:
  hive:
    spec:
      metastore:
        storage:
          # Default is null, which means using the default storage class if it exists.
          # If you wish to use a different storage class, specify it here
          # class: "null" 1
          size: "5Gi"
1
取消此行的注释,并将 null 替换为要使用的 StorageClass 名称。使用 null 值会使 metering 使用集群的默认 StorageClass。

4.4.1.2. 配置 Hive Metastore 的卷大小

使用以下 MetaStore-storage.yaml 文件作为模板。

apiVersion: metering.openshift.io/v1
kind: MeteringConfig
metadata:
  name: "operator-metering"
spec:
  hive:
    spec:
      metastore:
        storage:
          # Default is null, which means using the default storage class if it exists.
          # If you wish to use a different storage class, specify it here
          # class: "null"
          size: "5Gi" 1
1
size 值替换为您所需容量。示例文件显示“5Gi”。

4.4.2. 对 Hive metastore 使用 MySQL 或 PostgreSQL

默认安装的 metering 会把 Hive 配置为使用名为 Derby 的嵌入式 Java 数据库。该配置不适用于较大环境,它可以被替换为使用 MySQL 或 PostgreSQL 数据库。如果您的部署需要 Hive 使用 MySQL 或 PostgreSQL 数据库,则请使用以下配置示例文件。

有 4 个配置选项可用于控制 Hive metastore 所用数据库: url、driver、username 和 password。

使用以下示例配置文件配置 Hive 使用 MySQL 数据库:

spec:
  hive:
    spec:
      metastore:
        storage:
          create: false
      config:
        db:
          url: "jdbc:mysql://mysql.example.com:3306/hive_metastore"
          driver: "com.mysql.jdbc.Driver"
          username: "REPLACEME"
          password: "REPLACEME"

您可使用 spec.hive.config.url 来传递其他 JDBC 参数。更多详情请参阅 MySQL Connector/J 文档

使用以下示例配置文件配置 Hive 使用 PostgreSQL 数据库:

spec:
  hive:
    spec:
      metastore:
        storage:
          create: false
      config:
        db:
          url: "jdbc:postgresql://postgresql.example.com:5432/hive_metastore"
          driver: "org.postgresql.Driver"
          username: "REPLACEME"
          password: "REPLACEME"

您可使用 URL 来传递其他 JDBC 参数。更多详情请参阅 PostgreSQL JDBC 驱动程序文档