Dışarıya aktar (0) Yazdır
Tümünü Genişlet
Bu içerik dilinizde bulunmamaktadır ancak İngilizce sürümüne buradan bakabilirsiniz.

How to use PowerShell to set up a SQL Server virtual machine in Azure

Updated: March 31, 2015

You can manage your virtual machines in Azure by using the REST API and PowerShell cmdlets. For more information, see Azure Service Management API Reference and Azure Management Cmdlets in the MSDN library.

In this tutorial, you learn how to create multiple SQL Server virtual machines in the same Cloud Service by using the PowerShell cmdlets. This tutorial assumes the following:

  • You already have an Azure account with the virtual machine subscription.

  • You have installed the Azure PowerShell cmdlets.

  1. Open Azure PowerShell command prompt as an administrator. Then, execute:

    PS C:\> Get-AzurePublishSettingsFile
    This command launches your default browser, connects to your Azure account, and then automatically downloads the .publishsettings file for your account. The publish-settings file contains the secure credentials and more information about your Azure Subscription to use in your development environment.

  2. Then, execute the following statement to import a publishsettings file with a certificate to connect to your Azure account.

    PS C:\> Import-AzurePublishSettingsFile –PublishSettingsFile "C:\Temp\MyAccountName-date-credentials.publishsettings"
    Security Note: The publishsettings file contains your credentials (unencoded) that are used to administer your Azure subscriptions and services. The security best practice for this file is to store it temporarily outside your source directories (for example in the Libraries\Documents folder), and then delete it once the import has completed. A malicious user gaining access to the publishsettings file can edit, create, and delete your Azure services.

  3. Run Get-AzureSubscription to learn the subscription details.

    PS C:\> Get-AzureSubscription -Current
  4. Find which data center you want to create your virtual machines in:

    PS C:\> Get-AzureLocation
  5. Check whether you have a storage account already:

    PS C:\> Get-AzureStorageAccount
  6. If you don’t have any storage account, create a storage account in the data center that you have chosen.

    New-AzureStorageAccount -StorageAccountName ‘MyStorageAccountName’ -Location ‘DC-LOCATION’
    It is important that you create the virtual machines in the same location or region as your storage account.

  7. Set the Azure subscription:

    Set-AzureSubscription -SubscriptionName 'Your Subscription'  -CurrentStorageAccount 'Your storage account'
  8. Find out the list of available virtual machines images from the gallery:

    PS C:\> Get-AzureVMImage | select ImageName
  9. Create the first SQL Server virtual machine as follows:

    $dclocation = 'DC-LOCATION'
    $cloudSvcName = 'YourCloudService'
    $image = 'SQLImageName'
    $adminUserName = 'YourAdminUser'
    $adminPassword = 'YourPassword'
    $vmname = 'SQLVM1'
    New-AzureService -ServiceName $cloudSvcName -Label "MyLabel" -Location "DC-LOCATION"
    New-AzureVMConfig -Name $vmname -InstanceSize Large -ImageName $image | Add-AzureProvisioningConfig -Windows -Password $adminPassword -AdminUsername $adminUserName | New-AzureVM –ServiceName $cloudSvcName
    Start-AzureVM -ServiceName $cloudSvcName -Name $vmname
  10. Create the second SQL Server virtual machine in the same Cloud Service.

    $dclocation = 'DC-LOCATION'
    $cloudSvcName = 'YourCloudService'
    $image = 'SQLImageName'
    $adminUserName = 'YourAdminUser'
    $adminPassword = 'YourPassword'
    $vmname = ‘SQLVM2'
    New-AzureVMConfig -Name $vmname -InstanceSize Large -ImageName $image | Add-AzureProvisioningConfig -Windows -Password $adminPassword -AdminUsername $adminUserName | New-AzureVM –ServiceName $cloudSvcName
    Start-AzureVM -ServiceName $cloudSvcName -Name $vmname
  11. Create the .RDP files in the C:\ folder to launch these virtual machines to complete setup:

    $vmname = 'SQLVM1'
    Get-AzureRemoteDesktopFile -ServiceName $cloudSvcName -Name $vmname -LocalPath "c:\MyVM01.rdp"
    $vmname = 'SQLVM2'
    Get-AzureRemoteDesktopFile -ServiceName $cloudSvcName -Name $vmname -LocalPath "c:\MyVM02.rdp"
  12. To set up the firewall settings in the virtual machines, connect to the virtual machines via Remote Desktop respectively. Then, run the following command at the command prompt:

    netsh advfirewall firewall add rule name="SQLServerVM1Port" dir=in protocol=TCP localport=1433 action=allow
    netsh advfirewall firewall add rule name="SQLServerVM2Port" dir=in protocol=TCP localport=1433 action=allow

    The netsh advfirewall command adds an inbound rule to the firewall policy for port 1433 for SQL Server.

After completing these steps, connect to these new virtual machines by using remote desktop. Then, configure SQL Server to listen on the TCP protocol and for mixed mode authentication. In addition, create SQL Server authentication logins. If you want to access these virtual machines from Internet create a TCP endpoint for each as well. For more information, see Provisioning a SQL Server Virtual Machine on Azure as well as the connectivity tutorials in the Connectivity Considerations for SQL Server in Azure Virtual Machines section .

© 2015 Microsoft