gpt4 book ai didi

azure - Azure 虚拟机的 ec2metadata 等效项

转载 作者:行者123 更新时间:2023-12-04 15:43:40 32 4
gpt4 key购买 nike

Azure 虚拟机中有类似 ec2metadata 的东西吗?

我需要提取公共(public)主机名或实例 ID 等数据。在 Amazon EC2 实例中,我可以执行以下操作:

$ ec2metadata --instance-id
i-3a1dcfa3
$ ec2metadata --public-hostname
ec2-54-91-124-63.compute-1.amazonaws.com

最佳答案

看来这个问题很久以前就被问过了,所以也许你已经找到了答案。如果没有,那么您尝试过 Azure 实例元数据吗? ( https://learn.microsoft.com/en-us/azure/virtual-machines/virtual-machines-instancemetadataservice-overview ) 您可以像这样执行 http 请求:

curl -H Metadata:true "http://169.254.169.254/metadata/instance?api-version=2017-04-02"

响应如下所示:

{
"compute": {
"location": "westcentralus",
"name": "IMDSSample",
"offer": "UbuntuServer",
"osType": "Linux",
"platformFaultDomain": "0",
"platformUpdateDomain": "0",
"publisher": "Canonical",
"sku": "16.04.0-LTS",
"version": "16.04.201610200",
"vmId": "5d33a910-a7a0-4443-9f01-6a807801b29b",
"vmSize": "Standard_A1"
},
"network": {
"interface": [
{
"ipv4": {
"ipAddress": [
{
"privateIpAddress": "10.1.0.4",
"publicIpAddress": "X.X.X.X"
}
],
"subnet": [
{
"address": "10.1.0.0",
"prefix": "24"
}
]
},
"ipv6": {
"ipAddress": []
},
"macAddress": "000D3AF806EC"
}
]
}
}

希望这有帮助! :)

关于azure - Azure 虚拟机的 ec2metadata 等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27986152/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com