本页面介绍了如何为 Dataproc Metastore 创建元数据联合服务。借助联邦服务,您可以通过单个 gRPC 端点访问存储在多个来源中的元数据。
如需详细了解联合的工作原理及其限制,请参阅关于元数据联合。
准备工作
- 启用 Dataproc Metastore。
- 创建使用 gRPC 端点的 Dataproc Metastore 服务。
- 可选:如果您使用 BigQuery 源进行联邦查询,请完成以下操作:
- 在包含 BigQuery 源的项目中启用 BigQuery API。
- 启用 Resource Manager API。
- 可选:如果您使用 Dataplex Universal Catalog 数据湖作为联合的来源(预览版),请完成以下步骤:
- 在包含 Dataplex Universal Catalog 数据湖作为来源的项目中启用 Dataplex Universal Catalog API。
所需的角色
如需获得创建联邦服务并关联 Dataproc 集群所需的权限(遵循最小权限原则),请让管理员向您授予以下 IAM 角色:
-
如需访问联合身份验证服务,请向用户账号或服务账号授予联合身份验证访问者 (
roles/metastore.federationAccessor
) 角色 联合身份验证访问者 (roles/metastore.federationAccessor
) 用户账号或服务账号 -
如需授予对所有 Dataproc Metastore 资源的完全控制权限:
用户账号或服务账号上的 Dataproc Metastore 编辑者 (
roles/metastore.editor
) -
如需在配置了联邦服务的 Dataproc Metastore 上完成元数据操作:
元数据存储区所有者 (
metastore.metadataEditor
) 在用户账号或服务账号上 -
创建 Dataproc 集群:针对 Dataproc 虚拟机服务账号的 Dataproc worker (
roles/dataproc.worker
) - (可选)如需访问 BigQuery 数据集: 请在用户账号或服务账号上使用适用于您的使用情形的相应 BigQuery 预定义角色
- (可选)如需访问 Dataplex Universal Catalog 数据湖(预览版): 在用户账号或服务账号上使用适用于您的使用情形的相应 Dataplex Universal Catalog 预定义角色
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
这些预定义角色包含创建联邦服务和附加 Dataproc 集群所需的权限,并遵循最小权限原则。如需查看所需的确切权限,请展开所需权限部分:
所需权限
如需创建联邦服务并附加 Dataproc 集群,同时遵循最小权限原则,您需要具备以下权限:
-
如需创建 Dataproc Metastore,请确保用户账号或服务账号拥有
metastore.services.create
权限 -
如需列出、获取、创建、更新和删除联合身份验证服务,请向用户账号或服务账号授予以下权限:
metastore.federations.create, metastore.federations.update, metastore.federations.delete, metastore.federations.get metastore.federations.list
-
如需在 Dataproc Metastore 上完成元数据操作,请执行以下操作:
metastore.services.get, metastore.services.use, metastore.databases.create, metastore.databases.update, metastore.databases.deletemetastore.databases.get,metastore.databases.list, metastore.databases.getIamPolicy, metastore.tables.create, metastore.tables.update, metastore.tables.delete, metastore.tables.get, metastore.tables.list, metastore.tables.getIamPolicy
在用户账号或服务账号上 -
(可选)如需向联邦添加多区域服务,请执行以下操作:
metastore.services.get
在 Dataproc Metastore 账号上 -
(可选)如需访问 BigQuery 数据集:
For more information, see BigQuery permissions
在用户账号或服务账号上 -
(可选)如需访问 Dataplex Universal Catalog Lakes(预览版):
For more information, see Dataplex Universal Catalog permissions
用户账号或服务账号
创建联邦服务
以下说明介绍了如何创建联合服务并将其附加到来源。完成这些步骤后,您可以将联邦服务关联到 Dataproc 集群。
如需详细了解联合来源及其限制,请参阅元数据来源。
控制台
在 Google Cloud 控制台中,打开 Dataproc Metastore 页面:
在 Dataproc 导航菜单中,点击联合。
系统会打开联合元存储服务页面。
在联合元存储区菜单栏中,点击创建。
系统会打开创建联邦服务页面。
在联合名称字段中,为服务输入一个唯一名称。
如需了解详情,请参阅资源命名惯例。
选择数据位置。
请确保在 Dataproc Metastore 源所在的相同区域中创建联邦服务。
选择 Hive 版本。
如需为您的联合服务添加来源,请点击添加来源。
您可以添加一个或多个来源。您在此列表中添加的第一个来源会自动设置为主要元存储区。您可以在创建来源后更新来源排序。
在来源类型中,选择您的联合来源。
您可以选择 Dataproc Metastore 实例、包含一个或多个 BigQuery 数据集的项目,或 Dataplex Universal Catalog 数据湖(预览版)。
在来源字段中,输入以下信息:
对于 Dataproc Metastore 服务。
在所选项目字段中,点击浏览,然后选择包含您要用作来源的 Dataproc Metastore 的项目。
确保您的 Dataproc Metastore 源使用的是与联邦服务兼容的 Hive 版本。主 Metastore 必须使用大于或等于联邦服务的 Hive 版本。
在 Metastore 服务下拉菜单中,选择要用作来源的 Dataproc Metastore。
(可选)选中显示我所在区域之外的 Metastore 服务复选框。此命令会列出其他区域(包括多区域)的 Dataproc Metastore 服务。
如需在多区域 Dataproc Metastore 服务上启用联邦,请从此列表中选择一个多区域 Dataproc Metastore 服务。
适用于 BigQuery。 在所选项目字段中,点击浏览,然后选择包含 BigQuery 数据集的项目的项目 ID。
对于 Dataplex Universal Catalog(预览版)。 在所选项目字段中,点击浏览,然后选择包含 Dataplex Universal Catalog 数据湖的项目的项目 ID。
点击完成。
如需创建并启动服务,请点击提交。
现在,您可以将联邦服务附加到 Dataproc 集群。
gcloud CLI
如需创建具有 Dataproc Metastore 的联邦,请运行以下命令。
gcloud metastore federations create FEDERATION \ --location LOCATION \ --backends RANK=BACKEND_METASTORE \ --hive-metastore-version HIVE_VERSION
替换以下内容:
FEDERATION
:Dataproc Metastore 联合服务的名称。LOCATION
:要在其中创建联邦的 Google Cloud 区域。RANK
:用于解决数据库名称冲突的每个后端元存储区的排名编号。联合服务会先查询排名较低的号码。例如,系统会先查询等级为1
的后端元存储区,然后再查询等级为2
的元存储区。此值必须是整数。例如--backends 1=first_backend_metastore, 2=second_backend_metastore
。BACKEND_METASTORE
:每个后端 Metastore 的相对资源,格式如下:METASTORE_TYPE:METASTORE_NAME
。对于 Dataproc Metastore 服务,请使用dpms:SERVICE_ID
。SERVICE_ID
位于以下位置:projects/<project>/locations/<location>/services/<service-id>
。HIVE_VERSION
:Hive Metastore 的版本(3.1.2 或 2.3.6)。
更新联邦服务
以下说明介绍了如何更新联邦服务。您可以完成以下任务:
- 向联合服务添加来源。
- 从联邦服务中移除来源。
- 更改联合服务中包含的来源的来源顺序。
永久删除联合服务。删除服务后,其所有资源都会被释放。
控制台
https://cloud.google.com/dataproc-metastore/docs/create-federation
在 Google Cloud 控制台中,打开 Dataproc Metastore 页面:
在 Dataproc 导航菜单中,点击联合。
系统会打开联合元存储服务页面。
在联合 Metastore 服务页面上,点击要更新的服务名称。
服务详细信息页面会打开。
在菜单栏中,点击修改。
系统随即会打开修改服务页面。
选择要更新的值。
如需更新服务,请点击提交。
gcloud CLI
如需使用 Dataproc Metastore 更新联邦,请运行以下命令。
gcloud metastore federations update FEDERATATON \ --location=LOCATION \ --backends RANK1=BACKEND_METASTORE1,RANK2=BACKEND_METASTORE2
FEDERATION
:Dataproc Metastore 联合服务的名称。LOCATION
:用于创建联邦的 Google Cloud 区域。RANK
:用于解决数据库名称冲突的每个后端元存储区的排名编号。联合服务会先查询排名较低的号码。例如,系统会先查询等级为1
的后端元存储区,然后再查询等级为2
的元存储区。此值必须是整数。例如--backends 2=first_backend_metastore, 2=second_backend_metastore
。BACKEND_METASTORE
:每个后端 Metastore 的相对资源,格式如下:METASTORE_TYPE:METASTORE_NAME
。对于 Dataproc Metastore 服务,请使用dpms:SERVICE_ID
。SERVICE_ID
位于以下位置:projects/<project>/locations/<location>/services/<service-id>
。HIVE_VERSION
:Hive Metastore 的版本(3.1.2 或 2.3.6)。
将 Dataproc 集群关联到联邦服务
以下说明展示了如何创建 Dataproc 集群并将联合服务端点作为其 Metastore 进行连接。
在开始执行这些说明之前,请完成准备工作中列出的所有步骤,并创建联合服务。
gcloud CLI
如需创建 Dataproc 集群并附加联邦端点,请运行以下 gcloud Dataproc clusters create
命令。
gcloud dataproc clusters create CLUSTER_NAME \ --region=LOCATION \ --project=PROJECT_ID \ --scopes=https://www.googleapis.com/auth/cloud-platform \ --image-version=IMAGE_VERSION \ --service-account=SERVICE_ACCOUNT \ --optional-components=DOCKER \ --initialization-actions=gs://metastore-init-actions/metastore-grpc-proxy/metastore-grpc-proxy.sh \ --metadata="proxy-uri=FEDERATION_URI,hive-version=FEDERATION_VERSION" \ --properties="hive:hive.metastore.uris=thrift://localhost:9083,hive:hive.metastore.warehouse.dir=WAREHOUSE_DIR"
替换以下内容:
CLUSTER_NAME
:新 Dataproc 集群的名称。PROJECT_ID
:您要在其中创建 Dataproc 集群的项目的 Google Cloud 项目 ID。LOCATION
:Dataproc 集群所在的区域。IMAGE_VERSION
:您要使用的 Dataproc 映像版本。请确保您在此命令中使用的 Dataproc 映像与您的联邦服务所用的 Hive 版本兼容。如需了解详情,请参阅 Dataproc 映像版本列表。
SERVICE_ACCOUNT
可选:您用于创建 Dataproc 集群的服务账号。如果未指定,集群会使用您的默认 Compute Engine 服务账号。FEDERATION_URI
:您的联合服务的端点 URI。FEDERATION_VERSION
:您的联合服务使用的 Hive 版本。WAREHOUSE_DIR
:主 Dataproc Metastore 的仓库目录。