英文:
GCP compute engine: how to check instance type (custom Linux) from the instance terminal?
问题
我可以帮您翻译以下内容:
在AWS中,您可以轻松从终端检查EC2实例类型:
aws-instance-xyz:/ # dmidecode -s system-product-name
m6i.4xlarge
但是在GCP中,dmidecode命令无法用于检查计算引擎实例类型:
gcp-instance-xyz:/ # dmidecode -s system-product-name
Google Compute Engine
您想要能够使用终端命令检查GCP计算引擎实例类型,但无法在Linux环境中安装GCP命令行工具,因此任何gcloud/gutils命令都不可行。
英文:
I have custom Linux that I can boot up on AWS and GCP.
In AWS I can check EC2 instance type easily from terminal:
aws-instance-xyz:/ # dmidecode -s system-product-name
m6i.4xlarge
I would like to be able to check instance type of compute engine in GCP however dmidecode command is of no use here:
gcp-instance-xyz:/ # dmidecode -s system-product-name
Google Compute Engine
I have to be able to check the instance type using a command in terminal. I can't install GCP cli on that linux environment so any gcloud/gutils commands are not an option.
答案1
得分: 1
根据此官方文档,使用 sudo dmidecode -s system-product-name
可以检测 VM 是否在 Compute Engine 上运行。
要获取元数据详细信息,您需要使用如下所述的 curl
命令,详见此官方文档。使用以下命令获取实例类型:
curl "http://metadata.google.internal/computeMetadata/v1/instance/machine-type" -H "Metadata-Flavor: Google"
如果您使用 gcloud 并且希望灵活使用,我在此添加了安装文档供您参考。
英文:
As per this official doc sudo dmidecode -s system-product-name
is used to detect if the VM is running in Compute Engine.
To get the metadata details you need to use the curl
command as mentioned in this official doc.Use the below command to get instance type:
curl "http://metadata.google.internal/computeMetadata/v1/instance/machine-type" -H "Metadata-Flavor: Google"
It will be flexible if you use gcloud and adding here the installation document for your reference.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论