本文說明如何管理一致性群組。一致性群組是資源政策,可讓相同地區或區域中的多個磁碟保持一致的複製狀態。
如要進一步瞭解一致性群組,請參閱「關於非同步複製」。
限制
- 單一租戶節點中的磁碟不支援一致性群組。
- 一致性群組最多可有 128 個磁碟。
- 一致性群組中的所有磁碟都必須與一致性群組資源政策位於同一個專案。
- 一致性群組中的所有磁碟都必須位於同一個可用區 (適用於區域磁碟),或位於同一對可用區 (適用於區域磁碟)。
- 一致性群組可以包含主要磁碟或次要磁碟,但不能同時包含兩者。
- 磁碟複製期間,您無法在一致性群組中新增或移除主要磁碟。如要將主要磁碟新增至一致性群組或從中移除,請先停止複製。您可以隨時在一致性群組中新增或移除次要磁碟。
- 您最多可以將 16 個磁碟 (來自不同一致性群組,或不屬於任何一致性群組) 連接到 VM。如果磁碟位於同一個一致性群組,則會計為一個磁碟,因此不會超過 16 個磁碟的限制。
事前準備
-
如果尚未設定驗證,請先完成設定。
「驗證」是指驗證身分的程序,確認您有權存取 Google Cloud 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列其中一個選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
前往 Google Cloud 控制台的「Asynchronous replication」(非同步複製) 頁面。
按一下「一致性群組」分頁標籤。
按一下「建立一致性群組」。
在「Name」(名稱) 欄位中,輸入一致性群組的名稱。
在「Region」(地區) 欄位中,選取磁碟所在的地區。如要將主要磁碟新增至一致性群組,請選取主要區域。如要將次要磁碟新增至一致性群組,請選取次要區域。
點選「建立」。
CONSISTENCY_GROUP_NAME
:一致性群組的名稱。REGION
:一致性群組的區域。如要將主要磁碟新增至一致性群組,請使用主要區域。如要將次要磁碟新增至一致性群組,請使用次要區域。PROJECT
:包含一致性群組的專案。REGION
:一致性群組的區域。如要將主要磁碟新增至一致性群組,請使用與主要磁碟相同的區域。如要將次要磁碟新增至一致性群組,請使用與次要磁碟相同的區域。CONSISTENCY_GROUP_NAME
:一致性群組的名稱。前往 Google Cloud 控制台的「Asynchronous replication」(非同步複製) 頁面。
按一下「一致性群組」分頁標籤。
按一下要查看磁碟的一致性群組名稱。系統隨即會開啟「管理一致性群組」頁面。
查看「一致性群組成員」部分,瞭解一致性群組中包含的所有磁碟。
LOCATION_FLAG
:一致性群組中磁碟的位置標記。如果一致性群組中的磁碟是地區磁碟,請使用--region
。如果一致性群組中的磁碟是區域磁碟,請使用--zone
。LOCATION
:一致性群組中磁碟所在的區域或可用區。如果是區域磁碟,請使用區域。如果是區域磁碟,請使用區域。CONSISTENCY_GROUP_NAME
:一致性群組的名稱。使用
disks.get
方法查看一致性群組中的區域磁碟:GET https://compute.googleapis.com/compute/v1/projects/PROJECT/zones/ZONE/disks?filter=resourcePolicies%3DCONSISTENCY_GROUP_NAME
使用
regionDisks.get
方法查看一致性群組中的區域磁碟:GET https://compute.googleapis.com/compute/v1/projects/PROJECT/regions/REGION/disks?filter=resourcePolicies%3DCONSISTENCY_GROUP_NAME
PROJECT
:包含一致性群組的專案ZONE
:一致性群組中磁碟的可用區REGION
:一致性群組中磁碟的區域CONSISTENCY_GROUP_NAME
:一致性群組的名稱前往 Google Cloud 控制台的「Asynchronous replication」(非同步複製) 頁面。
按一下「一致性群組」分頁標籤。
按一下要新增磁碟的一致性群組名稱。 系統隨即會開啟「管理一致性群組」頁面。
按一下「指派磁碟」。「Assign disks」(指派磁碟) 頁面隨即開啟。
選取要加入一致性群組的磁碟。
按一下「指派磁碟」。出現提示時,按一下「新增」。
DISK_NAME
:要新增至一致性群組的磁碟名稱。LOCATION_FLAG
:磁碟的位置標記。如果是區域性磁碟,請使用--region
。如果是區域磁碟,請使用--zone
。LOCATION
:磁碟的區域或可用區。 如果是區域磁碟,請使用區域。如果是區域磁碟,請使用區域。CONSISTENCY_GROUP
:一致性群組的網址。例如:projects/PROJECT/regions/REGION/resourcePolicies/CONSISTENCY_GROUP_NAME
。使用
disks.addResourcePolicies
方法將區域磁碟新增至一致性群組:POST https://compute.googleapis.com/compute/v1/projects/PROJECT/zones/LOCATION/disks/DISK_NAME/addResourcePolicies { "resourcePolicies": "CONSISTENCY_GROUP" }
使用
regionDisks.addResourcePolicies
方法將地區磁碟新增至一致性群組:POST https://compute.googleapis.com/compute/v1/projects/PROJECT/regions/LOCATION/disks/DISK_NAME/addResourcePolicies { "resourcePolicies": "CONSISTENCY_GROUP" }
PROJECT
:包含磁碟的專案。LOCATION
:磁碟的可用區或區域。如果是區域磁碟,請使用可用區。如果是區域磁碟,請使用區域。DISK_NAME
:要新增至一致性群組的磁碟名稱。CONSISTENCY_GROUP
:一致性群組的網址。例如:projects/PROJECT/regions/REGION/resourcePolicies/CONSISTENCY_GROUP_NAME
。如果是地區磁碟,請指定地區而非可用區。
如要瞭解如何套用或移除 Terraform 設定,請參閱「基本 Terraform 指令」。
前往 Google Cloud 控制台的「Asynchronous replication」(非同步複製) 頁面。
按一下「一致性群組」分頁標籤。
按一下要新增磁碟的一致性群組名稱。 系統隨即會開啟「管理一致性群組」頁面。
選取要從一致性群組中移除的磁碟。
按一下「移除磁碟」。系統顯示提示時,按一下「移除」。
DISK_NAME
:要從一致性群組中移除的磁碟名稱。LOCATION_FLAG
:磁碟的位置標記。如果是區域性磁碟,請使用--region
。如果是區域磁碟,請使用--zone
。LOCATION
:磁碟的區域或可用區。 如果是區域磁碟,請使用區域。如果是區域磁碟,請使用區域。CONSISTENCY_GROUP
:一致性群組的網址。例如:projects/PROJECT/regions/REGION/resourcePolicies/CONSISTENCY_GROUP_NAME
。從一致性群組中移除區域磁碟:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT/zones/LOCATION/disks/DISK_NAME/removeResourcePolicies { "resourcePolicies": "CONSISTENCY_GROUP" }
從一致性群組中移除區域磁碟:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT/regions/LOCATION/disks/DISK_NAME/removeResourcePolicies { "resourcePolicies": "CONSISTENCY_GROUP" }
PROJECT
:包含磁碟的專案。LOCATION
:磁碟的可用區或區域。如果是區域磁碟,請使用可用區。如果是區域磁碟,請使用區域。DISK_NAME
:要從一致性群組中移除的磁碟名稱。CONSISTENCY_GROUP
:一致性群組的網址。例如:projects/PROJECT/regions/REGION/resourcePolicies/CONSISTENCY_GROUP_NAME
。前往 Google Cloud 控制台的「Asynchronous replication」(非同步複製) 頁面。
按一下「一致性群組」分頁標籤。
選取要刪除的一致性群組。
按一下 [Delete] (刪除),「刪除一致性群組」視窗隨即開啟。
點選「刪除」。
CONSISTENCY_GROUP
:一致性群組的名稱REGION
:一致性群組的區域PROJECT
:包含一致性群組的專案REGION
:一致性群組的區域CONSISTENCY_GROUP
:一致性群組的名稱- 瞭解如何管理使用非同步複製的磁碟。
- 瞭解如何容錯移轉及容錯回復。
- 瞭解如何監控非同步複製作業的效能。
Terraform
如要在本機開發環境中使用本頁的 Terraform 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
詳情請參閱 Set up authentication for a local development environment。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
詳情請參閱 Google Cloud 驗證說明文件中的「Authenticate for using REST」。
建立一致性群組
如要讓多個磁碟的複製作業保持一致,請在與主要磁碟相同的區域中建立一致性群組。如要對齊磁碟副本,請在與次要磁碟相同的區域中建立一致性群組。
使用 Google Cloud 控制台、Google Cloud CLI、REST 或 Terraform 建立一致性群組。
主控台
請按照下列步驟建立一致性群組:
gcloud
使用
gcloud compute resource-policies create disk-consistency-group
指令建立一致性群組:gcloud compute resource-policies create disk-consistency-group CONSISTENCY_GROUP_NAME \ --region=REGION
更改下列內容:
Go
Java
Node.js
Python
REST
使用
resourcePolicies.insert
方法建立一致性群組:POST https://compute.googleapis.com/compute/v1/projects/PROJECT/regions/REGION/resourcePolicies { "name": "CONSISTENCY_GROUP_NAME", "diskConsistencyGroupPolicy": { } }
更改下列內容:
Terraform
如要建立一致性群組,請使用
compute_resource_policy
資源。如要瞭解如何套用或移除 Terraform 設定,請參閱「基本 Terraform 指令」。
查看一致性群組中的磁碟
使用 Google Cloud 控制台、Google Cloud CLI 或 REST,查看一致性群組中的磁碟。
主控台
如要查看一致性群組中包含的磁碟,請執行下列操作:
gcloud
使用
gcloud compute disks list
指令,查看一致性群組中包含的磁碟:gcloud compute disks list \ --LOCATION_FLAG=LOCATION \ --filter=resourcePolicies=CONSISTENCY_GROUP_NAME
更改下列內容:
Go
Java
列出一致性群組中的區域磁碟
列出一致性群組中的區域磁碟
Node.js
Python
REST
使用查詢篩選器,透過下列任一方法查看一致性群組中的磁碟:
更改下列內容:
將磁碟新增至一致性群組
如要將主要磁碟新增至一致性群組,必須先將磁碟新增至一致性群組,才能開始複製。您可以隨時將次要磁碟加入一致性群組。一致性群組中的所有磁碟都必須位於同一個可用區 (適用於區域磁碟),或位於同一組可用區 (適用於區域磁碟)。
使用 Google Cloud 控制台、Google Cloud CLI、REST 或 Terraform,將磁碟新增至一致性群組。
主控台
如要將磁碟新增至一致性群組,請執行下列操作:
gcloud
使用
gcloud compute disks add-resource-policies
指令將磁碟新增至一致性群組:gcloud compute disks add-resource-policies DISK_NAME \ --LOCATION_FLAG=LOCATION \ --resource-policies=CONSISTENCY_GROUP
更改下列內容:
Go
Java
Node.js
Python
REST
使用下列其中一種方法,將磁碟新增至一致性群組:
更改下列內容:
Terraform
如要將磁碟加入一致性群組,請使用
compute_disk_resource_policy_attachment
資源。從一致性群組中移除磁碟
如要從一致性群組中移除磁碟,必須先停止磁碟的複製作業。
使用 Google Cloud 控制台、Google Cloud CLI 或 REST,從一致性群組中移除磁碟。
主控台
如要從一致性群組中移除主要磁碟,請按照下列步驟操作:
gcloud
使用
gcloud compute disks remove-resource-policies
指令,從一致性群組中移除磁碟:gcloud compute disks remove-resource-policies DISK_NAME \ --LOCATION_FLAG=LOCATION \ --resource-policies=CONSISTENCY_GROUP
更改下列內容:
Go
Java
Node.js
Python
REST
如要從一致性群組中移除磁碟,請使用區域磁碟的
disks.removeResourcePolicies
方法,或是地區磁碟的regionDisks.removeResourcePolicies
方法。更改下列內容:
刪除一致性群組
使用 Google Cloud 控制台、Google Cloud CLI 或 REST 刪除一致性群組。
主控台
如要刪除一致性,請按照下列步驟操作:
gcloud
使用
gcloud compute resource-policies delete
指令刪除資源政策:gcloud compute resource-policies delete CONSISTENCY_GROUP \ --region=REGION
更改下列內容:
Go
Java
Node.js
Python
REST
使用
resourcePolicies.delete
方法刪除一致性:DELETE https://compute.googleapis.com/compute/v1/projects/PROJECT/regions/REGION/resourcePolicies/CONSISTENCY_GROUP_NAME
更改下列內容:
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-11 (世界標準時間)。
-