本文說明如何使用中繼資料伺服器或作業系統工具,偵測 VM 是否在 Compute Engine 中執行。
使用中繼資料伺服器偵測 VM 是否在 Compute Engine 中執行
請根據 VM 的作業系統,使用下列其中一個程序向中繼資料伺服器傳送要求,並偵測 VM 是否在 Compute Engine 中執行:
Linux VM
在 Linux VM 中執行下列指令:
curl metadata.google.internal -i
確認輸出內容類似於下列內容,且包含
Metadata-Flavor: Google
:HTTP/1.1 200 OK Metadata-Flavor: Google Content-Type: application/text Date: Tue, 23 Nov 2021 01:27:16 GMT Server: Metadata Server for VM Content-Length: 22 X-XSS-Protection: 0 X-Frame-Options: SAMEORIGIN 0.1/ computeMetadata/
輸出內容中出現
Metadata-Flavor: Google
,表示要求是由 Compute Engine VM 傳送。
Windows VM
在 Windows VM 中執行下列指令:
curl metadata.google.internal -i
確認輸出內容類似於下列內容,且包含
Metadata-Flavor: Google
:HTTP/1.1 200 OK Metadata-Flavor: Google Content-Type: application/text Date: Tue, 23 Nov 2021 20:48:50 GMT Server: Metadata Server for VM Content-Length: 22 X-XSS-Protection: 0 X-Frame-Options: SAMEORIGIN 0.1/ computeMetadata/
輸出內容中出現
Metadata-Flavor: Google
,表示要求是由 Compute Engine VM 傳送。
使用作業系統工具偵測 VM 是否在 Compute Engine 中執行
請根據 VM 的作業系統,使用下列其中一種程序,透過 VM 作業系統專用的工具偵測 VM 是否在 Compute Engine 中執行:
Linux VM
在 Linux VM 中,執行下列
dmidecode
指令:sudo dmidecode -s system-product-name | grep "Google Compute Engine"
這個
dmidecode
指令可直接存取/proc/mem
中的系統管理 BIOS 資訊。確認輸出內容中是否包含
Google Compute Engine
。
Windows VM
在 Windows 命令提示字元中,執行 WMI 指令列公用程式:
wmic.exe computersystem get model,manufacturer
確認
System Manufacturer
為Google
,且System Model
為Google Compute Engine
。
如要瞭解如何以程式輔助方式判斷 Windows VM 是否正在執行 Compute Engine,請參閱下列內容: