2014-05-22 68 views
1

我在安装我的应用程序的虚拟机列表。我想知道的是安装了虚拟机的应用程序。有没有办法找出主机VM环境?Amazon EC2的检测从CentOS的

有没有一种方法可以从我的程序中检测到我正在Amazon EC2托管的虚拟机上运行?

回答

0

您可以尝试在合理的超时时间内获取http://169.254.169.254/latest/meta-data/,如果您收到某些回复,则说明您正在亚马逊上运行。

你可以阅读关于here

下面是您在EC2中运行时得到的结果。

% curl http://169.254.169.254/latest/meta-data/ 
ami-id 
ami-launch-index 
ami-manifest-path 
block-device-mapping/ 
hostname 
iam/ 
instance-action 
instance-id 
instance-type 
kernel-id 
local-hostname 
local-ipv4 
mac 
metrics/ 
network/ 
placement/ 
profile 
public-keys/ 
reservation-id 
security-groups 
services/ 

...并从正规机:

# curl http://169.254.169.254/latest/meta-data/ --connect-timeout 3 
curl: (28) connect() timed out!