设置多区域 Dataproc Metastore 服务

本页介绍了如何设置多区域 Dataproc Metastore 服务。如需详细了解多区域 Dataproc Metastore 服务的工作方式,请参阅 Dataproc Metastore 区域

准备工作

所需的角色

如需获得创建多区域 Dataproc Metastore 服务所需的权限,请让管理员根据最小权限原则向您授予项目的以下 IAM 角色:

如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

此预定义角色包含创建多区域 Dataproc Metastore 服务所需的 metastore.services.create 权限。

您也可以使用自定义角色或其他预定义角色来获取此权限。

如需详细了解特定的 Dataproc Metastore 角色和权限,请参阅使用 IAM 管理访问权限

多区域 Dataproc Metastore 服务简介

多区域 Dataproc Metastore 服务会将数据存储在两个不同的区域,并使用这两个区域来运行工作负载。例如,多区域 nam7 包含 us-central1us-east4 区域。

  • 多区域 Dataproc Metastore 服务会在两个区域中复制元数据,并公开相关端点以访问 Hive Metastore。对于 gRPC,每个区域公开一个端点。对于 Thrift,每个子网公开一个端点。

  • 多区域 Dataproc Metastore 服务提供主动-主动高可用性 (HA) 集群配置。此配置意味着工作负载在运行作业时可以访问任一区域。它还为您的服务提供故障切换机制。例如,如果您的主要区域端点出现故障,工作负载会自动路由到次要区域。这有助于防止 Dataproc 作业中断。

注意事项

以下注意事项适用于多区域 Dataproc Metastore 服务。

创建多区域 Dataproc Metastore 服务

选择以下任一标签页,了解如何使用 Thrift 或 gRPC 端点协议创建多区域服务,并使用 Dataproc Metastore 服务 2。

gRPC

创建使用 gRPC 端点协议的多区域服务时,您无需设置任何特定的网络设置。gRPC 协议会为您处理网络路由。

控制台

  1. 在 Google Cloud 控制台中,前往 Dataproc Metastore 页面。

    前往 Dataproc Metastore

  2. 在导航栏中,点击 + 创建

    系统会打开创建 Metastore 服务对话框。

  3. 选择 Dataproc Metastore 2

  4. 价格和容量部分中,选择企业 Plus 版 - 双区域

  5. 对于端点协议,请选择 gRPC

  6. 如需创建并启动服务,请点击提交

    新 Metastore 服务会显示在 Dataproc Metastore 页面上。在服务准备就绪之前,状态会显示为正在创建。 准备就绪后,状态会变为有效。 预配服务可能需要几分钟时间。

gcloud CLI

如需创建 Dataproc Metastore 多区域服务,请运行以下 gcloud metastore services create 命令。此命令会创建 Dataproc Metastore 版本 3.1.2。

gcloud metastore services create SERVICE \
  --location=MULTI_REGION \
{ --instance-size=INSTANCE_SIZE | --scaling-factor=SCALING_FACTOR } \
  --endpoint-protocol=grpc

替换以下内容:

  • SERVICE:Dataproc Metastore 服务的名称。
  • MULTI_REGION:您要在其中创建 Dataproc Metastore 服务的多区域
  • INSTANCE_SIZE:多区域 Dataproc Metastore 的实例大小。例如 smallmediumlarge。如果您为 INSTANCE_SIZE 指定了值,请勿为 SCALING_FACTOR 指定值。
  • SCALING_FACTOR:Dataproc Metastore 服务的扩缩比例。例如 0.1。 如果您为 SCALING_FACTOR 指定了值,请勿为 INSTANCE_SIZE 指定值。

Thrift

创建使用 Thrift 端点协议的多区域服务时,您必须设置适当的子网设置。在这种情况下,对于您使用的每个 VPC 网络,您都必须提供每个区域中的至少一个子网。

例如,如需创建 nam7 多区域,您必须同时提供 us-central1us-east4 区域。

控制台

  1. 在 Google Cloud 控制台中,前往 Dataproc Metastore 页面。

    前往 Dataproc Metastore

  2. 在导航栏中,点击 + 创建

    系统会打开创建 Metastore 服务对话框。

  3. 选择 Dataproc Metastore 2

  4. 价格和容量部分中,选择企业 Plus 版 - 双区域

    如需了解详情,请参阅价格方案和伸缩配置

  5. 服务名称字段中,为服务输入一个唯一名称。

    如需了解命名惯例,请参阅资源命名惯例

  6. 对于端点协议,请选择 Thrift

  7. 对于网络配置,请提供构成所选多区域配置的子网。

  8. 对于其余的服务配置选项,请使用提供的默认值。

  9. 如需创建并启动服务,请点击提交

    新 Metastore 服务会显示在 Dataproc Metastore 页面上。在服务准备就绪之前,状态会显示为正在创建。 准备就绪后,状态会变为有效。 预配服务可能需要几分钟时间。

gcloud CLI

如需创建 Dataproc Metastore 多区域服务,请运行以下 gcloud metastore services create 命令。 此命令会创建 Dataproc Metastore 版本 3.1.2。

gcloud metastore services create SERVICE \
  --location=MULTI_REGION \
  --consumer-subnetworks="projects/PROJECT_ID/regions/LOCATION1/subnetworks/SUBNET1,projects/PROJECT_ID/regions/LOCATION2/subnetworks/SUBNET2" \
{ --instance-size=INSTANCE_SIZE | --scaling-factor=SCALING_FACTOR } \
  --endpoint-protocol=thrift

或者,您也可以将网络设置存储在文件中,如以下命令所示。

gcloud metastore services create SERVICE \
  --location=MULTI_REGION \
  --network-config-from-file=NETWORK_CONFIG_FROM_FILE
{ --instance-size=INSTANCE_SIZE | --scaling-factor=SCALING_FACTOR } \
  --endpoint-protocol=thrift

替换以下内容:

  • SERVICE:Dataproc Metastore 服务的名称。
  • MULTI_REGION:您要在其中创建 Dataproc Metastore 服务的多区域。
  • PROJECT_ID:您要在其中创建 Dataproc Metastore 服务的 Google Cloud 项目 ID。
  • SUBNET1SUBNET2:构成多区域配置的子网列表。您可以使用子网的 ID、完全限定的网址或相对名称。您最多可以指定 6 个子网。
  • LOCATION1LOCATION2:构成多区域配置的位置列表。 您可以使用相应地点的 ID。例如,对于 nam7 多区域,您可以使用 us-central1us-east4
  • NETWORK_CONFIG_FROM_FILE:包含网络配置的 YAML 文件的路径。
  • INSTANCE_SIZE:多区域 Dataproc Metastore 的实例大小。例如 smallmediumlarge。如果您为 INSTANCE_SIZE 指定了值,请勿为 SCALING_FACTOR 指定值。
  • SCALING_FACTOR:Dataproc Metastore 服务的扩缩比例。例如 0.1。 如果您为 SCALING_FACTOR 指定了值,请勿为 INSTANCE_SIZE 指定值。

REST

如需了解如何创建多区域 Dataproc Metastore 服务,请按照说明使用 Google APIs Explorer 创建服务

如需配置多区域服务,请在 Network Config 对象中提供以下信息。

  "network_config": {
    "consumers": [
        {"subnetwork": "projects/PROJECT_ID/regions/LOCATION/subnetworks/SUBNET1"},
        {"subnetwork": "projects/PROJECT_ID/regions/LOCATION/subnetworks/SUBNET2"}
    ],
    "scaling_config": {
    "scaling_factor": SCALING_FACTOR
    }
  }

替换以下内容:

  • PROJECT_ID:包含 Dataproc Metastore 服务的项目的 Google Cloud 项目 ID。
  • LOCATION:Dataproc Metastore 服务所在的 Google Cloud 区域。
  • SUBNET1SUBNET2:构成多区域配置的子网列表。您可以使用子网的 ID、完全限定的网址或相对名称。您最多可以指定 5 个子网。
  • SCALING_FACTOR:您要用于服务的缩放比例

将 Dataproc Metastore 连接到 Dataproc 集群

选择以下任一标签页,了解如何从 Dataproc 集群连接多区域 Dataproc Metastore 服务。

gRPC

如需连接 Dataproc 集群,请选择与您使用的 Dataproc Metastore 版本对应的标签页。

Dataproc Metastore 3.1.2

  1. 为 Dataproc 集群创建以下变量:

    CLUSTER_NAME=CLUSTER_NAME
    PROJECT_ID=PROJECT_ID
    MULTI_REGION=MULTI_REGION
    DATAPROC_IMAGE_VERSION=DATAPROC_IMAGE_VERSION
    PROJECT=PROJECT
    SERVICE_ID=SERVICE_ID

    替换以下内容:

    • CLUSTER_NAME:Dataproc 集群的名称。
    • PROJECT_ID:包含 Dataproc 集群的 Google Cloud 项目。确保您使用的子网拥有访问此项目的相应权限。
    • MULTI_REGION:您要在其中创建 Dataproc 集群的 Google Cloud 多区域。
    • DATAPROC_IMAGE_VERSION:您正在 Dataproc Metastore 服务中使用的 Dataproc 映像版本。您必须使用 2.0 或更高版本的映像。
    • PROJECT:包含 Dataproc Metastore 服务的项目。
    • SERVICE_ID:Dataproc Metastore 服务的服务 ID。
  2. 如需创建集群,请运行以下 gcloud dataproc clusters create 命令。--enable-kerberos 是可选项。仅当您在集群中使用 Kerberos 时,才应包含此选项。

    gcloud dataproc clusters create ${CLUSTER_NAME} \
     --project ${PROJECT_ID} \
     --region ${MULTI_REGION} \
     --image-version ${DATAPROC_IMAGE_VERSION} \
     --scopes "https://www.googleapis.com/auth/cloud-platform" \
     --dataproc-metastore projects/${PROJECT}/locations/${MULTI_REGION}/services/${SERVICE_ID} \
    [ --enable-kerberos ]

Dataproc Metastore 2.3.6

  1. 为 Dataproc Metastore 服务创建以下变量:

    METASTORE_PROJECT=METASTORE_PROJECT
    METASTORE_ID=METASTORE_ID
    MULTI_REGION=MULTI_REGION
    SUBNET=SUBNET

    替换以下内容:

    • METASTORE_PROJECT:包含 Dataproc Metastore 服务的 Google Cloud 项目。
    • METASTORE_ID:Dataproc Metastore 服务的服务 ID。
    • MULTI_REGION:您要用于 Dataproc Metastore 服务的多区域位置。
    • SUBNET:您为 Dataproc Metastore 服务使用的子网之一。或者用于服务的子网的父 VPC 网络中的任何子网。
  2. 为 Dataproc 集群创建以下变量:

    CLUSTER_NAME=CLUSTER_NAME
    DATAPROC_PROJECT=DATAPROC_PROJECT
    DATAPROC_REGION=DATAPROC_REGION
    HIVE_VERSION=HIVE_VERSION
    IMAGE_VERSION=r>IMAGE_VERSION

    替换以下内容:

    • CLUSTER_NAME:Dataproc 集群的名称。
    • DATAPROC_PROJECT:包含 Dataproc 集群的 Google Cloud 项目。确保您使用的子网拥有访问此项目的相应权限。
    • DATAPROC_REGION:您要在其中创建 Dataproc 集群的 Google Cloud 区域。
    • HIVE_VERSION:Dataproc Metastore 服务使用的 Hive 版本。
    • IMAGE_VERSION:您正在 Dataproc Metastore 服务中使用的 Dataproc 映像版本。
      • 对于 Hive Metastore 版本 2.0,请使用映像版本 1.5
      • 对于 Hive Metastore 版本 3.1.2,请使用映像版本 2.0
  3. 检索 Dataproc Metastore 服务的仓库目录,并将其存储在一个变量中。

    WAREHOUSE_DIR=$(gcloud metastore services describe "${METASTORE_ID}" --project "${METASTORE_PROJECT}" --location "${MULTI_REGION}" --format="get(hiveMetastoreConfig.configOverrides[hive.metastore.warehouse.dir])")
  4. 创建配置了多区域 Dataproc Metastore 的 Dataproc 集群。

    gcloud dataproc clusters create ${CLUSTER_NAME} \
        --project "${DATAPROC_PROJECT}" \
        --region ${DATAPROC_REGION} \
        --scopes "https://www.googleapis.com/auth/cloud-platform" \
        --subnet "${SUBNET}" \
        --optional-components=DOCKER \
        --image-version ${IMAGE_VERSION} \
        --metadata "hive-version=${HIVE_VERSION},dpms-name=${DPMS_NAME}" \
        --properties "hive:hive.metastore.uris=thrift://localhost:9083,hive:hive.metastore.warehouse.dir=${WAREHOUSE_DIR}" \
        --initialization-actions gs://metastore-init-actions/mr-metastore-grpc-proxy/metastore-grpc-proxy.sh

Thrift

方法 1:修改 hive-site.xml 文件

  1. 找到 Dataproc Metastore 服务的端点 URI仓库目录。您可以选择公开的任何一个端点。
  2. 在 Google Cloud 控制台中,前往虚拟机实例页面。
  3. 在虚拟机实例列表中,点击 Dataproc 主节点 (.*-m) 所在行中的 SSH

    此时会打开一个浏览器窗口,并显示节点上的主目录。

  4. 打开 /etc/hive/conf/hive-site.xml 文件。

    sudo vim /etc/hive/conf/hive-site.xml
    

    您将看到类似如下所示的输出:

    <property>
        <name>hive.metastore.uris</name>
        <value>ENDPOINT_URI</value>
    </property>
    <property>
        <name>hive.metastore.warehouse.dir</name>
        <value>WAREHOUSE_DIR</value>
    </property>
    

    替换以下内容:

  5. 重启 HiveServer2:

    sudo systemctl restart hive-server2.service
    

选项 2:使用 gcloud CLI

运行以下 gcloud CLI gcloud dataproc clusters create 命令。

  1. 找到 Dataproc Metastore 服务的端点 URI仓库目录。您可以选择公开的任何一个端点。
gcloud dataproc clusters create CLUSTER_NAME \
    --network NETWORK \
    --project PROJECT_ID \
    --scopes "https://www.googleapis.com/auth/cloud-platform" \
    --image-version IMAGE_VERSION \
    --properties "hive:hive.metastore.uris=ENDPOINT,hive:hive.metastore.warehouse.dir=WAREHOUSE_DIR"

替换以下内容:

  • CLUSTER_NAME:Dataproc 集群的名称。
  • NETWORK:包含 Dataproc 集群的 Google Cloud 项目。确保您使用的子网拥有访问此项目的相应权限。
  • PROJECT_ID:Dataproc Metastore 服务使用的 Hive 版本。
  • IMAGE_VERSION:您正在 Dataproc Metastore 服务中使用的 Dataproc 映像版本。
    • 对于 Hive Metastore 版本 2.0,请使用映像版本 1.5
    • 对于 Hive Metastore 版本 3.1.2,请使用映像版本 2.0
  • ENDPOINT:Dataproc Metastore 使用的 Thrift 端点。
  • WAREHOUSE_DIR:Dataproc Metastore 的仓库目录。

自定义区域配置

您可以将 Dataproc Metastore 服务配置为使用自定义区域配置。

借助自定义区域配置,您的服务可以运行来自两个不同区域的工作负载。这样可提供跨区域的冗余,这意味着工作负载在运行作业时可以访问任一区域。它还为您的服务提供故障切换机制。例如,如果某个区域性端点出现故障,您的工作负载会自动路由到另一个区域。这有助于防止工作负载和作业中断。

借助自定义区域配置,您还可以控制元数据的存储位置以及 Hive Metastore 端点的公开位置。这有助于提高处理工作负载时的性能。

注意事项

对于配置了自定义区域配置的 Dataproc Metastore 服务,请注意以下事项:

  • 地区/配对限制:并非所有区域和组合都允许。
  • 只读限制:只读区域无法接受写入操作。如果选择了只读区域,但无法访问读写区域,则写入操作无法处理。
  • 配置不可变性:区域配置一经设置便无法更改。
  • 仅限美国堆栈:自定义双区域仅支持 US 堆栈,且仅限美国境内。

创建自定义区域服务

如需设置自定义区域,请在创建服务时选择两个相邻的区域。此组合可以是两个读写区域,也可以是一个读写区域和一个只读区域。

控制台

  1. 在 Google Cloud 控制台中,前往 Dataproc Metastore 页面。

    前往 Dataproc Metastore

  2. 在导航栏中,点击 + 创建

    系统会打开创建 Metastore 服务对话框。

  3. 选择 Dataproc Metastore 2

  4. 价格和容量部分中,选择企业 Plus 版 - 双区域

  5. 服务名称字段中,为服务输入一个唯一名称。

  6. 数据位置中,选择美国(大陆)

    系统会显示自定义区域部分。

  7. 自定义区域下,选择一个读写区域和一个只读区域。

  8. 对于其余的服务配置选项,请使用提供的默认值。

  9. 如需创建并启动服务,请点击提交

    新 Metastore 服务会显示在 Dataproc Metastore 页面上。在服务准备就绪之前,状态会显示为正在创建。 准备就绪后,状态会变为有效。 预配服务可能需要几分钟时间。

gcloud

如需创建具有自定义区域的 Dataproc Metastore 服务,请运行以下 gcloud CLI gcloud beta metastore services create 命令。

gcloud beta metastore services create SERVICE \
  --read-write-regions

替换以下内容:

  • SERVICE:Dataproc Metastore 服务的名称。
  • READ_WRITE_REGIONS:属于自定义区域配置的受支持的读写区域
  • READ_ONLY_REGIONS:自定义区域配置中支持的只读区域

后续步骤