【问题标题】:ARM Deployment error: Unable to freeze secondary namespace before creating pairing, this is probably because secondary namespace is not emptyARM 部署错误:在创建配对之前无法冻结辅助命名空间,这可能是因为辅助命名空间不为空
【发布时间】:2020-07-30 18:52:07
【问题描述】:

我通过 Azure 门户手动部署了两个高级服务总线实例。他们没有配置地理恢复别名,服务总线实例已经运行了大约一年。

现在,我正在尝试自动化这些服务总线实例的部署过程,并向其中添加一个 georecovery 别名资源,如下所示:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "serviceBusNamespaceName": {
      "type": "string",
      "metadata": {
        "description": "Name of the Service Bus namespace"
      }
    },
    "serviceBusQueueName": {
      "type": "string",
      "metadata": {
        "description": "Name of the Queue"
      }
    },
    "serviceBusLocation": {
      "type": "string"
    },
    "sku": {
      "type": "object",
      "defaultValue": "Standard"
    },
    "serviceBusTopicName": {
      "type": "string"
    },
    "serviceBusSubscriptionName": {
      "type": "string"
    },
    "isAliasEnabled": {
      "type": "bool"
    },
    "isQueueCreationEnabled": {
      "type": "bool"
    },
    "aliasName": {
      "type": "string"
    },
    "partnerNamespace": {
      "type": "string"
    }
  },
  "variables": {
    "defaultSASKeyName": "RootManageSharedAccessKey",
    "authRuleResourceId": "[resourceId('Microsoft.ServiceBus/namespaces/authorizationRules', parameters('serviceBusNamespaceName'), variables('defaultSASKeyName'))]",
    "sbVersion": "2017-04-01"
  },
  "resources": [
    {
      "apiVersion": "2018-01-01-preview",
      "name": "[parameters('serviceBusNamespaceName')]",
      "type": "Microsoft.ServiceBus/Namespaces",
      "location": "[parameters('serviceBusLocation')]",
      "sku": {
        "name": "[parameters('sku').name]",
        "tier": "[parameters('sku').tier]",
        "capacity": "[parameters('sku').capacity]"
      },
      "properties": {
        "zoneRedundant": false
      },
      "resources": [
        {
          "apiVersion": "2017-04-01",
          "name": "[parameters('aliasName')]",
          "type": "disasterRecoveryConfigs",
          "condition": "[parameters('isAliasEnabled')]",
          "dependsOn": [
            "[concat('Microsoft.ServiceBus/namespaces/', parameters('serviceBusNamespaceName'))]"
          ],
          "properties": {
            "partnerNamespace": "[parameters('partnerNamespace')]"
          }
        }
      ]
    }
  ]
}

我使用相同的模板分别部署主实例和辅助实例。请注意,disasterRecoveryConfigs 资源仅在它是主实例时才会被部署。

此模板成功部署了辅助命名空间,但主命名空间部署失败并出现以下错误:

在创建配对之前无法冻结辅助命名空间,这是 可能是因为辅助命名空间不为空。

这是正确的,即辅助命名空间已经创建了几个主题/订阅和队列。我不想删除它们,只想将主命名空间和辅助命名空间配对。

如何做到这一点?

【问题讨论】:

    标签: azure azureservicebus azure-resource-manager arm-template azure-resource-group


    【解决方案1】:

    如果您尝试在具有私有端点的主命名空间和没有私有端点的辅助命名空间之间进行create a pairing,则配对将失败。

    您可以参考这个template 允许您配置服务总线地理灾难恢复别名。

    {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "serviceBusNamespaceNamePrimary": {
          "type": "string",
          "metadata": {
            "description": "Name of Service Bus namespace"
          }
        },
        "serviceBusNamespaceNameSecondary": {
          "type": "string",
          "metadata": {
            "description": "Name of Service Bus namespace"
          }
        },
        "aliasName": {
          "type": "string",
          "metadata": {
            "description": "Name of Geo-Recovery Configuration Alias "
          }
        },
        "locationSecondaryNamepsace": {
          "type": "string",
          "defaultValue": "South Central US",
          "metadata": {
            "description": "Location of Secondary namespace"
          }
        },
        "location": {
          "type": "string",
          "defaultValue": "[resourceGroup().location]",
          "metadata": {
            "description": "Location of Primary namespace"
          }
        }
      },
      "variables": {
        "defaultSASKeyName": "RootManageSharedAccessKey",
        "defaultAuthRuleResourceId": "[resourceId('Microsoft.ServiceBus/namespaces/authorizationRules', parameters('serviceBusNamespaceNamePrimary'), variables('defaultSASKeyName'))]"
      },
      "resources": [
        {
          "apiVersion": "2017-04-01",
          "name": "[parameters('serviceBusNamespaceNameSecondary')]",
          "type": "Microsoft.ServiceBus/Namespaces",
          "location": "[parameters('locationSecondaryNamepsace')]",
          "sku": {
            "name": "Premium",
            "tier": "Premium",
            "capacity": 4
          },
          "tags": {
            "tag1": "value1",
            "tag2": "value2"
          }
        },
        {
          "apiVersion": "2017-04-01",
          "type": "Microsoft.ServiceBus/Namespaces",
          "dependsOn": [ "[concat('Microsoft.ServiceBus/namespaces/', parameters('serviceBusNamespaceNameSecondary'))]" ],
          "name": "[parameters('serviceBusNamespaceNamePrimary')]",
          "location": "[parameters('location')]",
          "sku": {
            "name": "Premium",
            "tier": "Premium",
            "capacity": 4
          },
          "tags": {
            "tag1": "value1",
            "tag2": "value2"
          },
          "resources": [
            {
              "apiVersion": "2017-04-01",
              "name": "[parameters('aliasName')]",
              "type": "disasterRecoveryConfigs",
              "dependsOn": [ "[concat('Microsoft.ServiceBus/namespaces/', parameters('serviceBusNamespaceNamePrimary'))]" ],
              "properties": {
                "partnerNamespace": "[resourceId('Microsoft.ServiceBus/Namespaces', parameters('serviceBusNamespaceNameSecondary'))]"
              }
            }
          ]
        }
      ],
      "outputs": {
        "NamespaceDefaultConnectionString": {
          "type": "string",
          "value": "[listkeys(variables('defaultAuthRuleResourceId'), '2017-04-01').primaryConnectionString]"
        },
        "DefaultSharedAccessPolicyPrimaryKey": {
          "type": "string",
          "value": "[listkeys(variables('defaultAuthRuleResourceId'), '2017-04-01').primaryKey]"
        }
      }
    }
    

    【讨论】:

    【解决方案2】:

    我对事件中心 Geo-Recovery ARM 模板有类似的问题,我仔细阅读了异常,它说辅助命名空间不为空意味着我们必须删除主题,从辅助命名空间排队然后再次运行模板,它会工作并将根据主命名空间再次创建主题和队列。

    但是如果你再次运行模板,你会得到不同的异常,即无法更新辅助命名空间(因为它在地理配对中)。这很奇怪,但根据设计,您无法在 Geo Pairing 中更新辅助命名空间,即使您删除 Geo Pairing,您的辅助命名空间也应该是空的,没有任何实例,例如主题、队列等。

    如何克服这个问题?

    让我们考虑一下,现在我想使用 ARM 模板在现有部署中添加主题或队列,那么当您的模板在管道中或任何地方并且需要多次运行并更新现有时,您将遇到问题主命名空间。

    1.快速修复(一次只有第二次手动再次您必须执行以下步骤)

    • 登录 Azure 门户
    • 转到您的主要服务总线命名空间
    • 点击设置部分下的 Geo-Recovery 选项
    • 在顶部的右侧找到选项中断配对和
      点击它。

    这会破坏配对&如果你不按照这个步骤你会得到异常,Secondary Namespaces can't be updated

    • 接下来,删除辅助命名空间实例或命名空间并运行 管道。它会起作用的。

    如果您不按照上述步骤操作,则会收到无法冻结辅助命名空间的错误。

    以上是一次性修复,如果再次运行模板,则必须再次手动重复上述过程。

    2。使用 CI-CD DevOps Pipeline 或 CLI 或 PowerShell 实现自动化

    大部分时间 ARM 模板在管道中运行,并且可以选择使用 Azure CLI 或 PowerShell 中断配对。您应该考虑在 YAML 文件中添加两个任务

    • 第一个任务,打破配对

    Azure CLI

    az servicebus georecovery-alias break-pair --resource-group myresourcegroup --namespace-name primarynamespace --alias myaliasname

    PowerShell

    Set-AzureRmServiceBusGeoDRConfigurationBreakPair -ResourceGroupName $resourcegroup -Name $aliasname -Namespace $primarynamespace
    • 第二个任务,删除辅助命名空间实例(主题, 队列)或删除整个命名空间。

    PowerShell

    Remove-AzServiceBusNamespace -ResourceGroup Default-ServiceBus-WestUS -NamespaceName SB-Example1

    要删除主题或队列而不是命名空间,请参阅以下文档。

    Azure Service Bus Management Common PowerShell commands

    此外,如果您在本地运行模板,您可以在运行模板之前添加小脚本或 CLI 命令。

    删除Secondary Namespace 或实例后对ConnectionString 或Data 有影响吗?

    它的有效问题,连接字符串或数据会发生什么,因为一些客户端已经在使用它,答案是如果我们删除辅助命名空间,连接字符串不会改变,因为在地理恢复场景中,我们应该使用别名连接字符串,因此对现有客户没有影响。

    关于数据的第二个问题,答案是辅助命名空间不会存储任何只有元数据的数据,这意味着在故障转移的情况下辅助命名空间开始工作。

    所以在部署期间删除辅助命名空间实例或命名空间不会影响任何事情。

    还有更好的选择吗?

    可能你在想,我为什么要遵循这么长的过程,但是由于 Geo Recovery 设计(服务总线、事件中心、事件网格等)而出现上述问题并且没有其他选择。

    我希望微软将来会想出一些更好的方法。

    【讨论】:

      猜你喜欢
      • 2014-01-05
      • 2016-01-21
      • 2019-02-28
      • 1970-01-01
      • 2012-09-29
      • 2013-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多