本頁說明如何設定多區域 Dataproc Metastore 服務。如要進一步瞭解多區域 Dataproc Metastore 服務的運作方式,請參閱 Dataproc Metastore 區域。
事前準備
- 在專案中啟用 Dataproc Metastore。
- 瞭解專案適用的網路需求。
- 瞭解 Dataproc Metastore 區域,然後選擇合適的區域。
必要的角色
如要取得建立多區域 Dataproc Metastore 服務所需的權限,請要求管理員根據最低權限原則,授予您專案的下列 IAM 角色:
-
授予 Dataproc Metastore 資源的完整控制權 (
roles/metastore.editor
) -
授予所有 Dataproc Metastore 資源的完整存取權,包括身分與存取權管理政策管理權 (
roles/metastore.admin
)
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
這個預先定義的角色包含 metastore.services.create
權限,這是建立多區域 Dataproc Metastore 服務的必要權限。
關於多區域 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 多區域位置建立構件 bucket。舉例來說,
Nam7
值區是在US
多地區位置建立的。
建立多區域 Dataproc Metastore 服務
請選擇下列任一分頁,瞭解如何使用 Thrift 或 gRPC 端點通訊協定,透過 Dataproc Metastore 服務 2 建立多區域服務。
gRPC
建立使用 gRPC 端點通訊協定的多區域服務時,不必設定任何特定網路設定。gRPC 通訊協定會為您處理網路路徑。
控制台
在 Google Cloud 控制台中,前往「Dataproc Metastore」頁面。
在導覽列中,按一下「+ 建立」。
「建立 Metastore 服務」對話方塊隨即開啟。
選取「Dataproc Metastore 2」。
在「定價和容量」部分,選取「Enterprise Plus - 雙區域」
在「Endpoint protocol」(端點通訊協定) 中選取「gRPC」。
如要建立並啟動服務,請按一下「Submit」(提交)。
新的 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
更改下列內容:
Thrift
建立使用 Thrift 端點通訊協定的多區域服務時,您必須設定適當的子網路設定。在這種情況下,您必須為使用的每個 VPC 網路,提供每個區域至少一個子網路。
舉例來說,如要建立 nam7
多區域,您必須提供 us-central1
和 us-east4
區域。
控制台
在 Google Cloud 控制台中,前往「Dataproc Metastore」頁面。
在導覽列中,按一下「+ 建立」。
「建立 Metastore 服務」對話方塊隨即開啟。
選取「Dataproc Metastore 2」。
在「價格和容量」部分,選取「Enterprise Plus - 雙區域」。
詳情請參閱定價方案和資源調度設定。
在「Service name」(服務名稱) 欄位中,輸入服務的專屬名稱。
如要瞭解命名慣例,請參閱資源命名慣例。
在「Endpoint protocol」(端點通訊協定) 部分,選取「Thrift」。
在「Network Config」(網路設定) 中,提供構成所選多區域設定的子網路。
其餘服務設定選項請使用系統提供的預設值。
如要建立並啟動服務,請按一下「Submit」(提交)。
新的 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
更改下列內容:
- :Dataproc Metastore 服務的名稱。
SERVICE
MULTI_REGION
:您要在其中建立 Dataproc Metastore 服務的多區域。PROJECT_ID
:您要在其中建立 Dataproc Metastore 服務的 Google Cloud 專案 ID。SUBNET1
、SUBNET2
:形成多區域設定的子網路清單。您可以使用子網路的 ID、完整網址或相對名稱。最多可指定六個子網路。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
指定值。
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 服務的專案 ID。 Google CloudLOCATION
:Dataproc Metastore 服務所在的 Google Cloud 區域。SUBNET1
、SUBNET2
:構成多區域設定的子網路清單。您可以使用子網路的 ID、完整網址或相對名稱。最多可指定五個子網路。SCALING_FACTOR
:要用於服務的縮放比例係數。
將 Dataproc Metastore 連線至 Dataproc 叢集
選擇下列任一分頁,瞭解如何從 Dataproc 叢集連線至多區域 Dataproc Metastore 服務。
gRPC
如要連線 Dataproc 叢集,請選擇與您使用的 Dataproc Metastore 版本相符的分頁。
Dataproc Metastore 3.1.2
為 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。
如要建立叢集,請執行下列
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
為 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 網路中的任何子網路。
為 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
映像檔版本。
- 如果是 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
Thrift
方法 1:編輯 hive-site.xml 檔案
- 找出 Dataproc Metastore 服務的端點 URI 和資料倉儲目錄。您可以選擇公開的任一端點。
- 前往 Google Cloud 控制台的「VM Instances」(VM 執行個體) 頁面。
在虛擬機器執行個體清單中,找到 Dataproc 主要節點 (
.*-m
),然後在該列中按一下「SSH」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 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
映像檔版本。
- 如果是 Hive Metastore 2.0 版,請使用映像檔版本
ENDPOINT
:Dataproc Metastore 使用的 Thrift 端點。WAREHOUSE_DIR
:Dataproc Metastore 的倉庫目錄。
自訂區域設定
您可以設定 Dataproc Metastore 服務,使用自訂區域設定。
自訂區域設定可讓服務從兩個不同的區域執行工作負載。這樣一來,工作負載在執行工作時,就能存取任一區域,達到跨區域備援的效果。並為服務提供容錯移轉機制。舉例來說,如果其中一個區域端點發生故障,系統會自動將工作負載轉送至其他區域。這有助於防止工作負載和作業中斷。
自訂區域設定也能控管中繼資料的儲存位置,以及 Hive Metastore 端點的公開位置。這有助於提升處理工作負載時的效能。
注意事項
如果 Dataproc Metastore 服務設定了自訂區域設定,請注意下列事項:
- 區域/配對限制:並非所有區域和組合都允許使用。
- 唯讀限制:唯讀區域無法接受寫入作業。 如果選擇唯讀區域,且無法連線至讀寫區域,寫入作業就會處理失敗。
- 設定不可變更:區域設定一經設定就無法變更。
- 僅限美國堆疊:自訂雙重區域僅支援
US
堆疊,且僅限於美國境內。
建立自訂區域服務
如要設定自訂區域,請在建立服務時選擇兩個相鄰區域。這兩個區域可以是讀寫區域,也可以是讀寫區域和唯讀區域。
主控台
在 Google Cloud 控制台中,前往「Dataproc Metastore」頁面。
在導覽列中,按一下「+ 建立」。
「建立 Metastore 服務」對話方塊隨即開啟。
選取「Dataproc Metastore 2」。
在「價格和容量」部分,選取「Enterprise Plus - 雙區域」。
在「Service name」(服務名稱) 欄位中,輸入服務的專屬名稱。
選取「美國 (洲)」做為「資料位置」。
畫面上會顯示「自訂區域」部分。
在「自訂區域」下方,選取「讀寫」區域和「唯讀」區域。
其餘服務設定選項請使用系統提供的預設值。
如要建立並啟動服務,請按一下「Submit」(提交)。
新的 Metastore 服務會顯示在「Dataproc Metastore」頁面。服務準備就緒前,狀態會顯示為「建立中」。 準備就緒後,狀態會變更為「有效」。 佈建服務可能需要幾分鐘的時間。
gcloud
如要建立具有自訂區域的 Dataproc Metastore 服務,請執行下列 gcloud CLI gcloud beta metastore services create
指令。
gcloud beta metastore services create SERVICE \ --read-write-regions
更改下列內容: