gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 04:09:22 28 4
gpt4 key购买 nike

如何在服务器的不同部署中创建 Azure SQL 故障转移组?

我们在部署中使用部署来实现并发部署。

我正在尝试创建 2 个 SQL Server,一台位于英国西部(主要),一台位于英国南部(辅助),然后创建一个从主要到辅助的故障转移组。

问题是,在创建故障转移组时,我必须引用主服务器来创建 FOG。这是失败的,并表示 SQL Server 未定义。

部署模板验证失败:“模板中未定义资源“Microsoft.Sql/servers/xxxxxx”。请参阅 https://aka.ms/arm-template 了解使用详情。'

是否可以保持部署分离,但仍然创建引用 SQL Server 的 FOG?我能找到的所有示例都使用单个模板/部署,这使得事情变得更加简单。

ma​​indeployment.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')]"
]
}

关于azure - 如何ARM模板Azure SQL故障转移组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57678041/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com