本文說明如何管理一致性群組。一致性群組是資源政策,可在相同區域或區域中,將多個磁碟的複製作業保持一致。
如要進一步瞭解一致性群組,請參閱「關於非同步複製」。
限制
- 單一用戶群節點中的磁碟不支援一致性群組。
- 一致性群組最多可包含 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.
Terraform
To use the Terraform samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- 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.
For more information, see Set up authentication for a local development environment.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the 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.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
建立一致性群組
如果您需要在多個磁碟之間對齊複製作業,請在主要磁碟所在的區域中建立一致性群組。如果您需要對齊磁碟克隆,請在次要磁碟所在的區域中建立一致性群組。
使用 Google Cloud 控制台、Google Cloud CLI、REST 或 Terraform 建立一致性群組。
主控台
如要建立一致性群組,請按照下列步驟操作:
前往 Google Cloud 控制台中的「非同步複製」頁面。
按一下「一致性群組」分頁標籤。
按一下「建立一致性群組」。
在「Name」欄位中,輸入一致性群組的名稱。
在「Region」(地區) 欄位中,選取磁碟所在的地區。如要將主要磁碟新增至一致性群組,請選取主要區域。如要將次要磁碟新增至一致性群組,請選取次要區域。
按一下 [建立]。
gcloud
使用 gcloud compute resource-policies create disk-consistency-group
指令建立一致性群組:
gcloud compute resource-policies create disk-consistency-group CONSISTENCY_GROUP_NAME \ --region=REGION
更改下列內容:
CONSISTENCY_GROUP_NAME
:一致性群組的名稱。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": { } }
更改下列內容:
PROJECT
:包含一致性群組的專案。REGION
:一致性群組的區域。如果您想將主要磁碟新增至一致性群組,請使用與主要磁碟相同的區域。如果您想將次要磁碟新增至一致性群組,請使用與次要磁碟相同的區域。CONSISTENCY_GROUP_NAME
:一致性群組的名稱。
Terraform
如要建立一致性群組,請使用 compute_resource_policy
資源。
如要瞭解如何套用或移除 Terraform 設定,請參閱「基本 Terraform 指令」。
查看一致性群組中的磁碟
使用 Google Cloud 控制台、Google Cloud CLI 或 REST,查看一致性群組中的磁碟。
主控台
如要查看一致性群組中的磁碟,請按照下列步驟操作:
前往 Google Cloud 控制台中的「非同步複製」頁面。
按一下「一致性群組」分頁標籤。
按一下要查看磁碟的一致性群組名稱。系統隨即會開啟「Manage consistency group」(管理一致性群組) 頁面。
查看「一致性群組成員」部分,瞭解一致性群組中包含的所有磁碟。
gcloud
使用 gcloud compute disks list
指令查看一致性群組中包含的磁碟:
gcloud compute disks list \ --LOCATION_FLAG=LOCATION \ --filter=resourcePolicies=CONSISTENCY_GROUP_NAME
更改下列內容:
LOCATION_FLAG
:一致性群組中磁碟的位置標記。如果一致性群組中的磁碟為地區磁碟,請使用--region
。如果一致性群組中的磁碟是區域磁碟,請使用--zone
。LOCATION
:一致性群組中磁碟的區域或可用區。如為區域性磁碟,請使用區域。如果是區域磁碟,請使用區域。CONSISTENCY_GROUP_NAME
:一致性群組的名稱。
Go
Java
列出一致性群組中的區域磁碟
列出一致性群組中的區域磁碟
Node.js
Python
REST
使用查詢篩選器搭配下列任一方法,即可查看一致性群組中的磁碟:
使用
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 控制台、Google Cloud CLI、REST 或 Terraform,將磁碟新增至一致性群組。
主控台
如要將磁碟新增至一致性群組,請按照下列步驟操作:
前往 Google Cloud 控制台中的「非同步複製」頁面。
按一下「一致性群組」分頁標籤。
按一下要新增磁碟的一致性群組名稱。系統隨即會開啟「Manage consistency group」(管理一致性群組) 頁面。
按一下「指派磁碟」。「Assign disks」(指派磁碟) 頁面隨即開啟。
選取要加入一致性群組的磁碟。
按一下「指派磁碟」。出現提示時,按一下「新增」。
gcloud
使用 gcloud compute disks add-resource-policies
指令將磁碟新增至一致性群組:
gcloud compute disks add-resource-policies DISK_NAME \ --LOCATION_FLAG=LOCATION \ --resource-policies=CONSISTENCY_GROUP
更改下列內容:
DISK_NAME
:要新增至一致性群組的磁碟名稱。LOCATION_FLAG
:磁碟的位置標記。如為地區磁碟,請使用--region
。如果是區域磁碟,請使用--zone
。LOCATION
:磁碟的區域或可用區。如為區域性磁碟,請使用區域。如果是區域磁碟,請使用區域。CONSISTENCY_GROUP
:一致性群組的網址。例如:projects/PROJECT/regions/REGION/resourcePolicies/CONSISTENCY_GROUP_NAME
。
Go
Java
Node.js
Python
REST
請使用下列任一方法,將磁碟新增至一致性群組:
使用
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
如要將磁碟新增至一致性群組,請使用 compute_disk_resource_policy_attachment
資源。
如果是地區磁碟,請改為指定地區,而非區域。
如要瞭解如何套用或移除 Terraform 設定,請參閱「基本 Terraform 指令」。
從一致性群組中移除磁碟
您必須先停止磁碟的複寫,才能從一致性群組中移除磁碟。
使用 Google Cloud 主控台、Google Cloud CLI 或 REST,從一致性群組中移除磁碟。
主控台
如要從一致性群組中移除主要磁碟,請按照下列步驟操作:
前往 Google Cloud 控制台中的「非同步複製」頁面。
按一下「一致性群組」分頁標籤。
按一下要新增磁碟的一致性群組名稱。系統隨即會開啟「Manage consistency group」(管理一致性群組) 頁面。
選取要從一致性群組中移除的磁碟。
按一下「移除磁碟」。系統顯示提示時,按一下「移除」。
gcloud
使用 gcloud compute disks remove-resource-policies
指令,從一致性群組中移除磁碟:
gcloud compute disks remove-resource-policies DISK_NAME \ --LOCATION_FLAG=LOCATION \ --resource-policies=CONSISTENCY_GROUP
更改下列內容:
DISK_NAME
:要從一致性群組中移除的磁碟名稱。LOCATION_FLAG
:磁碟的位置標記。如為地區磁碟,請使用--region
。如果是區域磁碟,請使用--zone
。LOCATION
:磁碟的區域或可用區。如為區域性磁碟,請使用區域。如果是區域磁碟,請使用區域。CONSISTENCY_GROUP
:一致性群組的網址。例如:projects/PROJECT/regions/REGION/resourcePolicies/CONSISTENCY_GROUP_NAME
。
Go
Java
Node.js
Python
REST
針對區域磁碟,請使用 disks.removeResourcePolicies
方法從一致性群組中移除磁碟;針對地區磁碟,請使用 regionDisks.removeResourcePolicies
方法。
從一致性群組中移除區域磁碟:
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 控制台、Google Cloud CLI 或 REST 刪除一致性群組。
主控台
如要刪除一致性,請按照下列步驟操作:
前往 Google Cloud 控制台中的「非同步複製」頁面。
按一下「一致性群組」分頁標籤。
選取要刪除的一致性群組。
按一下 [Delete] (刪除),「Delete consistency group」視窗隨即開啟。
點選「刪除」。
gcloud
使用 gcloud compute resource-policies delete
指令刪除資源政策:
gcloud compute resource-policies delete CONSISTENCY_GROUP \ --region=REGION
更改下列內容:
CONSISTENCY_GROUP
:一致性群組名稱REGION
:一致性群組的區域
Go
Java
Node.js
Python
REST
使用 resourcePolicies.delete
方法刪除一致性:
DELETE https://compute.googleapis.com/compute/v1/projects/PROJECT/regions/REGION/resourcePolicies/CONSISTENCY_GROUP_NAME
更改下列內容:
PROJECT
:包含一致性群組的專案REGION
:一致性群組的區域CONSISTENCY_GROUP
:一致性群組名稱
後續步驟
- 瞭解如何管理使用非同步複製功能的磁碟。
- 瞭解如何容錯移轉和復原。
- 瞭解如何監控非同步複製作業效能。