GCP计算引擎:如何从实例终端检查实例类型(自定义Linux)?

huangapple go评论47阅读模式
英文:

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"

输出:
GCP计算引擎:如何从实例终端检查实例类型(自定义Linux)?

如果您使用 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"

Output:
GCP计算引擎:如何从实例终端检查实例类型(自定义Linux)?

It will be flexible if you use gcloud and adding here the installation document for your reference.

huangapple
  • 本文由 发表于 2023年5月25日 16:00:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76330088.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定