如何在未安装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
相关产品推荐
相关产品推荐

