1
我在安裝我的應用程序的虛擬機列表。我想知道的是安裝了虛擬機的應用程序。有沒有辦法找出主機VM環境?Amazon EC2的檢測從CentOS的
有沒有一種方法可以從我的程序中檢測到我正在Amazon EC2託管的虛擬機上運行?
我在安裝我的應用程序的虛擬機列表。我想知道的是安裝了虛擬機的應用程序。有沒有辦法找出主機VM環境?Amazon EC2的檢測從CentOS的
有沒有一種方法可以從我的程序中檢測到我正在Amazon EC2託管的虛擬機上運行?
您可以嘗試在合理的超時時間內獲取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!