教程:将 Azure SQL 数据库弹性池添加到故障转移组Tutorial: Add an Azure SQL Database elastic pool to a failover group

适用于: Azure SQL 数据库

使用 Azure 门户为 Azure SQL 数据库弹性池配置故障转移组并测试故障转移。Configure a failover group for an Azure SQL Database elastic pool and test failover using the Azure portal. 在本教程中,您将学习如何执行以下操作:In this tutorial, you will learn how to:

  • 创建单一数据库。Create a single database.
  • 将数据库添加到弹性池中。Add the database to an elastic pool.
  • 在两个服务器之间创建两个弹性池的故障转移组Create a failover group for two elastic pools between two servers.
  • 测试故障转移。Test failover.

先决条件Prerequisites

若要完成本教程,请确保做好以下准备:To complete this tutorial, make sure you have:

1 - 创建单一数据库1 - Create a single database

在此步骤中,你将创建逻辑 SQL 服务器和使用 AdventureWorksLT 示例数据的单一数据库In this step, you create a logical SQL server and a single database that uses AdventureWorksLT sample data. 可以通过使用 Azure 门户菜单和屏幕,或通过使用 Azure CLI 或 PowerShell 脚本来创建数据库。You can create the database by using Azure portal menus and screens, or by using an Azure CLI or PowerShell script.

所有方法都包括设置服务器级防火墙规则,以允许用于访问服务器的计算机的公共 IP 地址。All the methods include setting up a server-level firewall rule to allow the public IP address of the computer you're using to access the server. 有关创建服务器级防火墙规则的详细信息,请参阅创建服务器级防火墙For more information about creating server-level firewall rules, see Create a server-level firewall. 还可以设置数据库级防火墙规则。You can also set database-level firewall rules. 请参阅创建数据库级防火墙规则See Create a database-level firewall rule.

若要在 Azure 门户中创建资源组、服务器和单一数据库,请执行以下操作:To create a resource group, server, and single database in the Azure portal:

  1. 登录门户Sign in to the portal.

  2. 在搜索栏中,搜索并选择“SQL 数据库”。From the Search bar, search for and select SQL database.

  3. 选择“创建” 。Select Create.

    创建单一数据库

  4. 在“创建 SQL 数据库”窗体的“基本信息”选项卡上的“项目详细信息”下,选择正确的 Azure订阅(如果尚未选择)。On the Basics tab of the Create SQL database form, under Project details, select the correct Azure Subscription if it isn't already selected.

  5. 在“资源组”下选择“新建”,输入“MyResourceGroup”,然后选择“确定” 。Under Resource group, select Create new, enter myResourceGroup, and select OK.

  6. 在“数据库详细信息”下,为“数据库名称”输入“mySampleDatabase”。Under Database details, for Database name enter mySampleDatabase.

  7. 对于“服务器”,选择“新建”,并按如下所示在“新服务器”窗体中填写信息:For Server, select Create new, and fill out the New server form as follows:

    • 服务器名称:输入“mysqlserver”和一些字符以实现唯一性。Server name: Enter mysqlserver, and some characters for uniqueness.
    • 服务器管理员登录名:输入“azureuser”。Server admin login: Enter azureuser.
    • 密码:输入符合要求的密码,然后在“确认密码”字段中再次输入该密码。Password: Enter a password that meets requirements, and enter it again in the Confirm password field.
    • 位置:单击下拉箭头并选择一个位置,例如“中国东部 2”。Location: Drop down and choose a location, such as China East 2.

    选择“确定” 。Select OK.

    新建服务器

    请记录服务器管理员登录名和密码,以便可以登录服务器及其数据库。Record the server admin login and password so you can log in to the server and its databases. 如果忘记了登录名或密码,那么在数据库创建之后,可在“SQL 服务器”页上获取登录名或重置密码。If you forget your login or password, you can get the login name or reset the password on the SQL server page after database creation. 若要打开“SQL 服务器”页,请在数据库“概述”页上选择服务器名称 。To open the SQL server page, select the server name on the database Overview page.

  8. 在“计算 + 存储”下,若要重新配置默认值,请选择“配置数据库”。Under Compute + storage, if you want to reconfigure the defaults, select Configure database.

    在“配置”页上,可以选择:On the Configure page, you can optionally:

    • 将“计算层”从“预配”更改为“无服务器”。Change the Compute tier from Provisioned to Serverless.
    • 查看并更改“Vcore”和“数据最大大小”设置 。Review and change the settings for vCores and Data max size.
    • 选择“更改配置”来更改硬件代系。Select Change configuration to change the hardware generation.

    进行更改后,请选择“应用”。After making any changes, select Apply.

  9. 在完成时选择“下一步:网络”。Select Next: Networking at the bottom of the page.

    新建 SQL 数据库 -“基本信息”选项卡

  10. 在“网络”选项卡上的“连接方法”下,选择“公共终结点”。On the Networking tab, under Connectivity method, select Public endpoint.

  11. 在“防火墙规则”下,将“添加当前客户端 IP 地址”设置为“是”。Under Firewall rules, set Add current client IP address to Yes.

  12. 在完成时选择“下一步:其他设置”。Select Next: Additional settings at the bottom of the page.

    “网络”选项卡

    有关防火墙设置的详细信息,请参阅允许 Azure 服务和资源访问此服务器添加专用终结点For more information about firewall settings, see Allow Azure services and resources to access this server and Add a private endpoint.

  13. 在“其他设置”选项卡上的“数据源”部分中,对于“使用现有数据”,请选择“示例”。On the Additional settings tab, in the Data source section, for Use existing data, select Sample.

  14. (可选)启用 Azure Defender for SQLOptionally, enable Azure Defender for SQL.

  15. 在页面底部选择“查看 + 创建”。Select Review + create at the bottom of the page.

    “其他设置”选项卡

  16. 查看设置后,选择“创建”。After reviewing settings, select Create.

2 - 将数据库添加到弹性池中2 - Add the database to an elastic pool

在此步骤中,我们将创建一个弹性池并向其添加数据库。In this step, you will create an elastic pool and add your database to it.

使用 Azure 门户创建弹性池。Create your elastic pool using the Azure portal.

  1. 在搜索框中键入 elastic pool,按 Enter,选择“SQL 弹性数据库池”图标,然后选择“创建”。 Type elastic pool in the search box, press enter, select the SQL Elastic database pool icon, and then select Create.

    选择弹性池

  2. 使用以下值配置弹性池:Configure your elastic pool with the following values:

    • 名称:提供弹性池的唯一名称,例如 myElasticPoolName: Provide a unique name for your elastic pool, such as myElasticPool.

    • 订阅:从下拉列表中选择订阅。Subscription: Select your subscription from the drop-down.

    • ResourceGroup:从下拉菜单中选择在第 1 部分创建的资源组 myResourceGroupResourceGroup: Select myResourceGroup from the drop-down, the resource group you created in section 1.

    • 服务器:从下拉菜单中选择在第 1 部分创建的服务器。Server: Select the server you created in section 1 from the drop-down.

      为弹性池创建新服务器

    • 计算 + 存储:选择“配置弹性池”以配置计算和存储,并将单一数据库添加到弹性池中。Compute + storage: Select Configure elastic pool to configure your compute, storage, and add your single database to your elastic pool. 在“池设置”选项卡上,保留默认值“第 5 代”、2 个 vCore 和 32GB 存储。On the Pool Settings tab, leave the default of Gen5, with 2 vCores and 32gb.

  3. 在“配置”页上选择“数据库”选项卡,然后选择“添加数据库”。 On the Configure page, select the Databases tab, and then choose to Add database. 选择在第 1 部分创建的数据库,然后选择“应用”将其添加到弹性池中。Choose the database you created in section 1 and then select Apply to add it to your elastic pool. 再次选择“应用”以应用弹性池设置并关闭“配置”页。 Select Apply again to apply your elastic pool settings and close the Configure page.

    将数据库添加到弹性池

  4. 选择“查看 + 创建”以检查弹性池设置,然后选择“创建”以创建弹性池。 Select Review + create to review your elastic pool settings and then select Create to create your elastic pool.

3 - 创建故障转移组3 - Create the failover group

此步骤在现有的服务器与另一区域中的新服务器之间创建一个故障转移组In this step, you will create a failover group between an existing server and a new server in another region. 然后,将弹性池添加到该故障转移组。Then add the elastic pool to the failover group.

使用 Azure 门户创建故障转移组。Create your failover group using the Azure portal.

  1. Azure 门户的左侧菜单中选择“所有服务”,然后选择“SQL 弹性池”。Select All services in the left-hand menu of the Azure portal, then select SQL elastic pools.

  2. 选择在上一部分中创建的弹性池,例如 myElasticPoolSelect the elastic pool created in the previous section, such as myElasticPool.

  3. 在“概述”窗格上,选择 服务器名称 下的服务器名称以打开服务器的设置。On the Overview pane, select the name of the server under Server name to open the settings for the server.

    打开弹性池的服务器

  4. 在“设置”窗格下选择“故障转移组”,然后选择“添加组”以创建新的故障转移组。 Select Failover groups under the Settings pane, and then select Add group to create a new failover group.

    添加新的故障转移组

  5. 在“故障转移组”页上输入或选择以下值,然后选择“创建”: On the Failover Group page, enter or select the following values, and then select Create:

    • 故障转移组名称:键入唯一的故障转移组名称,例如 failovergrouptutorialFailover group name: Type in a unique failover group name, such as failovergrouptutorial.

    • 辅助服务器:选择“配置所需设置”选项,然后选择“创建新服务器”。Secondary server: Select the option to configure required settings and then choose to Create a new server. 或者,可以选择现有的服务器作为辅助服务器。Alternatively, you can choose an already-existing server as the secondary server. 为新的辅助服务器输入以下值之后,选择“选择”。After entering the following values for your new secondary server, select Select.

      • 服务器名称:键入辅助服务器的唯一名称,例如 mysqlsecondaryServer name: Type in a unique name for the secondary server, such as mysqlsecondary.
      • 服务器管理员登录名:键入 azureuserServer admin login: Type azureuser
      • 密码:键入符合密码要求的复杂密码。Password: Type a complex password that meets password requirements.
      • 位置:从下拉列表中选择一个位置,例如“中国北部 2”。Location: Choose a location from the drop-down, such as China North 2. 此位置不能与主服务器的位置相同。This location cannot be the same location as your primary server.

      备注

      服务器登录名和防火墙设置必须与主服务器相匹配。The server login and firewall settings must match that of your primary server.

      为故障转移组创建辅助服务器

  6. 选择“组中的数据库”,然后选择在第 2 部分创建的弹性池。Select Databases within the group then select the elastic pool you created in section 2. 此时应会出现一条警告,提示你将在辅助服务器上创建弹性池。A warning should appear, prompting you to create an elastic pool on the secondary server. 选择该警告,然后选择“确定”以在辅助服务器上创建弹性池。Select the warning, and then select OK to create the elastic pool on the secondary server.

    将弹性池添加到故障转移组中

  7. 选择“选择”以将弹性池设置应用到故障转移组,然后选择“创建”以创建故障转移组。 Select Select to apply your elastic pool settings to the failover group, and then select Create to create your failover group. 将弹性池添加到故障转移组的操作会自动启动异地复制过程。Adding the elastic pool to the failover group will automatically start the geo-replication process.

4 - 测试故障转移4 - Test failover

此步骤将故障转移组故障转移到辅助服务器,然后使用 Azure 门户故障回复。In this step, you will fail your failover group over to the secondary server, and then fail back using the Azure portal.

使用 Azure 门户测试故障转移组的故障转移。Test failover of your failover group using the Azure portal.

  1. 登录 Azure 门户Sign in Azure portal.

  2. 选择在上一部分中创建的弹性池,例如 myElasticPoolSelect the elastic pool created in the previous section, such as myElasticPool.

  3. 服务器名称 下选择服务器的名称以打开服务器的设置。Select the name of the server under Server name to open the settings for the server.

    打开弹性池的服务器

  4. 在“设置”窗格下选择“故障转移组”,然后选择在第 2 部分创建的故障转移组。 Select Failover groups under the Settings pane and then choose the failover group you created in section 2.

    在门户中选择故障转移组

  5. 查看哪个服务器是主服务器,哪个服务器是辅助服务器。Review which server is primary, and which server is secondary.

  6. 在“任务”窗格中选择“故障转移”,以故障转移包含弹性池的故障转移组。Select Failover from the task pane to fail over your failover group containing your elastic pool.

  7. 在告知将会断开 TDS 会话连接的警告中选择“是”。Select Yes on the warning that notifies you that TDS sessions will be disconnected.

    对包含数据库的故障转移组进行故障转移

  8. 查看哪个服务器是主服务器,哪个服务器是辅助服务器。Review which server is primary, which server is secondary. 如果故障转移成功,这两个服务器的角色应会交换。If failover succeeded, the two servers should have swapped roles.

  9. 再次选择“故障转移”,将故障转移组故障回复到原始设置。Select Failover again to fail the failover group back to the original settings.

清理资源Clean up resources

通过删除资源组来清理资源。Clean up resources by deleting the resource group.

  1. Azure 门户中导航到你的资源组。Navigate to your resource group in the Azure portal.
  2. 选择“删除资源组”即可删除该资源组中的所有资源以及该组本身。Select Delete resource group to delete all the resources in the group, as well as the resource group itself.
  3. 在文本框中键入资源组的名称 myResourceGroup,然后选择“删除”以删除该资源组。Type the name of the resource group, myResourceGroup, in the textbox, and then select Delete to delete the resource group.

重要

若要保留资源组但删除辅助数据库,请先将其从故障转移组中移除,然后再将其删除。If you want to keep the resource group but delete the secondary database, remove it from the failover group before deleting it. 如果在从故障转移组中移除辅助数据库之前将其删除,则可能会导致不可预知的行为。Deleting a secondary database before it is removed from the failover group can cause unpredictable behavior.

完整脚本Full script

没有适用于 Azure 门户的脚本。There are no scripts available for the Azure portal.

后续步骤Next steps

在本教程中,你已将一个 Azure SQL 数据库弹性池添加到故障转移组,并测试了故障转移。In this tutorial, you added an Azure SQL Database elastic pool to a failover group, and tested failover. 你已了解如何:You learned how to:

  • 创建单一数据库。Create a single database.
  • 将数据库添加到弹性池中。Add the database into an elastic pool.
  • 在两个服务器之间创建两个弹性池的故障转移组Create a failover group for two elastic pools between two servers.
  • 测试故障转移。Test failover.

转到下一教程,其中介绍了如何使用 DMS 进行迁移。Advance to the next tutorial on how to migrate using DMS.