创建由 Azure Arc 启用的 Azure Local 虚拟机

适用于:Azure Local 2311.2 及更高版本

本文介绍如何从在 Azure 本地实例上创建的 VM 映像开始,创建由 Azure Arc 启用的 Azure 本地虚拟机(VM)。 可使用 Azure CLI、Azure 门户或 Azure 资源管理器模板来创建 Azure Local VM。

关于 Azure Local 资源

使用 Azure Local 资源页面以执行以下操作:

  • 创建和管理 Azure Local VM 资源,例如 VM 映像、磁盘、网络接口。
  • 查看和访问与 Azure Local 实例关联的 Azure Arc 资源网桥和自定义位置。
  • 预配和管理 VM。

下一部分将介绍创建 VM 的过程。

先决条件

在创建 Azure 本地 VM 之前,请确保满足以下先决条件:

  • 如果使用客户端连接到 Azure Local,请参阅通过 Azure CLI 客户端连接到 Azure Local

  • 访问在与您的 Azure Local 关联的逻辑网络上创建的网络接口。 可选择具有静态 IP 的网络接口或具有动态 IP 分配的网络接口。 有关详细信息,请参阅如何创建网络接口

创建 Azure Local VM

按照以下步骤在 Azure Local 上创建 VM。

在连接到 Azure Local 且作为 CLI 运行的客户端上执行以下步骤。

登录并设置订阅

  1. 连接到 Azure Local 上的计算机

  2. 登录。 类型:

    az login --use-device-code
    
  3. 设置订阅。

    az account set --subscription <Subscription ID>
    

创建 Windows VM

根据你创建的网络接口的类型,可创建具有静态 IP 网络接口的 VM 或具有动态 IP 分配的 VM。

注意

如果你的 VM 需要多个具有静态 IP 的网络接口,则请在创建 VM 之前立即创建一个或多个接口。 不支持在预配 VM 后添加具有静态 IP 的网络接口。

在此,创建一个在指定存储路径上使用特定内存与处理器计数的 VM。

  1. 设置一些参数。

    $vmName ="local-vm"
    $subscription =  "<Subscription ID>"
    $resource_group = "local-rg"
    $customLocationName = "local-cl"
    $customLocationID ="/subscriptions/$subscription/resourceGroups/$resource_group/providers/Microsoft.ExtendedLocation/customLocations/$customLocationName"
    $___location = "eastus"
    $computerName = "mycomputer"
    $userName = "local-user"
    $password = "<Password for the VM>"
    $imageName ="ws22server"
    $nicName ="local-vnic" 
    $storagePathName = "local-sp" 
    $storagePathId = "/subscriptions/<Subscription ID>/resourceGroups/local-rg/providers/Microsoft.AzureStackHCI/storagecontainers/local-sp" 
    

    VM 创建的参数列表如下:

    参数 说明
    名称 为 Azure Local 创建的 VM 的名称。 请确保提供的名称符合 Azure 资源规则
    管理员用户名 要在 Azure Local 上部署的 VM 中的用户的用户名。
    admin-password 要在 Azure Local 上部署的 VM 上的用户密码。
    image-name 用于预配 VM 的 VM 映像的名称。
    位置 az locations 指定的 Azure 区域。 例如,它可以是 eastuswesteurope
    resource-group 在其中创建 VM 的资源组的名称。 为便于管理,建议使用与 Azure Local 相同的资源组。
    订阅 部署 Azure Local 的订阅的名称或 ID。 这可能是你在 Azure Local 上用于 VM 的另一个订阅。
    自定义位置 使用此参数可提供与你创建此 VM 所在的 Azure Local 关联的自定义位置。
    authentication-type 用于此 VM 的身份验证的类型。 接受的值为 allpasswordssh。 默认值为 Windows 的密码和 Linux 的 SSH 公钥。 使用 all 来同时启用 sshpassword 身份验证。
    nics 与 VM 关联的网络接口的名称或 ID。 创建 VM 时,必须至少有一个网络接口才能启用来宾管理。
    memory-mb 分配给 VM 的内存(以 MB 为单位)。 如果未指定,则使用默认值。
    处理器 分配给 VM 的处理器数。 如果未指定,则使用默认值。
    storage-path-id 保存 VM 配置和数据的关联存储路径。
    proxy-configuration 使用此可选参数来为 VM 配置代理服务器。 有关详细信息,请参阅创建配置了代理服务器的 VM
  2. 运行以下命令以创建适用 VM。

    要创建受信任启动 Azure 本地 VM:

    1. 指定其他标志以启用安全启动、启用虚拟 TPM 和选择安全类型。 请注意,将安全类型指定为受信任启动时,必须启用安全启动和 vTPM,否则受信任启动 VM 创建会失败。

      az stack-hci-vm create --name $vmName --resource-group $resource_group --admin-username $userName --admin-password $password --computer-name $computerName --image $imageName --___location $___location --authentication-type all --nics $nicName --custom-___location $customLocationID --hardware-profile memory-mb="8192" processors="4" --storage-path-id $storagePathId --enable-secure-boot true --enable-vtpm true --security-type "TrustedLaunch"
      
    2. 创建 VM 后,若要验证 VM 的安全类型是否为 Trusted launch,请执行以下操作。

    3. 运行以下 cmdlet(在其中一个群集节点上)以查找 VM 的所有者节点:

      Get-ClusterGroup $vmName
      
    4. 在 VM 的所有者节点上运行以下 cmdlet:

      (Get-VM $vmName).GuestStateIsolationType
      
    5. 确保返回 TrustedLaunch 值。

    要创建标准 Azure Local VM:

     az stack-hci-vm create --name $vmName --resource-group $resource_group --admin-username $userName --admin-password $password --computer-name $computerName --image $imageName --___location $___location --authentication-type all --nics $nicName --custom-___location $customLocationID --hardware-profile memory-mb="8192" processors="4" --storage-path-id $storagePathId 
    

如果输出中的 provisioningState 显示为 succeeded,表示成功创建了 VM。

注意

默认情况下,创建的 VM 已启用来宾管理。 如果在 VM 创建过程中由于任何原因来宾管理失败,可按照在 Azure Local VM 上启用来宾管理中的步骤在 VM 创建后启用它。

在本例,使用 --storage-path-id 标志来指定存储路径,并确保工作负载数据(包括 VM、VM 映像、非 OS 数据磁盘)位于指定的存储路径中。

如果未指定该标志,则工作负载(VM、VM 映像、非 OS 数据磁盘)会自动位于高可用性存储路径中。

Windows Server 2012 和 Windows Server 2012 R2 映像的其他参数

使用 Windows Server 2012 和 Windows Server 2012 R2 映像创建 VM 时,请指定以下附加参数来创建 VM:

  • --enable-agent:将此参数设为 true 以在 VM 上加入 Azure Connected Machine 代理。
  • --enable-vm-config-agent:将此参数设置为 false,以防止通过 Hyper-V 套接字通道将 VM 上的 VM 代理从主机上载入。 Windows Server 2012 和 Windows Server 2012 R2 不支持 Hyper-V 套接字。 在支持 Hyper-V 套接字的较新映像版本中,VM 代理可用于在 VM 上加入 Azure Connected Machine 代理。 有关 Hyper-V 套接字的详细信息,请参阅创建自己的集成服务

创建 Linux VM

要创建 Linux VM,请使用与用于创建 Windows VM 相同的命令。

  • 指定的库映像应为 Linux 映像。
  • 用户名和密码将与 authentication-type-all 参数一起使用。
  • 对于 SSH 密钥,需将 ssh-key-values 参数与 authentication-type-all 一起传递。

重要

Ubuntu Server VM 支持在 VM 创建期间设置代理服务器。

创建配置了代理服务器的 VM

使用此可选参数 proxy-configuration 为 VM 配置代理服务器。

VM 的代理配置仅适用于 Azure 连接的计算机代理的加入,并设置为来宾 VM 操作系统中的环境变量。 VM 上的浏览器和应用程序不一定会通过此代理配置来启用。

因此,如果应用程序未引用 VM 中设置的环境变量,则可能需要专门为应用程序设置代理配置。

如果要在代理服务器后方创建 VM,请运行以下命令:

az stack-hci-vm create --name $vmName --resource-group $resource_group --admin-username $userName --admin-password $password --computer-name $computerName --image $imageName --___location $___location --authentication-type all --nics $nicName --custom-___location $customLocationID --hardware-profile memory-mb="8192" processors="4" --storage-path-id $storagePathId --proxy-configuration http_proxy="<Http URL of proxy server>" https_proxy="<Https URL of proxy server>" no_proxy="<URLs which bypass proxy>" cert_file_path="<Certificate file path for your machine>"

可以为 proxy-server-configuration 输入以下参数:

参数 说明
http_proxy 代理服务器的 HTTP URL。 示例 URL 为:http://proxy.example.com:3128
https_proxy 代理服务器的 HTTPS URL。 服务器可能仍会使用 HTTP 地址,如以下示例所示:http://proxy.example.com:3128
no_proxy URL,可以绕过代理。 典型示例为 localhost,127.0.0.1,.svc,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,100.0.0.0/8
cert_file_path 选择用于与代理服务器建立信任的证书文件。 例如:C:\Users\Palomino\proxycert.crt

下面是一个示例命令:

az stack-hci-vm create --name $vmName --resource-group $resource_group --admin-username $userName --admin-password $password --computer-name $computerName --image $imageName --___location $___location --authentication-type all --nics $nicName --custom-___location $customLocationID --hardware-profile memory-mb="8192" processors="4" --storage-path-id $storagePathId --proxy-configuration http_proxy="http://ubuntu:ubuntu@192.168.200.200:3128" https_proxy="http://ubuntu:ubuntu@192.168.200.200:3128" no_proxy="localhost,127.0.0.1,.svc,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,100.0.0.0/8,s-cluster.test.contoso.com" cert_file_path="C:\ClusterStorage\UserStorage_1\server.crt"

对于代理身份验证,可传递组合在 URL 中的用户名和密码,如下所示:"http://username:password@proxyserver.contoso.com:3128"

注意

  • 在 VM 预配期间,在 Azure 本地 VM 中创建和使用两个 DVD 驱动器。 成功创建 VM 后,将删除预配期间使用的 ISO 文件。 但是,你可能会看到在 VM 中可见的空的磁盘驱动器。
  • 若要删除 Windows VM 中的这些驱动器,请使用 Device Manager 卸载驱动器。 根据您使用的 Linux 发行版,也可以从 Linux VM 中删除它们。

使用托管标识对 Azure Local VM 进行身份验证

通过 Azure CLI 或 Azure 门户在 Azure Local 上创建 VM 时,还会创建一个系统分配的托管标识,而该标识在 VM 的生命周期内会持续有效。

Azure Local 上的 VM 是从已启用 Arc 的服务器扩展而来的,且可使用系统分配的托管标识来访问支持基于 Microsoft Entra ID 的身份验证的其他 Azure 资源。 例如,VM 可使用系统分配的托管标识来访问 Azure Key Vault。

有关详细信息,请参阅系统分配的托管标识使用已启用 Azure Arc 的服务器对 Azure 资源进行身份验证

后续步骤