教程:升级 Azure 中 Service Fabric 群集的运行时Tutorial: Upgrade the runtime of a Service Fabric cluster in Azure

本教程是四篇系列教程中的一篇,介绍如何升级 Azure Service Fabric 群集上的 Service Fabric 运行时。This tutorial is part four of a series, and shows you how to upgrade the Service Fabric runtime on an Azure Service Fabric cluster. 本教程部分是针对 Azure 上运行的 Service Fabric 群集编写的,不适用于独立 Service Fabric 群集。This tutorial part is written for Service Fabric clusters running on Azure and doesn't apply to standalone Service Fabric clusters.

警告

本教程部分要求使用 PowerShell。This part of the tutorial requires PowerShell. 目前尚不支持使用 Azure CLI 工具升级群集运行时。Support for upgrading the cluster runtime is not yet supported by the Azure CLI tools. 或者,可以在门户中升级群集。Alternatively, a cluster can be upgraded in the portal. 有关详细信息,请参阅升级 Azure Service Fabric 群集For more information, see Upgrade an Azure Service Fabric cluster.

如果群集已在运行最新的 Service Fabric 运行时,则不需要执行此步骤。If your cluster is already running the latest Service Fabric runtime, you don't need to do this step. 但是,可以参考本文在 Azure Service Fabric 群集上安装任何受支持的运行时。However, this article can be used to install any supported runtime on an Azure Service Fabric cluster.

在本教程中,你将了解如何执行以下操作:In this tutorial, you learn how to:

  • 读取群集版本Read the cluster version
  • 设置群集版本Set the cluster version

在此系列教程中,你会学习如何:In this tutorial series you learn how to:

备注

本文进行了更新,以便使用新的 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.

先决条件Prerequisites

在开始学习本教程之前:Before you begin this tutorial:

登录 AzureSign in to Azure

执行 Azure 命令之前,登录到你的 Azure 帐户并选择你的订阅。Sign in to your Azure account select your subscription before you execute Azure commands.

Connect-AzAccount -Environment AzureChinaCloud
Get-AzSubscription
Set-AzContext -SubscriptionId <guid>

获取运行时版本Get the runtime version

连接到 Azure 并选择包含 Service Fabric 群集的订阅之后,可获取群集的运行时版本。After you've connected to Azure, selected the subscription containing the Service Fabric cluster, you can get the runtime version of the cluster.

Get-AzServiceFabricCluster -ResourceGroupName SFCLUSTERTUTORIALGROUP -Name aztestcluster `
    | Select-Object ClusterCodeVersion

或者,直接使用以下示例获取订阅中所有群集的列表:Or, just get a list of all clusters in your subscription with the following example:

Get-AzServiceFabricCluster | Select-Object Name, ClusterCodeVersion

请注意 ClusterCodeVersion 值。Note the ClusterCodeVersion value. 在下一部分需使用此值。This value will be used in the next section.

升级运行时Upgrade the runtime

Get-ServiceFabricRuntimeUpgradeVersion cmdlet 中使用在上一部分获取的 ClusterCodeVersion 值来发现可升级到的版本。Use the value of ClusterCodeVersion from the previous section with the Get-ServiceFabricRuntimeUpgradeVersion cmdlet to discover what versions are available to upgrade to. 只能在已连接到 Internet 的计算机上运行此 cmdlet。This cmdlet can only be run from a computer connected to the internet. 例如,如果想要查看可从版本 5.7.198.9494 升级到哪些运行时版本,请使用以下命令:For example, if you wanted to see what runtime versions you could upgrade to from version 5.7.198.9494, use the following command:

Get-ServiceFabricRuntimeUpgradeVersion -BaseVersion "5.7.198.9494"

使用版本列表,可以让 Azure Service Fabric 群集升级到更新的运行时。With a list of versions, you can tell the Azure Service Fabric cluster to upgrade to a newer runtime. 例如,如果可升级到版本 6.0.219.9494,请使用以下命令升级群集。For example, if version 6.0.219.9494 is available to upgrade to, use the following command to upgrade your cluster.

Set-AzServiceFabricUpgradeType -ResourceGroupName SFCLUSTERTUTORIALGROUP `
                                    -Name aztestcluster `
                                    -UpgradeMode Manual `
                                    -Version "6.0.219.9494"

重要

群集运行时升级可能需要较长时间才能完成。The cluster runtime upgrade may take a long time to complete. 运行升级时,PowerShell 将被阻止。PowerShell is blocked while the upgrade is running. 可以使用另一个 PowerShell 会话来检查升级状态。You can use another PowerShell session to check the status of the upgrade.

可以使用 PowerShell 或 Azure Service Fabric CLI (sfctl) 监视升级状态。The status of the upgrade can be monitored with either PowerShell or the Azure Service Fabric CLI (sfctl).

首先,请使用在本教程第一部分中创建的 TLS/SSL 证书连接到群集。First connect to the cluster with the TLS/SSL certificate created in the first part of the tutorial. 使用 Connect-ServiceFabricCluster cmdlet 或 sfctl cluster upgrade-statusUse the Connect-ServiceFabricCluster cmdlet or sfctl cluster upgrade-status.

$endpoint = "<mycluster>.chinaeast.cloudapp.chinacloudapi.cn:19000"
$thumbprint = "63EB5BA4BC2A3BADC42CA6F93D6F45E5AD98A1E4"

Connect-ServiceFabricCluster -ConnectionEndpoint $endpoint `
                             -KeepAliveIntervalInSec 10 `
                             -X509Credential -ServerCertThumbprint $thumbprint `
                             -FindType FindByThumbprint -FindValue $thumbprint `
                             -StoreLocation CurrentUser -StoreName My
sfctl cluster select --endpoint https://aztestcluster.chinaeast.cloudapp.chinacloudapi.cn:19080 \
--pem ./aztestcluster201709151446.pem --no-verify

接下来,使用 Get-ServiceFabricClusterUpgradesfctl cluster upgrade-status 显示状态。Next, use Get-ServiceFabricClusterUpgrade or sfctl cluster upgrade-status to display the status. 将显示如下所示的结果。Something similar to the following result is shown.

Get-ServiceFabricClusterUpgrade

TargetCodeVersion                          : 6.0.219.9494
TargetConfigVersion                        : 3
StartTimestampUtc                          : 11/28/2017 3:09:48 AM
UpgradeState                               : RollingForwardPending
UpgradeDuration                            : 00:09:00
CurrentUpgradeDomainDuration               : 00:09:00
NextUpgradeDomain                          : 1
UpgradeDomainsStatus                       : { "0" = "Completed";
                                             "1" = "Pending";
                                             "2" = "Pending";
                                             "3" = "Pending";
                                             "4" = "Pending" }
UpgradeKind                                : Rolling
RollingUpgradeMode                         : Monitored
FailureAction                              : Rollback
ForceRestart                               : False
UpgradeReplicaSetCheckTimeout              : 37201.09:59:01
HealthCheckWaitDuration                    : 00:05:00
HealthCheckStableDuration                  : 00:05:00
HealthCheckRetryTimeout                    : 00:45:00
UpgradeDomainTimeout                       : 02:00:00
UpgradeTimeout                             : 12:00:00
ConsiderWarningAsError                     : False
MaxPercentUnhealthyApplications            : 0
MaxPercentUnhealthyNodes                   : 100
ApplicationTypeHealthPolicyMap             : {}
EnableDeltaHealthEvaluation                : True
MaxPercentDeltaUnhealthyNodes              : 0
MaxPercentUpgradeDomainDeltaUnhealthyNodes : 0
ApplicationHealthPolicyMap                 : {}
sfctl cluster upgrade-status

{
  "codeVersion": "6.0.219.9494",
  "configVersion": "3",

... item cut to save space ...

  },
  "upgradeDomains": [
    {
      "name": "0",
      "state": "Completed"
    },
    {
      "name": "1",
      "state": "Pending"
    },
    {
      "name": "2",
      "state": "Pending"
    },
    {
      "name": "3",
      "state": "Pending"
    },
    {
      "name": "4",
      "state": "Pending"
    }
  ],
  "upgradeDurationInMilliseconds": "PT1H2M4.63889S",
  "upgradeState": "RollingForwardPending"
}

后续步骤Next steps

在本教程中,你了解了如何执行以下操作:In this tutorial, you learned how to:

  • 获取群集运行时的版本Get the version of the cluster runtime
  • 升级群集运行时Upgrade the cluster runtime
  • 监视升级Monitor the upgrade

转到下一教程:Advance to the next tutorial: