本页介绍了如何设置跨区域 Dataproc Metastore 服务。如需详细了解多区域 Dataproc Metastore 服务的运作方式,请参阅 Dataproc Metastore 区域。
准备工作
- 在您的项目中启用 Dataproc Metastore。
- 了解适用于您的项目的网络要求。
- 了解 Dataproc Metastore 区域,然后选择适当的区域。
所需的角色
如需获得创建多区域 Dataproc Metastore 服务所需的权限,请让管理员根据最小特权原则为您授予项目的以下 IAM 角色:
-
授予对 Dataproc Metastore 资源的完全控制权 (
roles/metastore.editor
) -
授予对所有 Dataproc Metastore 资源的完整访问权限,包括 IAM 政策管理 (
roles/metastore.admin
)
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
此预定义角色包含创建多区域 Dataproc Metastore 服务所需的 metastore.services.create
权限。
多区域 Dataproc Metastore 服务简介
多区域 Dataproc Metastore 服务会将您的数据存储在两个不同的区域,并使用这两个区域来运行您的工作负载。例如,多区域 nam7
包含 us-central1
和 us-east4
区域。
多区域 Dataproc Metastore 服务会在两个区域复制元数据,并公开相关端点以访问 Hive Metastore。对于 gRPC,每个区域会公开一个端点。对于 Thrift,每个子网会公开一个端点。
多区域 Dataproc Metastore 服务提供主动-主动高可用性 (HA) 集群配置。这种配置意味着,工作负载在运行作业时可以访问任一区域。它还为您的服务提供了故障转移机制。例如,如果您的主要区域端点发生故障,您的工作负载会自动路由到次要区域。这有助于防止 Dataproc 作业中断。
注意事项
以下注意事项适用于多区域 Dataproc Metastore 服务。
多区域服务仅支持 Spanner 数据库类型。请先查看受支持的功能列表,然后再创建多区域服务。
多区域服务仅支持 Dataproc Metastore 2 配置。
多区域服务会在 Cloud Storage 多区域位置中创建工件存储分区。例如,
Nam7
存储分区是在US
多区域位置创建的。
创建多区域 Dataproc Metastore 服务
选择以下任一标签页,了解如何使用 Dataproc Metastore 服务 2 通过 Thrift 或 gRPC 端点协议创建多区域服务。
创建使用 gRPC 端点协议的多区域服务时,您无需设置任何特定的网络设置。gRPC 协议会为您处理网络路由。
在 Google Cloud 控制台中,前往 Dataproc Metastore 页面。
在导航栏中,点击 +Create(创建)。
系统随即会打开创建 Metastore 服务对话框。
选择 Dataproc Metastore 2。
在价格和容量部分中,选择企业 Plus 版 - 双区域
选择 gRPC 作为端点协议。
如需创建并启动该服务,请点击提交。
您的新 Metastore 服务会显示在 Dataproc Metastore 页面上。在服务准备就绪之前,状态会显示为正在创建。准备就绪后,状态会变为有效。 预配服务可能需要几分钟时间。
如需创建 Dataproc Metastore 多区域服务,请运行以下 gcloud metastore services create
命令。此命令会创建 Dataproc Metastore 版本 3.1.2。
gcloud metastore services createSERVICE \ --location=MULTI_REGION \ { --instance-size=INSTANCE_SIZE | --scaling-factor=SCALING_FACTOR } \ --endpoint-protocol=grpc
替换以下内容:
创建使用 Thrift 端点协议的多区域服务时,您必须设置适当的子网设置。在这种情况下,对于您使用的每个 VPC 网络,您必须在每个区域中至少提供一个子网。
例如,若要创建 nam7
多区域,您必须同时提供 us-central1
和 us-east4
区域。
在 Google Cloud 控制台中,前往 Dataproc Metastore 页面。
在导航栏中,点击 +Create(创建)。
系统随即会打开创建 Metastore 服务对话框。
选择 Dataproc Metastore 2。
在价格和容量部分中,选择企业 Plus 版 - 双区域。
如需了解详情,请参阅定价方案和扩缩配置。
在服务名称字段中,为服务输入一个唯一名称。
如需了解命名惯例,请参阅资源命名惯例。
对于端点协议,请选择 Thrift。
对于网络配置,请提供构成您所选多区域配置的子网。
对于其余服务配置选项,请使用提供的默认值。
如需创建并启动该服务,请点击提交。
您的新 Metastore 服务会显示在 Dataproc Metastore 页面上。在服务准备就绪之前,状态会显示为正在创建。准备就绪后,状态会变为有效。 预配服务可能需要几分钟时间。
如需创建 Dataproc Metastore 多区域服务,请运行以下 gcloud metastore services create
命令。此命令会创建 Dataproc Metastore 版本 3.1.2。
gcloud metastore services createSERVICE \ --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 createSERVICE \ --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。SUBNET1
、SUBNET2
:构成多区域配置的子网列表。您可以使用子网的 ID、完全限定网址或相对名称。您最多可以指定 6 个子网。LOCATION1
、LOCATION2
:构成多区域配置的位置列表。您可以使用相应地理位置的 ID。例如,对于nam7
多区域,您可以使用us-central1
和us-east4
。NETWORK_CONFIG_FROM_FILE
:包含网络配置的 YAML 文件的路径。INSTANCE_SIZE
:多区域 Dataproc Metastore 的实例大小。例如small
、medium
或large
。如果为INSTANCE_SIZE
指定了值,请勿为SCALING_FACTOR
指定值。SCALING_FACTOR
:Dataproc Metastore 服务的缩放因子。例如0.1
。 如果为SCALING_FACTOR
指定了值,请勿为INSTANCE_SIZE
指定值。
如需了解如何创建多区域 Dataproc Metastore 服务,请按照说明使用 Google API 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 区域。SUBNET1
、SUBNET2
:用于构成多区域配置的子网列表。您可以使用子网的 ID、完全限定网址或相对名称。您最多可以指定 5 个子网。SCALING_FACTOR
:您要为服务使用的缩放比例。
将 Dataproc Metastore 连接到 Dataproc 集群
请选择以下任一标签页,了解如何从 Dataproc 集群连接多区域 Dataproc Metastore 服务。
如需连接 Dataproc 集群,请选择与您使用的 Dataproc Metastore 版本对应的标签页。
为您的 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
: Google Cloud 包含 Dataproc 集群的项目。确保您使用的子网具有访问此项目的适当权限。MULTI_REGION
:您要在其中创建 Dataproc 集群的 Google Cloud 多区域。DATAPROC_IMAGE_VERSION
:您与 Dataproc Metastore 服务搭配使用的 Dataproc 映像版本。您必须使用2.0
或更高版本的映像。PROJECT
:包含 Dataproc Metastore 服务的项目。SERVICE_ID
:Dataproc Metastore 服务的服务 ID。
如需创建集群,请运行以下
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 服务创建以下变量:
METASTORE_PROJECT=
METASTORE_PROJECT METASTORE_ID=METASTORE_ID MULTI_REGION=MULTI_REGION SUBNET=SUBNET 替换以下内容:
METASTORE_PROJECT
: Google Cloud 包含您的 Dataproc Metastore 服务的项目。METASTORE_ID
:Dataproc Metastore 服务的服务 ID。MULTI_REGION
:您要为 Dataproc Metastore 服务使用的多区域位置。SUBNET
:您为 Dataproc Metastore 服务使用的子网之一。或者,用于您的服务的子网的父 VPC 网络中的任何子网。
为您的 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
: Google Cloud 包含 Dataproc 集群的项目。确保您使用的子网具有访问此项目的适当权限。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
。
- 对于 Hive Metastore 版本 2.0,请使用映像版本
检索 Dataproc Metastore 服务的仓库目录,并将其存储在变量中。
WAREHOUSE_DIR=$(gcloud metastore services describe "${METASTORE_ID}" --project "${METASTORE_PROJECT}" --location "${MULTI_REGION}" --format="get(hiveMetastoreConfig.configOverrides[hive.metastore.warehouse.dir])")
创建一个配置了多区域 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
方法 1:修改 hive-site.xml 文件
- 找到 Dataproc Metastore 服务的端点 URI 和仓库目录。您可以选择公开的任意端点。
- 在 Google Cloud 控制台中,前往虚拟机实例页面。
在虚拟机实例列表中,点击 Dataproc 主节点 (
.*-m
) 所在行中的 SSH。此时会在节点的主目录中打开一个浏览器窗口。
打开
/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>替换以下内容:
重启 HiveServer2:
sudo systemctl restart hive-server2.service
方案 2:使用 gcloud CLI
运行以下 gcloud CLI gcloud dataproc clusters create
命令。
gcloud dataproc clusters createCLUSTER_NAME \ --networkNETWORK \ --projectPROJECT_ID \ --scopes "https://www.googleapis.com/auth/cloud-platform" \ --image-versionIMAGE_VERSION \ --properties "hive:hive.metastore.uris=ENDPOINT ,hive:hive.metastore.warehouse.dir=WAREHOUSE_DIR "
替换以下内容:
CLUSTER_NAME
:您的 Dataproc 集群的名称。NETWORK
: Google Cloud 包含 Dataproc 集群的项目。确保您使用的子网具有访问此项目的适当权限。PROJECT_ID
:您的 Dataproc Metastore 服务使用的 Hive 版本。IMAGE_VERSION
:您在 Dataproc Metastore 服务中使用的 Dataproc 映像版本。- 对于 Hive Metastore 版本 2.0,请使用映像版本
1.5
。 - 对于 Hive Metastore 版本 3.1.2,请使用映像版本
2.0
。
- 对于 Hive Metastore 版本 2.0,请使用映像版本
ENDPOINT
:Dataproc Metastore 使用的 Thrift 端点。WAREHOUSE_DIR
:Dataproc Metastore 的仓库目录。
自定义区域配置
您可以将 Dataproc Metastore 服务配置为使用自定义区域配置。
借助自定义区域配置,您的服务可以运行来自两个不同区域的工作负载。这样可以跨区域提供冗余,也就是说,工作负载在运行作业时可以访问任一区域。它还为您的服务提供了故障转移机制。例如,如果其中一个区域性端点发生故障,您的工作负载会自动路由到另一个区域。这有助于防止工作负载和作业中断。
借助自定义区域配置,您还可以控制元数据的存储位置以及 Hive Metastore 端点的公开位置。这有助于提高处理工作负载时的性能。
注意事项
以下注意事项适用于使用自定义区域配置配置的 Dataproc Metastore 服务:
- 地区/配对限制:部分地区和组合不受支持。
- 只读限制:只读区域无法接受写入操作。如果选择了只读区域,而读写区域无法访问,则写入操作将无法处理。
- 配置不可变性:区域配置一经设置便无法更改。
- 仅限美国堆栈:自定义双区域仅支持
US
堆栈,且仅限于美国境内。
创建自定义区域服务
如需设置自定义区域,请在创建服务时选择两个相邻的区域。此组合可以是两个读写区域,也可以是一个读写区域和一个只读区域。
在 Google Cloud 控制台中,前往 Dataproc Metastore 页面。
在导航栏中,点击 +Create(创建)。
系统随即会打开创建 Metastore 服务对话框。
选择 Dataproc Metastore 2。
在价格和容量部分中,选择企业 Plus 版 - 双区域。
在服务名称字段中,为服务输入一个唯一名称。
在数据位置中,选择美国(大陆)。
系统随即会显示自定义区域部分。
在自定义区域下,选择一个读写区域和一个只读区域。
对于其余服务配置选项,请使用提供的默认值。
如需创建并启动该服务,请点击提交。
您的新 Metastore 服务会显示在 Dataproc Metastore 页面上。在服务准备就绪之前,状态会显示为正在创建。准备就绪后,状态会变为有效。预配服务可能需要几分钟时间。
如需创建具有自定义区域的 Dataproc Metastore 服务,请运行以下 gcloud CLI gcloud beta metastore services create
命令。
gcloud beta metastore services createSERVICE \ --read-write-regions
替换以下内容: