快速入门:配置 Azure VM 以连接到 Azure SQL 托管实例Quickstart: Configure an Azure VM to connect to Azure SQL Managed Instance

适用于:是Azure SQL 托管实例 APPLIES TO: yesAzure SQL Managed Instance

本快速入门介绍如何配置 Azure 虚拟机,以使用 SQL Server Management Studio (SSMS) 连接到 Azure SQL 托管实例。This quickstart shows you how to configure an Azure virtual machine to connect to Azure SQL Managed Instance using SQL Server Management Studio (SSMS).

如需介绍如何使用点到站点连接从本地客户端计算机进行连接的快速入门,请参阅配置点到站点连接For a quickstart showing how to connect from an on-premises client computer using a point-to-site connection instead, see Configure a point-to-site connection.

先决条件Prerequisites

本快速入门从创建托管实例中创建的资源着手。This quickstart uses the resources created in Create a managed instance as its starting point.

登录到 Azure 门户Sign in to the Azure portal

登录到 Azure 门户Sign in to the Azure portal.

创建新的子网 VNetCreate a new subnet VNet

以下步骤在 SQL 托管实例 VNet 中创建新的子网,以便 Azure 虚拟机能够连接到托管实例。The following steps create a new subnet in the SQL Managed Instance VNet so an Azure virtual machine can connect to the managed instance. SQL 托管实例子网专用于托管实例。The SQL Managed Instance subnet is dedicated to managed instances. 不能在该子网中创建任何其他的资源(例如 Azure 虚拟机)。You can't create any other resources, like Azure virtual machines, in that subnet.

  1. 打开在创建托管实例快速入门中创建的托管实例的资源组。Open the resource group for the managed instance that you created in the Create a managed instance quickstart. 为托管实例选择虚拟网络。Select the virtual network for your managed instance.

    SQL 托管实例资源

  2. 选择“子网”,然后选“+ 子网”择,以便创建新的子网。Select Subnets and then select + Subnet to create a new subnet.

    SQL 托管实例子网

  3. 根据此表中的信息填充窗体:Fill out the form using the information in this table:

    设置Setting 建议的值Suggested value 说明Description
    名称Name 任何有效的名称Any valid name 请参阅命名规则和限制,了解什么是有效的名称。For valid names, see Naming rules and restrictions.
    地址范围(CIDR 块)Address range (CIDR block) 有效的范围A valid range 默认值适用于本快速入门。The default value is good for this quickstart.
    网络安全组Network security group None 默认值适用于本快速入门。The default value is good for this quickstart.
    路由表Route table None 默认值适用于本快速入门。The default value is good for this quickstart.
    服务终结点Service endpoints 已选择 00 selected 默认值适用于本快速入门。The default value is good for this quickstart.
    子网委派Subnet delegation None 默认值适用于本快速入门。The default value is good for this quickstart.

    客户端 VM 的新 SQL 托管实例子网

  4. 选择“确定”,在 SQL 托管实例 VNet 中创建这个额外的子网。Select OK to create this additional subnet in the SQL Managed Instance VNet.

在新的子网中创建 VMCreate a VM in the new subnet

以下步骤说明如何在新的子网中创建虚拟机,以连接到 SQL 托管实例。The following steps show you how to create a virtual machine in the new subnet to connect to SQL Managed Instance.

准备 Azure 虚拟机Prepare the Azure virtual machine

由于 SQL 托管实例放置在专用虚拟网络中,因此需创建一个 Azure VM,其中需安装 SQL 客户端工具(例如 SQL Server Management Studio 或 Azure Data Studio)。Since SQL Managed Instance is placed in your private virtual network, you need to create an Azure VM with an installed SQL client tool, like SQL Server Management Studio or Azure Data Studio. 可以通过此工具连接到 SQL 托管实例并执行查询。This tool lets you connect to SQL Managed Instance and execute queries. 本快速入门使用 SQL Server Management Studio。This quickstart uses SQL Server Management Studio.

若要使用所有必需的工具创建一个客户端虚拟机,最容易的方式是使用 Azure 资源管理器模板。The easiest way to create a client virtual machine with all necessary tools is to use the Azure Resource Manager templates.

  1. 确保在另一浏览器标签页中登录到 Azure 门户。然后,选择下面的按钮,创建客户端虚拟机并安装 SQL Server Management Studio:Make sure that you're signed in to the Azure portal in another browser tab. Then, select the following button to create a client virtual machine and install SQL Server Management Studio:

    图像显示标记为“部署到 Azure”的按钮。Image showing a button labeled "Deploy to Azure".

  2. 根据下表中的信息填充窗体:Fill out the form using the information in the following table:

    设置Setting 建议的值Suggested value 描述Description
    订阅Subscription 有效的订阅A valid subscription 必须是有权在其中创建新资源的订阅。Must be a subscription in which you have permission to create new resources.
    资源组Resource Group 创建 SQL 托管实例快速入门中指定的资源组The resource group that you specified in the Create SQL Managed Instance quickstart 此资源组必须是 VNet 所在的资源组。This resource group must be the one in which the VNet exists.
    位置Location 资源组的位置The location for the resource group 此值基于所选资源组进行填充。This value is populated based on the resource group selected.
    虚拟机名称Virtual machine name 任何有效的名称Any valid name 请参阅命名规则和限制,了解什么是有效的名称。For valid names, see Naming rules and restrictions.
    管理员用户名Admin Username 任何有效的用户名Any valid username 请参阅命名规则和限制,了解什么是有效的名称。For valid names, see Naming rules and restrictions. 不要使用“serveradmin”,因为这是保留的服务器级角色。Don't use "serveradmin" as that is a reserved server-level role.
    连接到 VM 时使用此用户名。You use this username any time you connect to the VM.
    密码Password 任何有效的密码Any valid password 密码必须至少 12 个字符长,且符合定义的复杂性要求The password must be at least 12 characters long and meet the defined complexity requirements.
    连接到 VM 时使用此密码。You use this password any time you connect to the VM.
    虚拟机大小Virtual Machine Size 任何有效的大小Any valid size 此模板中的默认值 Standard_B2s 足以满足本快速入门的要求。The default in this template of Standard_B2s is sufficient for this quickstart.
    位置Location [resourceGroup().location]。[resourceGroup().location]. 请勿更改此值。Don't change this value.
    虚拟网络名称Virtual Network Name 在其中创建了托管实例的虚拟网络The virtual network in which you created the managed instance
    子网名称Subnet name 在前述过程中创建的子网的名称The name of the subnet that you created in the previous procedure 请勿选择在其中创建了托管实例的子网。Don't choose the subnet in which you created the managed instance.
    项目位置artifacts Location [deployment().properties.templateLink.uri][deployment().properties.templateLink.uri] 请勿更改此值。Don't change this value.
    项目位置 Sas 令牌artifacts Location Sas token 留空Leave blank 请勿更改此值。Don't change this value.

    创建客户端 VM

    如果使用了在创建 SQL 托管实例中建议的 VNet 名称和默认子网,则不需更改后两个参数。If you used the suggested VNet name and the default subnet in creating your SQL Managed Instance, you don't need to change last two parameters. 否则,应将这些值更改为设置网络环境时输入的值。Otherwise you should change these values to the values that you entered when you set up the network environment.

  3. 选择“我同意上述条款和条件”复选框。Select the I agree to the terms and conditions stated above checkbox.

  4. 选择“购买”,在网络中部署 Azure VM。Select Purchase to deploy the Azure VM in your network.

  5. 选择“通知”图标,查看部署的状态。Select the Notifications icon to view the status of deployment.

重要

创建虚拟机后约 15 分钟内,不要继续操作,以便创建后脚本有时间来安装 SQL Server Management Studio。Do not continue until approximately 15 minutes after the virtual machine is created to give time for the post-creation scripts to install SQL Server Management Studio.

连接到虚拟机Connect to the virtual machine

以下步骤说明如何通过远程桌面连接连接到新创建的虚拟机。The following steps show you how to connect to your newly created virtual machine using a Remote Desktop connection.

  1. 部署完成后,转到虚拟机资源。After deployment completes, go to the virtual machine resource.

    VM

  2. 选择“连接” 。Select Connect.

    此时会显示远程桌面协议文件(.rdp 文件)窗体,其中包含虚拟机的公共 IP 地址和端口号。A Remote Desktop Protocol file (.rdp file) form appears with the public IP address and port number for the virtual machine.

    RDP 窗体

  3. 选择“下载 RDP 文件”。Select Download RDP File.

    备注

    也可使用 SSH 连接到 VM。You can also use SSH to connect to your VM.

  4. 关闭“连接到虚拟机”窗体。Close the Connect to virtual machine form.

  5. 若要连接到 VM,请打开下载的 RDP 文件。To connect to your VM, open the downloaded RDP file.

  6. 出现提示时,选择“连接”。When prompted, select Connect. 在 Mac 上,需要一个 RDP 客户端,例如 Mac App Store 提供的这个远程桌面客户端On a Mac, you need an RDP client such as this Remote Desktop Client from the Mac App Store.

  7. 输入在创建虚拟机时指定的用户名和密码,然后选择“确定”。Enter the username and password you specified when creating the virtual machine, and then choose OK.

  8. 你可能会在登录过程中收到证书警告。You might receive a certificate warning during the sign-in process. 选择“是”或“继续”以继续连接。 Choose Yes or Continue to proceed with the connection.

已连接到“服务器管理器”仪表板中的虚拟机。You're connected to your virtual machine in the Server Manager dashboard.

连接到 SQL 托管实例Connect to SQL Managed Instance

  1. 在虚拟机中,打开 SQL Server Management Studio。In the virtual machine, open SQL Server Management Studio.

    需要一些时间才能打开,因为这是第一次启动 SSMS,因此需要完成其配置。It takes a few moments to open, as it needs to complete its configuration since this is the first time SSMS has been started.

  2. 在“连接到服务器”对话框的“服务器名称”框中,输入托管实例的完全限定的“主机名” 。In the Connect to Server dialog box, enter the fully qualified host name for your managed instance in the Server name box. 选择“SQL Server 身份验证”,提供用户名和密码,然后选择“连接”。 Select SQL Server Authentication, provide your username and password, and then select Connect.

    SSMS 连接

连接后,可以在“数据库”节点中查看系统和用户数据库,以及在“安全性”、“服务器对象”、“复制”、“管理”、“SQL Server 代理”和“XEvent 探查器”节点中查看各种对象。After you connect, you can view your system and user databases in the Databases node, and various objects in the Security, Server Objects, Replication, Management, SQL Server Agent, and XEvent Profiler nodes.

后续步骤Next steps