您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

使用脚本在 Azure 实验室服务中对模板虚拟机启用嵌套虚拟化Enable nested virtualization on a template virtual machine in Azure Lab Services using a script

使用嵌套虚拟化,可以在实验室的模板虚拟机内创建多 VM 环境。Nested virtualization enables you to create a multi-VM environment inside a lab's template virtual machine. 发布模板会为实验室中的每个用户提供一个虚拟机,其中包含多个 VM。Publishing the template will provide each user in the lab with a virtual machine set up with multiple VMs within it. 有关嵌套虚拟化和 Azure 实验室服务的详细信息,请参阅在 Azure 实验室服务中对模板虚拟机启用嵌套虚拟化For more information about nested virtualization and Azure Lab Services, see Enable nested virtualization on a template virtual machine in Azure Lab Services.

本文中的步骤重点介绍如何为 Windows Server 2016、Windows Server 2019 或 Windows 10 设置嵌套虚拟化。The steps in this article focus on setting up nested virtualization for Windows Server 2016, Windows Server 2019, or Windows 10. 你将使用脚本设置具有 Hyper-V 的模板计算机。You will use a script to set up template machine with Hyper-V. 以下步骤将引导你了解如何使用实验室服务 Hyper-V 脚本The following steps will guide you through how to use the Lab Services Hyper-V scripts.

重要

创建实验室时,选择“大型(嵌套虚拟化)”或“中等(嵌套虚拟化)”作为虚拟机大小。Select Large (nested virtualization) or Medium (nested virtualization) for the virtual machine size when creating the lab. 否则,嵌套虚拟化将不起作用。Nested virtualization will not work otherwise.

运行脚本Run script

  1. 如果使用的是 Internet Explorer,则可能必须将 https://github.com 添加到“受信任的站点”列表中。If you're using Internet Explorer, you may have to add https://github.com to the trusted sites list.

    1. 打开 Internet Explorer。Open Internet Explorer.

    2. 选择齿轮图标,然后选择“Internet 选项”。Select the gear icon, and choose Internet options.

    3. 出现“Internet 选项”对话框后,请依次选择“安全性”、“受信任的站点”,然后单击“站点”按钮。When the Internet Options dialog appears, select Security, select Trusted Sites, click Sites button.

    4. 当“受信任的站点”对话框出现时,请将 https://github.com 添加到受信任网站的列表,然后选择“关闭”。When the Trusted sites dialog appears, add https://github.com to the trusted websites list, and select Close.

      受信任的站点

  2. 按照以下步骤所述下载 Git 存储库文件。Download the Git repository files as outlined in the following steps.

    1. 转到 https://github.com/Azure/azure-devtestlab/Go to https://github.com/Azure/azure-devtestlab/.
    2. 单击“克隆或下载”按钮。Click the Clone or Download button.
    3. 单击“下载 ZIP”。Click Download ZIP.
    4. 提取 ZIP 文件Extract the ZIP file

    提示

    也可以在 https://github.com/Azure/azure-devtestlab.git 上克隆 Git 存储库。You can also clone the Git repository at https://github.com/Azure/azure-devtestlab.git.

  3. 以“管理员”模式启动 PowerShell。Launch PowerShell in Administrator mode.

  4. 在 PowerShell 窗口中,导航到包含已下载脚本的文件夹。In the PowerShell window, navigate to the folder with the downloaded script. 如果是从存储库文件的顶级文件夹导航,则该脚本位于 azure-devtestlab\samples\ClassroomLabs\Scripts\HyperV\If you're navigating from the top folder of the repository files, the script is located at azure-devtestlab\samples\ClassroomLabs\Scripts\HyperV\.

  5. 你可能必须更改执行策略才能成功运行该脚本。You may have to change the execution policy to successfully run the script. 运行以下命令:Run the following command:

    Set-ExecutionPolicy bypass -force
    
  6. 运行以下脚本:Run the script:

    .\SetupForNestedVirtualization.ps1
    

    备注

    该脚本可能需要重启计算机。The script may require the machine to be restarted. 按照该脚本中的说明操作,然后重新运行该脚本,直到在输出中显示“已完成脚本”。Follow instructions from the script and re-run the script until Script completed is seen in the output.

  7. 请不要忘记重置执行策略。Don't forget to reset the execution policy. 运行以下命令:Run the following command:

    Set-ExecutionPolicy default -force
    

结束语Conclusion

现在,模板计算机已准备好创建 Hyper-V 虚拟机。Now your template machine is ready to create Hyper-V virtual machines. 有关如何创建 Hyper-V 虚拟机的说明,请参阅在 Hyper-V 中创建虚拟机See Create a Virtual Machine in Hyper-V for instructions on how to create Hyper-V virtual machines. 另外,请参阅 Microsoft 评估中心以查看可用的操作系统和软件。Also, see Microsoft Evaluation Center to check out available operating systems and software.

后续步骤Next steps

后续步骤是设置任何实验室时通用的。Next steps are common to setting up any lab.