2016-10-03 163 views
0

我一直在尝试将Azure应用程序网关部署到前端应用程序,我在现有的虚拟机上并将主机名用于池选择。我开始从混帐https://github.com/Azure/azure-quickstart-templates/tree/master/201-application-gateway-multihosting该模板基础上,文章https://github.com/Azure/azure-content/blob/master/articles/application-gateway/application-gateway-multi-site-overview.md如何部署带有虚拟机的应用程序网关

这里是体改tempate我用

{ 
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 
"contentVersion": "1.0.0.0", 
"parameters": { 
    "vnetAddressPrefix": { 
     "type": "string", 
     "defaultValue": "10.0.0.0/16", 
     "metadata": { 
      "description": "Address prefix for the Virtual Network" 
     } 
    }, 
    "subnetPrefix": { 
     "type": "string", 
     "defaultValue": "10.0.0.0/28", 
     "metadata": { 
      "description": "Gateway Subnet prefix" 
     } 
    }, 
    "skuName": { 
     "type": "string", 
     "allowedValues": [ 
      "Standard_Small", 
      "Standard_Medium", 
      "Standard_Large" 
     ], 
     "defaultValue": "Standard_Small", 
     "metadata": { 
      "description": "Sku Name" 
     } 
    }, 
    "capacity": { 
     "type": "int", 
     "defaultValue": 4, 
     "metadata": { 
      "description": "Number of instances" 
     } 
    }, 
    "backendIpAddress1": { 
     "type": "string", 
     "metadata": { 
      "description": "IP Address for Backend Server 1" 
     } 
    }, 
    "backendIpAddress2": { 
     "type": "string", 
     "metadata": { 
      "description": "IP Address for Backend Server 2" 
     } 
    }, 
    "backendIpAddress3": { 
     "type": "string", 
     "metadata": { 
      "description": "IP Address for Backend Server 3" 
     } 
    }, 
    "backendIpAddress4": { 
     "type": "string", 
     "metadata": { 
      "description": "IP Address for Backend Server 4" 
     } 
    }, 
    "backendIpAddress5": { 
     "type": "string", 
     "metadata": { 
      "description": "IP Address for Backend Server 5" 
     } 
    }, 
    "backendIpAddress6": { 
     "type": "string", 
     "metadata": { 
      "description": "IP Address for Backend Server 6" 
     } 
    }, 
    "hostName1": { 
     "type": "string", 
     "metadata": { 
      "description": "HostName for listener 1" 
     } 
    }, 
    "hostName2": { 
     "type": "string", 
     "metadata": { 
      "description": "HostName for listener 2" 
     } 
    }, 
    "certData1": { 
     "type": "securestring", 
     "metadata": { 
      "description": "Base-64 encoded form of the .pfx file" 
     } 
    }, 
    "certPassword1": { 
     "type": "securestring", 
     "metadata": { 
      "description": "Password for .pfx certificate" 
     } 
    } 
}, 
"variables": { 
    "applicationGatewayName": "PortalGateway", 
    "publicIPAddressName": "PortalGatewayFrontendIP", 
    "virtualNetworkName": "PalitonNetworks-East-VirtualNetwork", 
    "subnetName": "GWSubnet1", 
    "vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]", 
    "subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]", 
    "publicIPRef": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]", 
    "applicationGatewayID": "[resourceId('Microsoft.Network/applicationGateways',variables('applicationGatewayName'))]", 
    "apiVersion": "2015-06-15" 
}, 
"resources": [ 
    { 
     "apiVersion": "[variables('apiVersion')]", 
     "type": "Microsoft.Network/publicIPAddresses", 
     "name": "[variables('publicIPAddressName')]", 
     "location": "[resourceGroup().location]", 
     "properties": { 
      "publicIPAllocationMethod": "Dynamic" 
     } 
    }, 
    { 
     "apiVersion": "[variables('apiVersion')]", 
     "type": "Microsoft.Network/virtualNetworks", 
     "name": "[variables('virtualNetworkName')]", 
     "location": "[resourceGroup().location]", 
     "properties": { 
      "addressSpace": { 
       "addressPrefixes": [ 
        "[parameters('vnetAddressPrefix')]" 
       ] 
      }, 
      "subnets": [ 
       { 
        "name": "[variables('subnetName')]", 
        "properties": { 
         "addressPrefix": "[parameters('subnetPrefix')]" 
        } 
       } 
      ] 
     } 
    }, 
    { 
     "apiVersion": "[variables('apiVersion')]", 
     "name": "[variables('applicationGatewayName')]", 
     "type": "Microsoft.Network/applicationGateways", 
     "location": "[resourceGroup().location]", 
     "dependsOn": [ 
      "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]", 
      "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]" 
     ], 
     "properties": { 
      "sku": { 
       "name": "[parameters('skuName')]", 
       "tier": "Standard", 
       "capacity": "[parameters('capacity')]" 
      }, 
      "sslCertificates": [ 
       { 
        "name": "appGatewaySslCert1", 
        "properties": { 
         "data": "[parameters('certData1')]", 
         "password": "[parameters('certPassword1')]" 
        } 
       } 

      ], 
      "gatewayIPConfigurations": [ 
       { 
        "name": "appGatewayIpConfig", 
        "properties": { 
         "subnet": { 
          "id": "[variables('subnetRef')]" 
         } 
        } 
       } 
      ], 
      "frontendIPConfigurations": [ 
       { 
        "name": "appGatewayFrontendIP", 
        "properties": { 
         "PublicIPAddress": { 
          "id": "[variables('publicIPRef')]" 
         } 
        } 
       } 
      ], 
      "frontendPorts": [ 
       { 
        "name": "appGatewayFrontendPort1", 
        "properties": { 
         "Port": 443 
        } 
       }, 
       { 
        "name": "appGatewayFrontendPort2", 
        "properties": { 
         "Port": 80 
        } 
       } 
      ], 
      "backendAddressPools": [ 
       { 
        "name": "appGatewayBackendPool1", 
        "properties": { 
         "BackendAddresses": [ 
          { 
           "IpAddress": "[parameters('backendIpAddress1')]" 
          }, 
          { 
           "IpAddress": "[parameters('backendIpAddress2')]" 
          }, 
          { 
           "IpAddress": "[parameters('backendIpAddress3')]" 
          } 
         ] 
        } 
       }, 
       { 
        "name": "appGatewayBackendPool2", 
        "properties": { 
         "BackendAddresses": [ 
          { 
           "IpAddress": "[parameters('backendIpAddress4')]" 
          }, 
          { 
           "IpAddress": "[parameters('backendIpAddress5')]" 
          }, 
          { 
           "IpAddress": "[parameters('backendIpAddress6')]" 
          } 
         ] 
        } 
       } 
      ], 
      "backendHttpSettingsCollection": [ 
       { 
        "name": "appGatewayBackendHttpSettings", 
        "properties": { 
         "Port": 80, 
         "Protocol": "Http", 
         "CookieBasedAffinity": "Disabled" 
        } 
       }, 
       { 
        "name": "appGatewayBackendHttpsSettings", 
        "properties": { 
         "Port": 443, 
         "Protocol": "Https", 
         "CookieBasedAffinity": "Disabled" 
        } 
       } 
      ], 
      "httpListeners": [ 
       { 
        "name": "appGatewayHttpsListener-Group1", 
        "properties": { 
         "FrontendIPConfiguration": { 
          "Id": "[concat(variables('applicationGatewayID'), '/frontendIPConfigurations/appGatewayFrontendIP')]" 
         }, 
         "FrontendPort": { 
          "Id": "[concat(variables('applicationGatewayID'), '/frontendPorts/appGatewayFrontendPort1')]" 
         }, 
         "Protocol": "Https", 
         "SslCertificate": { 
          "Id": "[concat(variables('applicationGatewayID'), '/sslCertificates/appGatewaySslCert1')]" 
         }, 
         "HostName": "[parameters('hostName1')]", 
         "RequireServerNameIndication": "false" 
        } 
       }, 
       { 
        "name": "appGatewayHttpsListener-Group2", 
        "properties": { 
         "FrontendIPConfiguration": { 
          "Id": "[concat(variables('applicationGatewayID'), '/frontendIPConfigurations/appGatewayFrontendIP')]" 
         }, 
         "FrontendPort": { 
          "Id": "[concat(variables('applicationGatewayID'), '/frontendPorts/appGatewayFrontendPort1')]" 
         }, 
         "Protocol": "Https", 
         "SslCertificate": { 
          "Id": "[concat(variables('applicationGatewayID'), '/sslCertificates/appGatewaySslCert1')]" 
         }, 
         "HostName": "[parameters('hostName2')]", 
         "RequireServerNameIndication": "false" 
        } 
       }, 
     { 
        "name": "appGatewayHttpListener-Group1", 
        "properties": { 
         "FrontendIPConfiguration": { 
          "Id": "[concat(variables('applicationGatewayID'), '/frontendIPConfigurations/appGatewayFrontendIP')]" 
         }, 
         "FrontendPort": { 
          "Id": "[concat(variables('applicationGatewayID'), '/frontendPorts/appGatewayFrontendPort2')]" 
         }, 
         "Protocol": "Http", 
         "SslCertificate": null, 
         "HostName": "[parameters('hostName1')]", 
         "RequireServerNameIndication": "false" 
        } 
       }, 
     { 
        "name": "appGatewayHttpListener-Group2", 
        "properties": { 
         "FrontendIPConfiguration": { 
          "Id": "[concat(variables('applicationGatewayID'), '/frontendIPConfigurations/appGatewayFrontendIP')]" 
         }, 
         "FrontendPort": { 
          "Id": "[concat(variables('applicationGatewayID'), '/frontendPorts/appGatewayFrontendPort2')]" 
         }, 
         "Protocol": "Http", 
         "SslCertificate": null, 
         "HostName": "[parameters('hostName2')]", 
         "RequireServerNameIndication": "false" 
        } 
       } 
      ], 
      "requestRoutingRules": [ 
       { 
        "Name": "Group1-SSL", 
        "properties": { 
         "RuleType": "Basic", 
         "httpListener": { 
          "id": "[concat(variables('applicationGatewayID'), '/httpListeners/appGatewayHttpsListener-Group1')]" 
         }, 
         "backendAddressPool": { 
          "id": "[concat(variables('applicationGatewayID'), '/backendAddressPools/appGatewayBackendPool1')]" 
         }, 
         "backendHttpSettings": { 
          "id": "[concat(variables('applicationGatewayID'), '/backendHttpSettingsCollection/appGatewayBackendHttpSettings')]" 
         } 
        } 
       }, 
       { 
        "Name": "Group2-SSL", 
        "properties": { 
         "RuleType": "Basic", 
         "httpListener": { 
          "id": "[concat(variables('applicationGatewayID'), '/httpListeners/appGatewayHttpsListener-Group2')]" 
         }, 
         "backendAddressPool": { 
          "id": "[concat(variables('applicationGatewayID'), '/backendAddressPools/appGatewayBackendPool2')]" 
         }, 
         "backendHttpSettings": { 
          "id": "[concat(variables('applicationGatewayID'), '/backendHttpSettingsCollection/appGatewayBackendHttpSettings')]" 
         } 
        } 
       }, 
     { 
        "Name": "Group2-www", 
        "properties": { 
         "RuleType": "Basic", 
         "httpListener": { 
          "id": "[concat(variables('applicationGatewayID'), '/httpListeners/appGatewayHttpListener-Group1')]" 
         }, 
         "backendAddressPool": { 
          "id": "[concat(variables('applicationGatewayID'), '/backendAddressPools/appGatewayBackendPool1')]" 
         }, 
         "backendHttpSettings": { 
          "id": "[concat(variables('applicationGatewayID'), '/backendHttpSettingsCollection/appGatewayBackendHttpSettings')]" 
         } 
        } 
       }, 
     { 
        "Name": "Group1-www", 
        "properties": { 
         "RuleType": "Basic", 
         "httpListener": { 
          "id": "[concat(variables('applicationGatewayID'), '/httpListeners/appGatewayHttpListener-Group2')]" 
         }, 
         "backendAddressPool": { 
          "id": "[concat(variables('applicationGatewayID'), '/backendAddressPools/appGatewayBackendPool2')]" 
         }, 
         "backendHttpSettings": { 
          "id": "[concat(variables('applicationGatewayID'), '/backendHttpSettingsCollection/appGatewayBackendHttpSettings')]" 
         } 
        } 
       } 
      ] 
     } 
    } 
] 
} 

正如你可以看到我指定GWSubnet1作为应用网关子网。我的后端IP位于同一虚拟网络下的VMnet1子网中。当我部署失败时说它不能删除VMnet1。 VMNet1仅被间接引用为后端IP,为什么它会尝试删除它。根据Azure的部署规则,GWSubnet1是未使用的空子网。

如果我使用GUI,我可以创建网关并选择GWSubnet1。但是,使用GUI将主机名放入列表器的高级功能不是一个选项,因此不会让您使用相同的前端端口创建多个列表器。我尝试使用GUI和,然后通过Poweshell加入listners(3.0.0版本)使用以下

$hostname = "example1.foo.com" 
$listnername = "group2-az" 
$appgwname = "PortalGateway" 
$rmname = "myrmg" 
$feipname = "appGatewayFrontendIP" 
$fepname = "appGatewayFrontendPort" 
$behttpname = "appGatewayBackendHttpSettings" 


$appgw = Get-AzureRmApplicationGateway -Name $appgwname -ResourceGroupName  $rmname 
$bepool = Get-AzureRmApplicationGatewayBackendAddressPool -ApplicationGateway $appgw -Name "appGatewayBackendPool" 
$behttp = Get-AzureRmApplicationGatewayBackendHttpSettings -ApplicationGateway $appgw -Name $behttpname 



$fipc = Get-AzureRmApplicationGatewayFrontendIPConfig -Name $feipname -ApplicationGateway $appgw 
$fep = Get-AzureRmApplicationGatewayFrontendPort -Name $fepname -ApplicationGateway $appgw 
$result = Add-AzureRmApplicationGatewayHttpListener -ApplicationGateway $appgw -Name "appGatewayHttpListenerGroup1" -Protocol Http -FrontendIPConfiguration $fipc -FrontendPort $fep -HostName $hostname -RequireServerNameIndication false 

但是这似乎发生的是,它不添加一个监听器,它只是改变了现有的默认监听器是通过GUI创建appgateway时创建的。无论我选择什么名字作为听众,它都会这样做。

我知道部署模板工程,我可以创造一个新的空资源组,并在那里部署它,并将其部署。我似乎无法让它部署在有现有VM的地方。什么是正确的方法来做到这一点?

+0

你尝试到你的后端子网添加到模板?我有同样的问题。据我了解,VNET需要在模板中包含所有子网。 –

回答

1

ARM模板是声明性的,在您的模板中只有一个子网。如果您部署该模板,ARM将尝试完全按照您的定义进行设置=它会尝试删除该子网中未使用自身定义的任何子网。 这就是你错误的原因。 ARM试图删除你的VMnet1,只要它有与之关联的NIC,它就不能这么做。

检查这里的文档: Deploy resources with Resource Manager templates and Azure PowerShell

你最有趣的部分是:

增量和完整部署

在部署你的资源,你指定的部署或者是一个增量更新或完整更新。默认情况下,资源管理器将部署处理为资源组的增量更新。

随着增量部署,资源管理器:

  • 留下存在的资源组中,但在模板
  • 没有规定不变资源补充说,在模板中指定的,但做资源不存在于资源组中
  • 不会根据模板中定义的相同条件重新配置存在于资源组中的资源
  • reprovisions,在模板

有了完整的部署已更新的设置,资源管理器现有资源:

  • 删除存在的资源组中,但在未指定资源模板
  • 增加在模板中指定但资源中不存在的资源组
  • 不另配资源存在资源组在模板中定义相同的条件下
  • reprovisions,在模板

已经更新设置现有资源来解决你的问题,你需要使子网配置完全代表您的现有设置,或者手动创建新的子网,并且不要在模板中定义vnet。

如果您创建子网手动您可以参考现有的互联星空和子网模板是这样的:

"parameters": { 
    "existingVirtualNetworkName": { 
     "type": "string" 
    }, 
    "existingVirtualNetworkResourceGroup": { 
     "type": "string" 
    }, 
    "existingSubnet1Name": { 
     "type": "string" 
    }, 
    "existingSubnet2Name": { 
     "type": "string" 
    }, 
} 
"variables": { 
    "existingVnetID": "[resourceId(parameters('existingVirtualNetworkResourceGroup'), 'Microsoft.Network/virtualNetworks', parameters('existingVirtualNetworkName'))]", 
    "existingSubnet1Ref": "[concat(variables('existingVnetID'),'/subnets/', parameters('existingSubnet1Name'))]", 
    "existingSubnet2Ref": "[concat(variables('existingVnetID'),'/subnets/', parameters('existingSubnet2Name'))]", 
} 

通过现有RessourceGroup,互联星空和Subnetnames通过参数,你可以只使用变量“existingSubnet1Name后“指向正确的ID。

神奇的是[resourceId()]函数可选参数:[subscriptionId],[resourceGroupName]。

resourceId ([subscriptionId], [resourceGroupName], resourceType, resourceName1, [resourceName2]...) 

文档:Template functions

相关问题