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

教程:使用 Azure PowerShell 在 Windows VM 中安装 SQL、IIS、.NET 堆栈Tutorial: Install the SQL, IIS, .NET stack in a Windows VM with Azure PowerShell

在本教程中,我们将使用 Azure PowerShell 安装 SQL、IIS、.NET 堆栈。In this tutorial, we install a SQL, IIS, .NET stack using Azure PowerShell. 此堆栈包含两个运行 Windows Server 2016 的 VM,一个带有 IIS 和 .NET,另一个带有 SQL Server。This stack consists of two VMs running Windows Server 2016, one with IIS and .NET and the other with SQL Server.

  • 创建 VMCreate a VM
  • 在 VM 上安装 IIS 和 .NET Core SDKInstall IIS and the .NET Core SDK on the VM
  • 创建运行 SQL Server 的 VMCreate a VM running SQL Server
  • 安装 SQL Server 扩展Install the SQL Server extension

启动 Azure Cloud ShellLaunch Azure Cloud Shell

Azure Cloud Shell 是免费的交互式 shell,可以使用它运行本文中的步骤。The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. 它预安装有常用 Azure 工具并将其配置与帐户一起使用。It has common Azure tools preinstalled and configured to use with your account. 请直接单击“复制”对代码进行复制,将其粘贴到 Cloud Shell 中,然后按 Enter 来运行它。Just click the Copy to copy the code, paste it into the Cloud Shell, and then press enter to run it. 可通过多种方式来启动 Cloud Shell:There are a few ways to launch the Cloud Shell:

单击代码块右上角的“试用”。Click Try It in the upper right corner of a code block. 本文中的 Cloud Shell
在浏览器中打开 Cloud Shell。Open Cloud Shell in your browser. https://shell.azure.com/powershell
单击 Azure 门户右上角菜单上的“Cloud Shell”按钮。Click the Cloud Shell button on the menu in the upper right of the Azure portal. 门户中的 Cloud ShellCloud Shell in the portal

如果选择在本地安装并使用 PowerShell,则本教程需要 AzureRM.Compute 模块 5.7.0 或更高版本。If you choose to install and use the PowerShell locally, this tutorial requires the AzureRM.Compute module version 5.7.0 or later. 运行 Get-Module -ListAvailable AzureRM.Compute 即可查找版本。Run Get-Module -ListAvailable AzureRM.Compute to find the version. 如果需要升级,请参阅安装 Azure PowerShell 模块If you need to upgrade, see Install Azure PowerShell module.

创建 IIS VMCreate a IIS VM

在此示例中,我们使用 New-AzureRMVM cmdlet 在 PowerShell Cloud Shell 中快速创建 Windows Server 2016 VM,然后安装 IIS 和 .NET Framework。In this example, we use New-AzureRMVM cmdlet in the PowerShell Cloud Shell to quickly create a Windows Server 2016 VM and then install IIS and the .NET Framework. IIS 和 SQL VM 共享资源组和虚拟网络,因此我们创建这些名称的变量。The IIS and SQL VMs share a resource group and virtual network, so we create variables for those names.

$vmName = "IISVM"
$vNetName = "myIISSQLvNet"
$resourceGroup = "myIISSQLGroup"
New-AzureRmVm `
    -ResourceGroupName $resourceGroup `
    -Name $vmName `
    -Location "East US" `
    -VirtualNetworkName $vNetName `
    -SubnetName "myIISSubnet" `
    -SecurityGroupName "myNetworkSecurityGroup" `
    -AddressPrefix 192.168.0.0/16 `
    -PublicIpAddressName "myIISPublicIpAddress" `
    -OpenPorts 80,3389 

通过 Set-AzureRmVMExtension cmdlet 使用自定义脚本扩展安装 IIS 和 .NET Framework。Install IIS and the .NET framework using the custom script extension with the Set-AzureRmVMExtension cmdlet.

Set-AzureRmVMExtension `
    -ResourceGroupName $resourceGroup `
    -ExtensionName IIS `
    -VMName $vmName `
    -Publisher Microsoft.Compute `
    -ExtensionType CustomScriptExtension `
    -TypeHandlerVersion 1.4 `
    -SettingString '{"commandToExecute":"powershell Add-WindowsFeature Web-Server,Web-Asp-Net45,NET-Framework-Features"}' `
    -Location EastUS

创建另一子网Create another subnet

为 SQL VM 创建第二个子网。Create a second subnet for the SQL VM. 使用 [Get-AzureRmVirtualNetwork]{/powershell/module/azurerm.network/get-azurermvirtualnetwork} 获取 vNet。Get the vNet using [Get-AzureRmVirtualNetwork]{/powershell/module/azurerm.network/get-azurermvirtualnetwork}.

$vNet = Get-AzureRmVirtualNetwork `
   -Name $vNetName `
   -ResourceGroupName $resourceGroup

使用 Add-AzureRmVirtualNetworkSubnetConfig 为子网创建配置。Create a configuration for the subnet using Add-AzureRmVirtualNetworkSubnetConfig.

Add-AzureRmVirtualNetworkSubnetConfig `
   -AddressPrefix 192.168.0.0/24 `
   -Name mySQLSubnet `
   -VirtualNetwork $vNet `
   -ServiceEndpoint Microsoft.Sql

通过 Set-AzureRmVirtualNetwork 使用新的子网信息更新 vNetUpdate the vNet with the new subnet information using Set-AzureRmVirtualNetwork

$vNet | Set-AzureRmVirtualNetwork

Azure SQL VMAzure SQL VM

使用 SQL Server 的预配置 Azure 市场映像创建 SQL VM。Use a pre-configured Azure marketplace image of a SQL server to create the SQL VM. 首先创建 VM,然后在 VM 上安装 SQL Server 扩展。We first create the VM, then we install the SQL Server Extension on the VM.

New-AzureRmVm `
    -ResourceGroupName $resourceGroup `
    -Name "mySQLVM" `
    -ImageName "MicrosoftSQLServer:SQL2016SP1-WS2016:Enterprise:latest" `
    -Location eastus `
    -VirtualNetworkName $vNetName `
    -SubnetName "mySQLSubnet" `
    -SecurityGroupName "myNetworkSecurityGroup" `
    -PublicIpAddressName "mySQLPublicIpAddress" `
    -OpenPorts 3389,1401 

使用 Set-AzureRmVMSqlServerExtensionSQL Server 扩展添加到 SQL VM。Use Set-AzureRmVMSqlServerExtension to add the SQL Server extension to the SQL VM.

Set-AzureRmVMSqlServerExtension `
   -ResourceGroupName $resourceGroup  `
   -VMName mySQLVM `
   -Name "SQLExtension" `
   -Location "EastUS"

后续步骤Next steps

在本教程中,已使用 Azure PowerShell 安装 SQL\IIS\.NET 堆栈。In this tutorial, you installed a SQL\IIS\.NET stack using Azure PowerShell. 你已了解如何:You learned how to:

  • 创建 VMCreate a VM
  • 在 VM 上安装 IIS 和 .NET Core SDKInstall IIS and the .NET Core SDK on the VM
  • 创建运行 SQL Server 的 VMCreate a VM running SQL Server
  • 安装 SQL Server 扩展Install the SQL Server extension

转到下一教程,了解如何使用 SSL 证书保护 IIS Web 服务器。Advance to the next tutorial to learn how to secure IIS web server with SSL certificates.