【问题标题】:amazon ec2 detection from CentOS来自 CentOS 的 amazon ec2 检测
【发布时间】:2014-05-22 06:36:07
【问题描述】:

我有安装了我的应用程序的虚拟机列表。我想知道应用程序安装在哪个 VM 上。有没有办法找出宿主VM环境?

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

【问题讨论】:

    标签: amazon-web-services amazon-ec2 virtual-machine


    【解决方案1】:

    您可以尝试在合理的超时时间内获取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!
    

    【讨论】:

      猜你喜欢
      • 2016-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-20
      • 2014-10-25
      • 2014-07-16
      • 2016-08-17
      • 1970-01-01
      相关资源
      最近更新 更多