Azure SQL 数据库的 DNS 别名DNS alias for Azure SQL Database

Azure SQL 数据库有一个域名系统 (DNS) 服务器。Azure SQL Database has a Domain Name System (DNS) server. PowerShell 和 REST API 允许使用相应的调用来创建和管理 SQL 数据库服务器的别名PowerShell and REST APIs accept calls to create and manage DNS aliases for your SQL Database server name.

可以使用 DNS 别名来取代 Azure SQL 数据库服务器名称。A DNS alias can be used in place of the Azure SQL Database server name. 客户端程序可在其连接字符串中使用别名。Client programs can use the alias in their connection strings. DNS 别名提供一个转换层,用于将客户端程序重定向到不同的服务器。The DNS alias provides a translation layer that can redirect your client programs to different servers. 使用此层无需查找和编辑所有客户端及其连接字符串,因此降低了复杂性。This layer spares you the difficulties of having to find and edit all the clients and their connection strings.

DNS 别名的常见用途包括:Common uses for a DNS alias include the following cases:

  • 为 Azure SQL Server 创建易记的名称。Create an easy to remember name for an Azure SQL Server.
  • 在初始开发期间,别名可以引用测试 SQL 数据库服务器。During initial development, your alias can refer to a test SQL Database server. 应用程序上线后,你可以修改别名以引用生产服务器。When the application goes live, you can modify the alias to refer to the production server. 从测试到生产的转换不需要对连接到数据库服务器的多个客户端的配置进行任何修改。The transition from test to production does not require any modification to the configurations several clients that connect to the database server.
  • 假设只将应用程序中的唯一数据库移到了另一个 SQL 数据库服务器。Suppose the only database in your application is moved to another SQL Database server. 此时,可以修改别名,而无需修改多个客户端的配置。Here you can modify the alias without having to modify the configurations of several clients.

Internet 的域名系统 (DNS)Domain Name System (DNS) of the Internet

Internet 依赖于 DNS。The Internet relies on the DNS. DNS 将友好名称转换为 Azure SQL 数据库服务器的名称。The DNS translates your friendly names into the name of your Azure SQL Database server.

使用一个 DNS 别名的方案Scenarios with one DNS alias

假设你需要将系统切换到新的 Azure SQL 数据库服务器。Suppose you need to switch your system to a new Azure SQL Database server. 在过去,需要查找并更新每个客户端程序中的每个连接字符串。In the past you needed to find and update every connection string in every client program. 而现在,如果连接字符串使用 DNS 别名,则只需更新别名属性。But now, if the connection strings use a DNS alias, only an alias property must be updated.

Azure SQL 数据库的 DNS 别名功能有助于实现以下方案:The DNS alias feature of Azure SQL Database can help in the following scenarios:

测试到生产Test to production

在开始开发客户端程序时,可让这些程序在其连接字符串中使用 DNS 别名。When you start developing the client programs, have them use a DNS alias in their connection strings. 将别名属性指向 Azure SQL 数据库服务器的测试版本。You make the properties of the alias point to a test version of your Azure SQL Database server.

以后,当有新的系统在生产环境中上线时,可将别名属性更新为指向生产 SQL 数据库服务器。Later when the new system goes live in production, you can update the properties of the alias to point to the production SQL Database server. 不需要对客户端程序进行任何更改。No change to the client programs is necessary.

跨区域支持Cross-region support

灾难恢复可将 SQL 数据库服务器转移到不同的地理区域。A disaster recovery might shift your SQL Database server to a different geographic region. 对于使用 DNS 别名的系统,不需要查找并更新所有客户端的所有连接字符串。For a system than was using a DNS alias, the need to find and update all the connection strings for all clients can be avoided. 可将别名更新为引用现在正在托管数据库的新 SQL 数据库服务器。Instead, you can update an alias to refer to the new SQL Database server that now hosts your database.

DNS 别名的属性Properties of a DNS alias

以下属性适用于 SQL 数据库服务器的每个 DNS 别名:The following properties apply to each DNS alias for your SQL Database server:

  • 唯一的名称:像服务器名称一样,创建的每个别名在所有 Azure SQL 数据库服务器上保持唯一。Unique name: Each alias name you create is unique across all Azure SQL Database servers, just as server names are.
  • 需要服务器:除非 DNS 别名恰好引用一个服务器,并且该服务器存在,否则无法创建该别名。Server is required: A DNS alias cannot be created unless it references exactly one server, and the server must already exist. 更新的别名必须始终恰好引用一个现有服务器。An updated alias must always reference exactly one existing server.
    • 删除某个 SQL 数据库服务器时,Azure 系统也会删除引用该服务器的所有 DNS 别名。When you drop a SQL Database server, the Azure system also drops all DNS aliases that refer to the server.
  • 不受限于任一区域:DNS 别名不受限于某一区域。Not bound to any region: DNS aliases are not bound to a region. 可以更新任何 DNS 别名,以引用位于任何地理区域中的 Azure SQL 数据库服务器。Any DNS aliases can be updated to refer to an Azure SQL Database server that resides in any geographic region.
    • 但是,将别名更新为引用另一台服务器时,这两台服务器必须位于同一个 Azure 订阅中。However, when updating an alias to refer to another server, both servers must exist in the same Azure subscription.
  • 权限:管理 DNS 别名的用户必须拥有“服务器参与者”权限或更高权限。Permissions: To manage a DNS alias, the user must have Server Contributor permissions, or higher. 有关详细信息,请参阅 Azure 门户中基于角色的访问控制入门For more information, see Get started with Role-Based Access Control in the Azure portal.

管理 DNS 别名Manage your DNS aliases

可以使用 REST API 和 PowerShell cmdlet 以编程方式管理 DNS 别名。Both REST APIs and PowerShell cmdlets are available to enable you to programmatically manage your DNS aliases.

用于管理 DNS 别名的 REST APIREST APIs for managing your DNS aliases

以下网页中提供了 REST API 的文档:The documentation for the REST APIs is available near the following web location:

另外,GitHub 中也提供了 REST API:Also, the REST APIs can be seen in GitHub at:

用于管理 DNS 别名的 PowerShellPowerShell for managing your DNS aliases

Note

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

Important

PowerShell Azure 资源管理器模块仍受 Azure SQL 数据库的支持,但所有未来的开发都是针对 Az.Sql 模块的。The PowerShell Azure Resource Manager module is still supported by Azure SQL Database, but all future development is for the Az.Sql module. 若要了解这些 cmdlet,请参阅 AzureRM.SqlFor these cmdlets, see AzureRM.Sql. Az 模块和 AzureRm 模块中的命令参数大体上是相同的。The arguments for the commands in the Az module and in the AzureRm modules are substantially identical.

可以使用 PowerShell cmdlet 来调用 REST API。PowerShell cmdlets are available that call the REST APIs.

以下文档介绍了用于管理 DNS 别名的 PowerShell cmdlet 代码示例:A code example of PowerShell cmdlets being used to manage DNS aliases is documented at:

代码示例中使用的 cmdlet 如下:The cmdlets used in the code example are the following:

预览期间的限制Limitations during preview

目前,DNS 别名存在以下限制:Presently, a DNS alias has the following limitations:

  • 延迟最长为 2 分钟:最长需要 2 分钟才能更新或删除 DNS 别名。Delay of up to 2 minutes: It takes up to 2 minutes for a DNS alias to be updated or removed.
    • 不管延迟时间有多短,别名都会使客户端连接立即停止引用旧服务器。Regardless of any brief delay, the alias immediately stops referring client connections to the legacy server.
  • DNS 查找:目前,检查给定 DNS 别名引用哪台服务器的唯一权威方法是执行 DNS 查找DNS lookup: For now, the only authoritative way to check what server a given DNS alias refers to is by performing a DNS lookup.
  • 不支持表审核:在已对数据库上启用表审核的 Azure SQL 数据库服务器上,无法使用 DNS 别名。Table auditing is not supported: You cannot use a DNS alias on an Azure SQL Database server that has table auditing enabled on a database.
    • 表审核已弃用。Table auditing is deprecated.
    • 我们建议改用 Blob 审核We recommend that you move to Blob Auditing.

后续步骤Next steps