教程:使用 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 PowerShellLaunch Azure PowerShell

Note

本文进行了更新,以便使用新的 Azure PowerShell Az 模块This article has been updated to use the new Azure PowerShell Az module. AzureRM 将继续获取关键的 bug 修复更新,但新功能将只出现在 Az 模块中。AzureRM will continue to get critical bugfix updates, but new features will be in the Az module only.

  • 若要在本地安装 Az 模块,请参阅安装 Azure PowerShellTo install the Az module locally, see Install Azure PowerShell.
  • 如果在本地安装 Az 模块,可通过运行 Enable-AzureRmAlias 来启用 AzureRM 兼容性。If you install the Az module locally, you can enable the AzureRM compatibility by running Enable-AzureRmAlias.

创建 IIS VMCreate a IIS VM

在此示例中,我们使用 New-AzVM cmdlet 在 PowerShell 中快速创建 Windows Server 2016 VM,然后安装 IIS 和 .NET Framework。In this example, we use New-AzVM cmdlet in the PowerShell 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.

Connect-AzAccount -Environment AzureChinaCloud
$vmName = "IISVM"
$vNetName = "myIISSQLvNet"
$resourceGroup = "myIISSQLGroup"
New-AzVm `
    -ResourceGroupName $resourceGroup `
    -Name $vmName `
    -Location "China East" `
    -VirtualNetworkName $vNetName `
    -SubnetName "myIISSubnet" `
    -SecurityGroupName "myNetworkSecurityGroup" `
    -AddressPrefix 192.168.0.0/16 `
    -PublicIpAddressName "myIISPublicIpAddress" `
    -OpenPorts 80,3389 

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

Set-AzVMExtension `
    -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 ChinaEast

创建另一子网Create another subnet

为 SQL VM 创建第二个子网。Create a second subnet for the SQL VM. 使用 Get-AzVirtualNetwork 获取 vNet。Get the vNet using Get-AzVirtualNetwork.

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

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

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

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

$vNet | Set-AzVirtualNetwork

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-AzVm `
    -ResourceGroupName $resourceGroup `
    -Name "mySQLVM" `
    -ImageName "MicrosoftSQLServer:SQL2016SP1-WS2016:Enterprise:latest" `
    -Location chinaeast `
    -VirtualNetworkName $vNetName `
    -SubnetName "mySQLSubnet" `
    -SecurityGroupName "myNetworkSecurityGroup" `
    -PublicIpAddressName "mySQLPublicIpAddress" `
    -OpenPorts 3389,1401 

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

Set-AzVMSqlServerExtension `
   -ResourceGroupName $resourceGroup  `
   -VMName mySQLVM `
   -Name "SQLExtension" `
   -Location "chinanorth"

后续步骤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.