教程:为 IoT 中心执行手动故障转移Tutorial: Perform manual failover for an IoT hub

手动故障转移是 IoT 中心服务的一项功能,允许客户将其中心的操作从主要区域故障转移到相应的 Azure 异地配对区域。Manual failover is a feature of the IoT Hub service that allows customers to failover their hub's operations from a primary region to the corresponding Azure geo-paired region. 在出现区域性灾难或者服务中断时间延长的情况下,可以进行手动故障转移。Manual failover can be done in the event of a regional disaster or an extended service outage. 也可通过执行计划内故障转移来测试灾难恢复功能,虽然我们建议使用测试性 IoT 中心而不是在生产环境中运行的 IoT 中心。You can also perform a planned failover to test your disaster recovery capabilities, although we recommend using a test IoT hub rather than one running in production. 提供给客户的手动故障转移功能不另外收费。The manual failover feature is offered to customers at no additional cost.

将在本教程中执行以下任务:In this tutorial, you perform the following tasks:

  • 使用 Azure 门户创建 IoT 中心。Using the Azure portal, create an IoT hub.
  • 执行故障转移。Perform a failover.
  • 查看在辅助位置运行的中心。See the hub running in the secondary location.
  • 执行故障回复,让 IoT 中心的操作返回到主位置。Perform a failback to return the IoT hub's operations to the primary location.
  • 确认中心在正确的位置正确运行。Confirm the hub is running correctly in the right location.

先决条件Prerequisites

  • Azure 订阅。An Azure subscription. 如果没有 Azure 订阅,可在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.
  • 确保已在防火墙中打开端口 8883。Make sure that port 8883 is open in your firewall. 本教程中的设备示例使用 MQTT 协议,该协议通过端口 8883 进行通信。The device sample in this tutorial uses MQTT protocol, which communicates over port 8883. 在某些公司和教育网络环境中,此端口可能被阻止。This port may be blocked in some corporate and educational network environments. 有关解决此问题的更多信息和方法,请参阅连接到 IoT 中心(MQTT)For more information and ways to work around this issue, see Connecting to IoT Hub (MQTT).

创建 IoT 中心Create an IoT hub

  1. 登录到 Azure 门户Log into the Azure portal.

  2. 单击“+ 创建资源”,选择“物联网”,然后选择“IoT 中心”。 Click + Create a resource and select Internet of Things, then IoT Hub.

    显示正在创建 IoT 中心的屏幕截图

  3. 选择“基本信息” 选项卡。在以下字段中进行填充。Select the Basics tab. Fill in the following fields.

    订阅:选择要使用的 Azure 订阅。Subscription: select the Azure subscription you want to use.

    资源组:单击“新建”,指定“ManlFailRG”作为资源组名称。 Resource Group: click Create new and specify ManlFailRG for the resource group name.

    区域:选择离你近的区域。Region: select a region close to you. 本教程使用 chinaeastThis tutorial uses chinaeast. 只能在 Azure 异地配对区域之间执行故障转移。A failover can only be performed between Azure geo-paired regions. 与 chinaeast 异地配对的区域是 chinanorth。The region geo-paired with chinaeast is chinanorth.

    Iot 中心名称:指定 IoT 中心的名称。IoT Hub Name: specify a name for your Iot hub. 该中心名称必须在全局中独一无二。The hub name must be globally unique.

    显示用于创建 IoT 中心的“基本信息”窗格的屏幕截图

    单击“查看 + 创建” 。Click Review + create. (它使用大小和规模的默认值。)(It uses the defaults for size and scale.)

  4. 查看信息,然后单击“创建”以创建 IoT 中心。 Review the information, then click Create to create the IoT hub.

    显示用于创建 IoT 中心的最后步骤的屏幕截图

执行手动故障转移Perform a manual failover

请注意,一个 IoT 中心每天的限制是两次故障转移和两次故障回复。Note that there is a limit of two failovers and two failbacks per day for an IoT hub.

  1. 单击“资源组”,然后选择资源组“ManlFailRG” 。Click Resource groups and then select the resource group ManlFailRG. 在资源列表中单击你的中心。Click on your hub in the list of resources.

  2. 在 IoT Hub 窗格上的“设置” 下,单击“故障转移” 。Under Settings on the IoT Hub pane, click Failover.

    显示 IoT 中心属性窗格的屏幕截图

  3. 在“手动故障转移”窗格上,可以看到当前位置故障转移位置On the Manual failover pane, you see the Current Location and the Failover Location. 当前位置始终指示中心当前处于活动状态的位置。The current location always indicates the location in which the hub is currently active. 故障转移位置是标准的 Azure 异地配对区域,与当前位置配对。The failover location is the standard Azure geo-paired region that is paired to the current location. 不能更改位置值。You cannot change the location values. 在本教程中,当前位置为 chinaeast,故障转移位置为 chinanorthFor this tutorial, the current location is chinaeast and the failover location is chinanorth.

    显示“手动故障转移”窗格的屏幕截图

  4. 在“手动故障转移”窗格顶部单击“启动故障转移”。 At the top of the Manual failover pane, click Start failover.

  5. 在“确认”窗格中填充 IoT 中心的名称,确认是它需要故障转移。In the confirmation pane, fill in the name of your IoT hub to confirm it's the one you want to failover. 然后,若要启动故障转移,请单击“故障转移” 。Then, to initiate the failover, click Failover.

    执行手动故障转移所需时间与中心的已注册设备数成正比。The amount of time it takes to perform the manual failover is proportional to the number of devices that are registered for your hub. 例如,如果有 1 百万台设备,可能需要 15 分钟,但如果有 5 百万台设备,则可能需要 1 小时或更长的时间。For example, if you have 100,000 devices, it might take 15 minutes, but if you have five million devices, it might take an hour or longer.

    显示“手动故障转移”窗格的屏幕截图

    在手动故障转移进程正在运行时,会显示一个横幅,告诉你正在进行手动故障转移。While the manual failover process is running, a banner appears to tell you a manual failover is in progress.

    显示手动故障转移正在进行的屏幕截图

    如果在关闭“IoT 中心”窗格后又在“资源组”窗格中通过单击来打开它,则会看到一个横幅,告诉你该中心正在进行手动故障转移。If you close the IoT Hub pane and open it again by clicking it on the Resource Group pane, you see a banner that tells you the hub is in the middle of a manual failover.

    显示 IoT 中心正在进行故障转移的屏幕截图

    故障转移完成后,“手动故障转移”页上的当前区域和故障转移区域会互换,中心重新处于活动状态。After it's finished, the current and failover regions on the Manual Failover page are flipped and the hub is active again. 在本示例中,当前位置现在为 chinaeast,故障转移位置现在为 chinanorthIn this example, the current location is now chinaeast and the failover location is now chinanorth.

    显示故障转移已完成的屏幕截图

    “概述”页还显示一个横幅,指示故障转移已完成,并且 IoT 中心正在 China East 中运行。The overview page also shows a banner indicating that the failover complete and the IoT Hub is running in China East.

    “概述”页中显示故障转移已完成的屏幕截图

执行故障回复Perform a failback

执行手动故障转移以后,可以将中心的操作切换回原始的主要区域 -- 这称为故障回复。After you have performed a manual failover, you can switch the hub's operations back to the original primary region -- this is called a failback. 如果刚执行故障转移,则需等待大约一小时,然后才能请求故障回复。If you have just performed a failover, you have to wait about an hour before you can request a failback. 如果尝试在比这更短的时间内执行故障回复,则会显示错误消息。If you try to perform the failback in a shorter amount of time, an error message is displayed.

故障回复的执行方式与手动故障转移一样。A failback is performed just like a manual failover. 下面是步骤:These are the steps:

  1. 若要执行故障回复,请返回到 Iot 中心的“Iot 中心”窗格。To perform a failback, return to the Iot Hub pane for your Iot hub.

  2. 在 IoT Hub 窗格上的“设置” 下,单击“故障转移” 。Under Settings on the IoT Hub pane, click Failover.

  3. 在“手动故障转移”窗格顶部单击“启动故障转移”。 At the top of the Manual failover pane, click Start failover.

  4. 在“确认”窗格中填充 IoT 中心的名称,确认是它需要故障回复。In the confirmation pane, fill in the name of your IoT hub to confirm it's the one you want to failback. 然后,若要启动故障回复,请单击“确定”。To then initiate the failback, click OK.

    手动故障回复请求的屏幕截图

    横幅会如执行故障转移部分所述一样显示。The banners are displayed as explained in the perform a failover section. 故障回复完成之后,它会再次将 chinaeast 显示为当前位置,将 chinanorth 显示为故障转移位置,就像初始设置的一样。After the failback is complete, it again shows chinaeast as the current location and chinanorth as the failover location, as set originally.

清理资源Clean up resources

若要删除为本教程创建的资源,请删除资源组。To remove the resources you've created for this tutorial, delete the resource group. 此操作会一并删除组中包含的所有资源。This action deletes all resources contained within the group. 在本示例中,它会删除 IoT 中心和资源组本身。In this case, it removes the IoT hub and the resource group itself.

  1. 单击“资源组”。 Click Resource Groups.

  2. 找到并选择资源组“ManlFailRG”。 Locate and select the resource group ManlFailRG. 单击可将其打开。Click on it to open it.

  3. 单击“删除资源组”。 Click Delete resource group. 系统提示时,请输入资源组的名称,然后单击“删除”进行确认 。When prompted, enter the name of the resource group and click Delete to confirm.

后续步骤Next steps

本教程介绍了如何执行以下任务,以便配置并执行手动故障转移以及请求故障回复:In this tutorial, you learned how to configure and perform a manual failover, and how to request a failback by performing the following tasks:

  • 使用 Azure 门户创建 IoT 中心。Using the Azure portal, create an IoT hub.
  • 执行故障转移。Perform a failover.
  • 查看在辅助位置运行的中心。See the hub running in the secondary location.
  • 执行故障回复,让 IoT 中心的操作返回到主位置。Perform a failback to return the IoT hub's operations to the primary location.
  • 确认中心在正确的位置正确运行。Confirm the hub is running correctly in the right location.

转到下一教程,了解如何管理 IoT 设备的状态。Advance to the next tutorial to learn how to manage the state of an IoT device.