如何知道机器是否是Google Compute Engine实例 [英] How to know if a machine is an Google Compute Engine instance
问题描述
是否可以从命令行shell知道我当前是否在Google Compute Engine计算机上或其他地方(开发计算机)上?
Is there a way to know from a command line shell if I am currently on a Google Compute Engine machine or somewhere else (development machine)?
推荐答案
每个元数据文档:
您可以使用元数据服务器轻松检测您的应用程序或脚本是否在Compute Engine实例中运行.当您向服务器发出请求时,来自元数据服务器的任何响应都将包含
Metadata-Flavor: Google
标头.您可以查找此标头,以可靠地检测您是否正在Compute Engine中运行.
You can easily detect if your applications or scripts are running within a Compute Engine instance by using the metadata server. When you make a request to the server, any response from the metadata server will contain the
Metadata-Flavor: Google
header. You can look for this header to reliably detect if you are running in Compute Engine.
例如,以下curl请求返回Metadata-Flavor: Google
标头,表明该请求是在Compute Engine实例内进行的.
For example, the following curl request returns a Metadata-Flavor: Google
header, indicating that the request is being made from within a Compute Engine instance.
me@my-inst:~$ curl metadata.google.internal -i
HTTP/1.1 200 OK
Metadata-Flavor: Google
Content-Type: application/text
Date: Thu, 10 Apr 2014 19:24:27 GMT
Server: Metadata Server for VM
Content-Length: 22
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
0.1/
computeMetadata/
这篇关于如何知道机器是否是Google Compute Engine实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!