本文件說明如何在現有的 Compute Engine 執行個體中停用平穩關機功能。如要進一步瞭解正常關機,包括如何略過個別停止或刪除作業的正常關機程序,請參閱「正常關機總覽」。
如果您已在執行個體中啟用安全關機功能,則可以停用該功能來執行下列操作:
加快停止或刪除作業的速度,避免產生不必要的費用。
更新需要重新啟動的執行個體屬性。
事前準備
-
如果尚未設定,請先設定驗證機制。驗證是指驗證身分,以便存取 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.
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.
-
必要的角色
如要取得在運算執行個體中停用平穩關機功能所需的權限,請要求管理員為您授予專案的 Compute 執行個體管理員 (v1) (roles/compute.instanceAdmin.v1
) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
這個預先定義的角色包含
權限,這是在運算執行個體中停用平穩關機功能的必要條件。
compute.instances.update
on the instance
停用執行個體的安全關機功能
您可以在運算執行個體中停用安全關機功能,而無須重新啟動執行個體。不過,您無法在執行個體安全關機 (PENDING_STOP
) 的過程中停用安全關機功能。
如要在執行個體中停用正常關機功能,請選取下列任一選項:
主控台
前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面。
在「名稱」欄中,按一下執行個體名稱即可查看詳細資料。
執行個體的詳細資料頁面會隨即開啟,並選取「Details」分頁標籤。
按一下「Edit」(編輯)
。在「Management」部分,清除「Gracefully shut down the VM」核取方塊。
按一下 [儲存]。
gcloud
如要停用執行個體的正常關機功能,請使用 gcloud beta compute instances update
指令搭配 --no-graceful-shutdown
標記:
gcloud beta compute instances update INSTANCE_NAME \
--no-graceful-shutdown \
--zone=ZONE
更改下列內容:
INSTANCE_NAME
:執行個體的名稱。ZONE
:執行個體所在的區域。
REST
建立空白 JSON 檔案。
如要查看現有例項的屬性,請對 beta
instances.get
方法發出GET
要求:GET https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME
更改下列內容:
PROJECT_ID
:執行個體所在專案的 ID。ZONE
:執行個體所在的區域。INSTANCE_NAME
:現有執行個體的名稱。
在先前步驟中建立的空 JSON 檔案中,執行下列操作:
輸入
GET
要求輸出內容中的執行個體屬性。找出
gracefulShutdown.enabled
欄位,然後將其值變更為false
:{ ... "scheduling": { ... "gracefulShutdown": { "enabled": false } }, ... }
如要更新執行個體,請對 beta
instances.update
方法發出PUT
要求。請提供下列資訊:在要求網址中加入
mostDisruptiveAllowedAction
查詢參數。在要求主體中,納入您在先前步驟中建立及更新的 JSON 檔案中的執行個體屬性。
用於更新執行個體的
PUT
要求類似於以下內容:PUT https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME?mostDisruptiveAllowedAction=ALLOWED_ACTION { ... "scheduling": { ... "gracefulShutdown": { "enabled": false } }, ... }
請將
ALLOWED_ACTION
替換為下列任一值:NO_EFFECT
:這項要求會檢查更新要求是否有效,以及資源是否可用,但不會更新執行個體。REFRESH
:如果修改的執行個體屬性不需要重新啟動執行個體,Compute Engine 就會更新執行個體。
如要進一步瞭解如何更新執行個體的屬性,請參閱「更新執行個體屬性」。