简体   繁体   English

检测是否在Azure IaaS VM(.NET应用程序)上运行

[英]Detect whether running on Azure IaaS VM (.NET Application)

I have seen many posts relating to what I believe should be a relatively simple task. 我看到许多与我认为应该是相对简单的任务有关的帖子。 As part of our licensing criteria we detect if we are running within a virtualised environment. 作为我们许可标准的一部分,我们检测我们是否在虚拟环境中运行。 However some identifiers we were using can change as a result of deallocation of the VM's and so we started looking into substituting some of these with the Azure Unique ID (UUID). 但是,由于VM的重新分配,我们使用的某些标识符可能会更改,因此我们开始研究用Azure唯一ID(UUID)替换其中的一些标识符。 But in order to do we so we need to make changes to our licensing code to correctly detect we are running in an azure environment. 但是,为了做到这一点,我们需要对许可代码进行更改,以正确检测我们是否正在蔚蓝的环境中运行。 I've seen many posts relating to using the Azure SDK and RoleEnvironment, but I believe this doesn't work when running on managed IaaS VM's (When copying the requisite DLL's across). 我已经看过许多有关使用Azure SDK和RoleEnvironment的帖子,但是我相信在托管IaaS VM上运行时(跨必需的DLL复制时),这是行不通的。

So ideally we want a way within a .NET application without having dependencies on the Azure SDK that we can correctly identify an Azure VM as opposed to a standard VM. 因此,理想情况下,我们希望在.NET应用程序中提供一种不依赖于Azure SDK的方式,以便我们可以正确地标识与标准VM相对的Azure VM。 This could include registry keys, WMI lookups etc. 这可能包括注册表项,WMI查找等。

I will note an existing solution found on the technet website of microsoft Script Detect Windows Azure Virtual Machine , but because the code we are running is generalised to work for all types of environments this isn't really practical. 我将注意到在Microsoft Script Detect Windows Azure虚拟机的technet网站上找到的现有解决方案,但是由于我们正在运行的代码被普遍适用于所有类型的环境,因此这实际上并不实用。

The Azure Instance Metadata Service provides information about running virtual machine instances that can be used to manage and configure your virtual machines. Azure实例元数据服务提供了有关正在运行的虚拟机实例的信息,这些信息可用于管理和配置虚拟机。 This includes information such as SKU, network configuration, and upcoming maintenance events. 其中包括诸如SKU,网络配置和即将发生的维护事件之类的信息。 For more information on what type of information is available, see metadata categories. 有关可用的信息类型的更多信息,请参见元数据类别。

Azure's Instance Metadata Service is a REST Endpoint accessible to all IaaS VMs created via the Azure Resource Manager. Azure的实例元数据服务是一个REST端点,可通过Azure资源管理器创建的所有IaaS VM都可以访问。 The endpoint is available at a well-known non-routable IP address 169.254.169.254 that can be accessed only from within the VM. 该终结点位于一个众所周知的不可路由IP地址169.254.169.254 ,该地址只能从VM内部访问。

https://docs.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service https://docs.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM