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

在 Azure 中安装 SQL\IIS\.NET 堆栈Install a SQL\IIS\.NET stack in Azure

在本教程中,我们将使用 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.

  • 使用 New-AzVM 创建 VMCreate a VM using New-AzVM
  • 在 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

创建 IIS VMCreate a IIS VM

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

单击代码块右上方的“试用”按钮,以便在此窗口中启动 Cloud Shell。Click on the Try It button to the upper right of the code block to launch Cloud Shell in this window. 在命令提示符下将要求你提供虚拟机的凭据。You will be asked to provide credentials for the virtual machine at the cmd prompt.

$vNetName = "myIISSQLvNet"
$resourceGroup = "myIISSQLGroup"
New-AzVm -Name myIISVM -ResourceGroupName $resourceGroup -VirtualNetworkName $vNetName 

使用自定义脚本扩展安装 IIS 和 .NET framework。Install IIS and the .NET framework using the custom script extension.


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

Azure SQL VMAzure SQL VM

我们使用 SQL server 的预配置 Azure marketplace 映像创建 SQL VM。We 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.

# Create user object. You get a pop-up prompting you to enter the credentials for the VM.
$cred = Get-Credential -Message "Enter a username and password for the virtual machine."

# Create a subnet configuration
$vNet = Get-AzureRmVirtualNetwork -Name $vNetName -ResourceGroupName $resourceGroup
Add-AzureRmVirtualNetworkSubnetConfig -Name mySQLSubnet -VirtualNetwork $vNet -AddressPrefix "192.168.2.0/24"
Set-AzureRmVirtualNetwork -VirtualNetwork $vNet


# Create a public IP address and specify a DNS name
$pip = New-AzureRmPublicIpAddress -ResourceGroupName $resourceGroup -Location eastus `
  -Name "mypublicdns$(Get-Random)" -AllocationMethod Static -IdleTimeoutInMinutes 4

# Create an inbound network security group rule for port 3389
$nsgRuleRDP = New-AzureRmNetworkSecurityRuleConfig -Name myNetworkSecurityGroupRuleRDP  -Protocol Tcp `
  -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * `
  -DestinationPortRange 3389 -Access Allow


# Create a network security group
$nsg = New-AzureRmNetworkSecurityGroup -ResourceGroupName $resourceGroup -Location eastus `
  -Name myNetworkSecurityGroup -SecurityRules $nsgRuleRDP

# Create a virtual network card and associate with public IP address and NSG
$nic = New-AzureRmNetworkInterface -Name mySQLNic -ResourceGroupName $resourceGroup -Location eastus `
  -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id

# Create a virtual machine configuration
$vmConfig = New-AzureRmVMConfig -VMName mySQLVM -VMSize Standard_D1 | `
Set-AzureRmVMOperatingSystem -Windows -ComputerName mySQLVM -Credential $cred | `
Set-AzureRmVMSourceImage -PublisherName MicrosoftSQLServer -Offer SQL2014SP2-WS2012R2 -Skus Enterprise -Version latest | `
Add-AzureRmVMNetworkInterface -Id $nic.Id

# Create the VM
New-AzureRmVM -ResourceGroupName $resourceGroup -Location eastus -VM $vmConfig

使用 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"

后续步骤Next steps

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

  • 使用 New-AzVM 创建 VMCreate a VM using New-AzVM
  • 在 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.