简体   繁体   English

如何 ARM 模板 Azure SQL 故障转移组?

[英]How to ARM Template Azure SQL Failover Group?

How can I create a Azure SQL Failover Group in a different deployment to the servers?如何在与服务器不同的部署中创建 Azure SQL 故障转移组?

We use deployments within deployments to achieve concurrent deployments.我们在部署中使用部署来实现并发部署。

I'm trying to create 2 SQL Servers, one in UK West (primary) and one in UK South (secondary), and then create a Failover group from the Primary to Secondary.我正在尝试创建 2 个 SQL Server,一个在英国西部(主要),一个在英国南部(次要),然后创建一个从主要到次要的故障转移组。

The issue is that when creating the Failover group, I have to reference the primary server to create the FOG under.问题是在创建故障转移组时,我必须引用主服务器来创建 FOG。 This is failing and saying that the SQL Server is not defined.这是失败的,并表示未定义 SQL Server。

Deployment template validation failed: 'The resource 'Microsoft.Sql/servers/xxxxxx' is not defined in the template. Please see https://aka.ms/arm-template for usage details.'

Is it possible to keep the deployments separate, yet still create the FOG which references the SQL Servers?是否可以将部署分开,但仍然创建引用 SQL Server 的 FOG? All examples I can find are using a single template/deployment which makes matters slightly more straightforward.我能找到的所有示例都使用单个模板/部署,这使事情变得更加简单。

maindeployment.json maindeployment.json

{
  "apiVersion": "2018-05-01",
  "name": "sqlServerTemplate",
  "type": "Microsoft.Resources/deployments",
  "properties": {
    "mode": "Incremental",
    "templateLink": {
      "uri": "[replace(variables('templateLinkUri'), '*', 'sql-server')]",
      "contentVersion": "1.0.0.0"
    },
    "parameters": {
      "name": {
        "value": "[variables('sqlServerName')]"
      },
      "location": {
        "value": "[parameters('location')]"
      },
      "adminUsername": {
        "value": "[variables('sqlServerAdminUsername')]"
      },
      "adminPassword": {
        "value": "[variables('sqlServerAdminPassword')]"
      }
    }
  }
},
{
  "apiVersion": "2018-05-01",
  "name": "dbTemplate",
  "type": "Microsoft.Resources/deployments",
  "properties": {
    "mode": "Incremental",
    "templateLink": {
      "uri": "[replace(variables('templateLinkUri'), '*', 'sql-database')]",
      "contentVersion": "1.0.0.0"
    },
    "parameters": {
      "dbName": {
        "value": "[variables('dbName')]"
      },
      "sqlServerName": {
        "value": "[variables('sqlServerName')]"
      },
      "location": {
        "value": "[parameters('location')]"
      },
      "skuName": {
        "value": "[parameters('dbSkuName')]"
      },
      "dbCapacity": {
        "value": "[parameters('dbCapacity')]"
      }
    }
  },
  "dependsOn": [
    "sqlServerTemplate"
  ]
},
{
  "apiVersion": "2018-05-01",
  "name": "failoverSqlServerTemplate",
  "type": "Microsoft.Resources/deployments",
  "properties": {
    "mode": "Incremental",
    "templateLink": {
      "uri": "[replace(variables('templateLinkUri'), '*', 'sql-server-failover')]",
      "contentVersion": "1.0.0.0"
    },
    "parameters": {
      "name": {
        "value": "[variables('failoverSqlServerName')]"
      },
      "location": {
        "value": "[parameters('failoverLocation')]"
      },
      "adminUsername": {
        "value": "[variables('sqlServerAdminUsername')]"
      },
      "adminPassword": {
        "value": "[variables('sqlServerAdminPassword')]"
      }
    }
  }
},
{
  "apiVersion": "2018-05-01",
  "name": "sqlFailoverGroupTemplate",
  "type": "Microsoft.Resources/deployments",
  "properties": {
    "mode": "Incremental",
    "templateLink": {
      "uri": "[replace(variables('templateLinkUri'), '*', 'sql-failovergroup')]",
      "contentVersion": "1.0.0.0"
    },
    "parameters": {
      "failoverGroupName": {
        "value": "[variables('failoverGroupName')]"
      },
      "sourceSqlServerName": {
        "value": "[reference('sqlServerTemplate').parameters.name.value]"
      },
      "targetSqlServerName": {
        "value": "[reference('failoverSqlServerTemplate').parameters.name.value]"
      },
      "sqlDatabaseNameToReplicate": {
        "value": "[reference('dbTemplate').parameters.dbName.value]"
      }
    }
  }
}

sql-failovergroup.json sql-failovergroup.json

{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "failoverGroupName": {
      "type": "string"
    },
    "sourceSqlServerName": {
      "type": "string"
    },
    "targetSqlServerName": {
      "type": "string"
    },
    "sqlDatabaseNameToReplicate": {
      "type": "string"
    }
  },
  "variables": {
    "TODO": "Figure out how to reference the SQL Server as the below method is failing with... Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'The resource 'Microsoft.Sql/servers/xxxxx' is not defined in the template.",
    "sourceServerResourceId": "[resourceId('Microsoft.Sql/servers', parameters('sourceSqlServerName'))]",
    "targetServerResourceId": "[resourceId('Microsoft.Sql/servers', parameters('targetSqlServerName'))]",
    "databaseResourceId": "[concat(resourceGroup().id, '/providers/Microsoft.Sql/servers/', parameters('sourceSqlServerName'), '/databases/', parameters('sqlDatabaseNameToReplicate'))]"
  },
  "resources": [
    {
      "name": "[concat(parameters('sourceSqlServerName'), '/', parameters('failoverGroupName'))]",
      "type": "Microsoft.Sql/servers/failoverGroups",
      "apiVersion": "2015-05-01-preview",
      "properties": {
        "readWriteEndpoint": {
          "failoverPolicy": "Manual",
          "failoverWithDataLossGracePeriodMinutes": 60
        },
        "readOnlyEndpoint": {
          "failoverPolicy": "Disabled"
        },
        "partnerServers": [
          {
            "id": "[variables('targetServerResourceId')]"
          }
        ],
        "databases": [
          "[variables('databaseResourceId')]"
        ]
      },
      "dependsOn": [
        "[variables('sourceServerResourceId')]",
        "[variables('targetServerResourceId')]"
      ]
    }
  ]
}

sql-server.json sql-server.json

{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
  "name": {
    "type": "string"
  },
  "location": {
    "type": "string"
  },
  "adminUsername": {
    "type": "string"
  },
  "adminPassword": {
    "type": "string"
  },
  "whitelistStartIpAddress": {
    "type": "string"
  },
  "whitelistEndIpAddress": {
    "type": "string"
  }
},
"variables": {
   "azureStartIpAddress": "0.0.0.0",
   "azureEndIpAddress": "0.0.0.0"
},
"resources": [{
    "name": "[parameters('name')]",
    "type": "Microsoft.Sql/servers",
    "apiVersion": "2014-01-01",
    "location": "[parameters('location')]",
    "properties": {
      "administratorLogin": "[parameters('adminUsername')]",
      "administratorLoginPassword": "[parameters('adminPassword')]"
    }
  },
  {
    "name": "[concat(parameters('name'), '/WindowsAzureIps')]",
    "type": "Microsoft.Sql/servers/firewallRules",
    "apiVersion": "2014-04-01",
    "properties": {
      "startIpAddress": "[variables('azureStartIpAddress')]",
      "endIpAddress": "[variables('azureEndIpAddress')]"
    },
    "dependsOn": [
      "[resourceId('Microsoft.Sql/servers', parameters('name'))]"
    ]
  }
]

} }

Just came across this same problem, and found the answer on this example:刚刚遇到了同样的问题,并在这个例子中找到了答案:

https://github.com/Azure/azure-quickstart-templates/blob/master/101-sql-with-failover-group/azuredeploy.json https://github.com/Azure/azure-quickstart-templates/blob/master/101-sql-with-failover-group/azuredeploy.json

The bit you're missing is: "serverName": "[parameters('sourceSqlServerName')]",您缺少的位是: "serverName": "[parameters('sourceSqlServerName')]",

So your full resource:所以你的全部资源:

{
  "name": "[concat(parameters('sourceSqlServerName'), '/', parameters('failoverGroupName'))]",
  "type": "Microsoft.Sql/servers/failoverGroups",
  "apiVersion": "2015-05-01-preview",
  "properties": {
    "readWriteEndpoint": {
      "failoverPolicy": "Manual",
      "failoverWithDataLossGracePeriodMinutes": 60
    },
    "readOnlyEndpoint": {
      "failoverPolicy": "Disabled"
    },
    "serverName": "[parameters('sourceSqlServerName')]",
    "partnerServers": [
      {
        "id": "[variables('targetServerResourceId')]"
      }
    ],
    "databases": [
          "[variables('databaseResourceId')]"
    ]
  },
  "dependsOn": [
    "[variables('sourceServerResourceId')]",
    "[variables('targetServerResourceId')]"
  ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM