You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在未安装GCP CLI的自定义Linux终端查看GCE实例类型?

在GCP Compute Engine中无需安装CLI查询实例类型的方法

GCP Compute Engine实例内部可通过元数据服务器直接获取实例类型信息,无需安装gcloud或其他CLI工具,具体命令如下:

  • 直接获取完整机器类型路径:

    curl -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/machine-type
    

    输出示例:projects/123456789/zones/us-central1-a/machineTypes/n2-standard-4

  • 仅提取实例类型名称(如n2-standard-4):

    curl -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/machine-type | awk -F'/' '{print $NF}'
    
  • 若系统无curl,可使用wget替代:

    wget -qO- --header="Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/machine-type | awk -F'/' '{print $NF}'
    

说明:元数据服务器是GCP实例内部默认可访问的服务,无需额外权限,上述命令依赖的curl/wget和awk在绝大多数Linux发行版中均为默认预装工具。

内容的提问来源于stack exchange,提问作者pykaczka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 20:52:06