建立中繼資料聯盟服務

本頁說明如何為 Dataproc Metastore 建立中繼資料聯盟服務。透過聯盟服務,您可以從單一 gRPC 端點存取多個來源中儲存的中繼資料。

如要進一步瞭解聯盟的運作方式和限制,請參閱「關於中繼資料聯盟」。

事前準備

必要的角色

如要取得建立同盟服務並附加 Managed Service for Apache Spark 叢集所需的權限,請遵循最小權限原則,要求管理員授予您下列 IAM 角色:

如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

這些預先定義的角色具備建立同盟服務,以及附加 Managed Service for Apache Spark 叢集所需的權限,並遵循最小權限原則。如要查看確切的必要權限,請展開「Required permissions」(必要權限) 部分:

所需權限

根據最小權限原則,您必須具備下列權限,才能建立同盟服務並附加 Managed Service for Apache Spark 叢集:

  • 如要建立 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 在使用者帳戶或服務帳戶上
  • (選用) 如要存取 BigQuery 資料集: For more information, see BigQuery permissions 在使用者帳戶或服務帳戶中
  • (選用) 如要存取 Knowledge Catalog Lakes (預覽版): For more information, see Knowledge Catalog permissions 在使用者帳戶或服務帳戶中

您或許還可透過自訂角色或其他預先定義的角色取得這些權限。

如要進一步瞭解特定 Dataproc Metastore 角色和權限,請參閱「使用 Identity and Access Management 管理 Dataproc Metastore 存取權」。

建立聯盟服務

下列操作說明會引導您建立同盟服務,並將其附加至來源。完成這些步驟後,您就可以將同盟服務連接至 Managed Service for Apache Spark 叢集。

如要進一步瞭解聯盟來源及其限制,請參閱中繼資料來源

控制台

  1. 在 Google Cloud 控制台中,開啟「Dataproc Metastore」頁面:

    開啟 Dataproc Metastore

  2. 在 Managed Service for Apache Spark 導覽選單中,按一下「Federation」(同盟)

    「Federated」中繼存放區服務頁面隨即開啟。

  3. 在「Federated」 metastore 選單列中,按一下「Create」

    「建立同盟服務」頁面隨即開啟。

  4. 在「Federation name」(聯盟名稱) 欄位中,輸入服務的專屬名稱。

    詳情請參閱資源命名慣例

  5. 選取「資料位置」

    請務必在 Dataproc Metastore 來源的相同區域中建立同盟服務。

  6. 選取 Hive 版本

  7. 如要為同盟服務新增來源,請按一下「新增來源」

    你可以新增一或多個來源。您在這個清單中新增的第一個來源,會自動設為主要中繼資料存放區。建立後仍可更新來源排序。

    1. 在「來源類型」部分,選取您的聯盟來源。

      您可以選擇 Dataproc Metastore 執行個體、包含一或多個 BigQuery 資料集的專案,或是 Knowledge Catalog lake (預先發布版)

    2. 在「來源」欄位中,輸入下列資訊:

      • 適用於 Dataproc Metastore 服務

        1. 在「Selected project」(所選專案) 欄位中,按一下「Browse」(瀏覽),然後選取包含要做為來源的 Dataproc Metastore 的專案。

          請確認 Dataproc Metastore 來源使用的 Hive 版本與聯盟服務相容。主要中繼儲存庫使用的 Hive 版本必須大於或等於同盟服務。

        2. 在「Metastore service」(中繼資料儲存庫服務) 下拉式選單中,選取要做為來源的 Dataproc Metastore。

        3. (選用) 選取「顯示我的區域以外的 Metastore 服務」核取方塊。列出其他區域的 Dataproc Metastore 服務。

      • 適用於 BigQuery。 在「所選專案」欄位中,按一下「瀏覽」,然後選取包含 BigQuery 資料集的專案 ID。

      • 適用於 Knowledge Catalog (搶先版)。在「Selected project」(所選專案) 欄位中,按一下「Browse」(瀏覽),然後選取包含 Knowledge Catalog Lake 的專案 ID。

    3. 按一下 [完成]

  8. 如要建立並啟動服務,請按一下「Submit」(提交)

    您現在可以將同盟服務附加至 Managed Service for Apache Spark 叢集

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_TYPE:METASTORE_NAME。如果是 Dataproc Metastore 服務,請使用 dpms:SERVICE_IDSERVICE_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

  1. 在 Google Cloud 控制台中,開啟「Dataproc Metastore」頁面:

    開啟 Dataproc Metastore

  2. 在 Managed Service for Apache Spark 導覽選單中,按一下「Federation」(同盟)

    「Federated」中繼存放區服務頁面隨即開啟。

  3. 在「Federated」中繼存放區服務頁面,按一下要更新的服務名稱。

    「服務詳細資料」頁面隨即開啟。

  4. 按一下選單列中的「編輯」

    「編輯服務」頁面隨即開啟。

  5. 選擇要更新的值。

  6. 如要更新服務,請按一下「提交」

gcloud CLI

如要使用 Dataproc Metastore 更新聯盟,請執行下列指令。

gcloud metastore federations update FEDERATION \
  --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_TYPE:METASTORE_NAME。如果是 Dataproc Metastore 服務,請使用 dpms:SERVICE_IDSERVICE_ID位於以下位置:projects/<project>/locations/<location>/services/<service-id>
  • HIVE_VERSION:Hive Metastore 版本 (3.1.2 或 2.3.6)。

將 Managed Service for Apache Spark 叢集附加至同盟服務

下列操作說明將示範如何建立 Managed Service for Apache Spark 叢集,並將同盟服務端點附加為其 metastore。

開始執行這些操作說明前,請先完成「事前準備」中列出的所有步驟,並建立同盟服務

gcloud CLI

如要建立 Managed Service for Apache Spark 叢集並附加同盟端點,請執行下列 gcloud Managed Service for Apache Spark 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:新 Managed Service for Apache Spark 叢集的名稱。
  • PROJECT_ID:您要在其中建立 Managed Service for Apache Spark 叢集的專案的專案 ID。 Google Cloud
  • LOCATION:Managed Service for Apache Spark 叢集的區域。
  • IMAGE_VERSION:要使用的 Managed Service for Apache Spark 映像檔版本。

    請確認您在此指令中使用的 Managed Service for Apache Spark 映像檔,與用於同盟服務的 Hive 版本相容。詳情請參閱「Managed Service for Apache Spark 映像檔版本清單」。

  • SERVICE_ACCOUNT (選用) 用於建立 Managed Service for Apache Spark 叢集的服務帳戶。如未指定,叢集會使用預設的 Compute Engine 服務帳戶。

  • FEDERATION_URI:同盟服務的端點 URI。

  • FEDERATION_VERSION:您的聯盟服務使用的 Hive 版本。

  • WAREHOUSE_DIR:主要 Dataproc Metastore 的資料倉儲目錄。

後續步驟