快速入门:使用 Azure CLI 在 Azure Stack Hub 中 创建 Windows Server 虚拟机Quickstart: Create a Windows Server virtual machine using Azure CLI in Azure Stack Hub

可以使用 Azure CLI 创建 Windows Server 2016 虚拟机。You can create a Windows Server 2016 virtual machine by using the Azure CLI. 请按照本文中的步骤创建和使用虚拟机。Follow the steps in this article to create and use a virtual machine. 本文还提供了以下步骤:This article also gives you the following steps:

  • 通过远程客户端连接到虚拟机。Connect to the virtual machine with a remote client.
  • 安装 IIS Web 服务器并查看默认主页。Install the IIS web server and view the default home page.
  • 清理资源。Clean up your resources.

先决条件Prerequisites

  • 确保 Azure Stack Hub 操作员已将“Windows Server 2016” 映像添加到 Azure Stack Hub 市场。Make sure that your Azure Stack Hub operator added the Windows Server 2016 image to the Azure Stack Hub Marketplace.

  • Azure Stack Hub 需要使用特定版本的 Azure CLI 来创建和管理资源。Azure Stack Hub requires a specific version of Azure CLI to create and manage the resources. 如果尚未为 Azure Stack Hub 配置 Azure CLI,请按照安装和配置 Azure CLI 的步骤进行操作。If you don't have Azure CLI configured for Azure Stack Hub, follow the steps to install and configure Azure CLI.

创建资源组Create a resource group

资源组是一个逻辑容器,可以在其中部署和管理 Azure Stack Hub 资源。A resource group is a logical container where you can deploy and manage Azure Stack Hub resources. 在 Azure Stack Hub 环境中,运行 az group create 命令以创建资源组。From your Azure Stack Hub environment, run the az group create command to create a resource group.

备注

代码示例中为所有变量都分配了值。Values are assigned for all the variables in the code examples. 但是,如果愿意,也可以分配新值。However, you can assign new values if you want to.

以下示例在本地位置创建名为 myResourceGroup 的资源组:The following example creates a resource group named myResourceGroup in the local location:

az group create --name myResourceGroup --location local

创建虚拟机Create a virtual machine

可以使用 az vm create 命令创建虚拟机 (VM)。Create a virtual machine (VM) by using the az vm create command. 以下示例创建名为 myVM 的 VM。The following example creates a VM named myVM. 此示例使用 Demouser 作为管理员用户名,并使用 Demouser@123 作为管理员密码。This example uses Demouser for an adminuser name and Demouser@123 as the admin password. 将这些值更改为适合你的环境的值。Change these values to something that is appropriate for your environment.

az vm create \
  --resource-group "myResourceGroup" \
  --name "myVM" \
  --image "Win2016Datacenter" \
  --admin-username "Demouser" \
  --admin-password "Demouser@123" \
  --location local

创建 VM 时,输出中的 PublicIPAddress 参数包含虚拟机的公共 IP 地址。When the VM is created, the PublicIPAddress parameter in the output contains the public IP address for the virtual machine. 记下此地址,因为需要使用它来访问虚拟机。Write down this address because you need it to use the virtual machine.

为 Web 流量打开端口 80Open port 80 for web traffic

由于此 VM 将运行 IIS Web 服务器,因此需要为 Internet 流量打开端口 80。Because this VM is going to run the IIS web server, you need to open port 80 to internet traffic.

使用 az vm open-port 命令打开端口 80:Use the az vm open-port command to open port 80:

az vm open-port --port 80 --resource-group myResourceGroup --name myVM

连接到虚拟机Connect to the virtual machine

使用以下命令创建到虚拟机的远程桌面连接。Use the next command to create a Remote Desktop connection to your virtual machine. 将“Public IP Address”替换为你的虚拟机的 IP 地址。Replace "Public IP Address" with the IP address of your virtual machine. 系统询问时,输入用于虚拟机的用户名和密码。When asked, enter the username and password that you used for the virtual machine.

mstsc /v <Public IP Address>

使用 PowerShell 安装 IISInstall IIS using PowerShell

现在,你已登录到虚拟机,可以使用 PowerShell 来安装 IIS 了。Now that you've signed in to the virtual machine, you can use PowerShell to install IIS. 在虚拟机上启动 PowerShell 并运行以下命令:Start PowerShell on the virtual machine and run the following command:

Install-WindowsFeature -name Web-Server -IncludeManagementTools

查看 IIS 欢迎页View the IIS welcome page

可以使用所选的浏览器查看默认 IIS 欢迎页。You can use a browser of your choice to view the default IIS welcome page. 请使用前面部分中列出的公共 IP 地址来访问默认页面:Use the public IP address listed in the previous section to visit the default page:

IIS 默认站点

清理资源Clean up resources

清理不再需要的资源。Clean up the resources that you don't need any longer. 可以使用 az group delete 命令来删除资源组、虚拟机和所有相关的资源。Use the az group delete command to remove the resource group, the virtual machine, and all related resources.

az group delete --name myResourceGroup

后续步骤Next steps

在本快速入门中,你已部署了一台基本的 Windows Server 虚拟机。In this quickstart, you deployed a basic Windows Server virtual machine. 若要详细了解 Azure Stack Hub 虚拟机,请继续阅读有关 Azure Stack Hub 中虚拟机的注意事项To learn more about Azure Stack Hub virtual machines, continue to Considerations for Virtual Machines in Azure Stack Hub.