簡體   English   中英

如何 ARM 模板 Azure SQL 故障轉移組?

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

如何在與服務器不同的部署中創建 Azure SQL 故障轉移組?

我們在部署中使用部署來實現並發部署。

我正在嘗試創建 2 個 SQL Server,一個在英國西部(主要),一個在英國南部(次要),然后創建一個從主要到次要的故障轉移組。

問題是在創建故障轉移組時,我必須引用主服務器來創建 FOG。 這是失敗的,並表示未定義 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.'

是否可以將部署分開,但仍然創建引用 SQL Server 的 FOG? 我能找到的所有示例都使用單個模板/部署,這使事情變得更加簡單。

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

{
"$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

{
"$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'))]"
    ]
  }
]

}

剛剛遇到了同樣的問題,並在這個例子中找到了答案:

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

您缺少的位是: "serverName": "[parameters('sourceSqlServerName')]",

所以你的全部資源:

{
  "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