我正在尝试创建一个ARM模板,该模板将为多个Web服务器提供可直接访问的端口。例如,我希望VM根据VM的索引打开端口9001或9002。
我正在努力让frontendPort参数接受一个函数。 Here是我使用过的文档。
以下是我的模板的相关部分:
"inboundNatRules": [
{
"copy": {
"name": "natCopy",
"count": "[parameters('numberOfVms')]"
},
"name": "[concat('directHttps-', copyIndex())]",
"properties": {
"frontendIPConfiguration": {
"id": "[concat(variables('lbID'),'/frontendIPConfigurations/LoadBalancerFrontEnd')]"
},
"frontendPort": "[add(9001, copyIndex())]",
"backendPort": 9001,
"enableFloatingIP": false,
"idleTimeoutInMinutes": 4,
"protocol": "Tcp",
"backendIPConfiguration": {
"id": "[resourceId('Microsoft.Network/networkInterfaces', concat(variables('vmNicName'), copyIndex()), 'ipconfig')]"
}
}
}
我希望这个特定的端口会产生“9001”或“9002”。
"frontendPort": "[add(9001, copyIndex())]"
相反,我在Visual Studio的Intellisense中看到了一个错误,当我尝试部署解决方案时。
Create template deployment 'deploymenttemplate-0107-1555'.
New-AzureRmResourceGroupDeployment : Resource Microsoft.Network/loadBalancers 'webserverLb'
failed with message 'Unable to process template language expressions for resource
'/subscriptions/some random guid/resourceGroups/webservers/providers/Microsoft.Network/loadBalancers/webserverLb'
at line '102' and column '10'. 'The template function 'copyIndex' is not expected at this location.
The function can only be used in a resource with copy specified.
长话短说,我只是尝试使用与模板中的VM相同数量的NAT规则,并动态分配外部端口号。
如果我能提供更多信息,请告诉我。谢谢。
答案 0 :(得分:0)
您可以在MSDN网络论坛上提出您的问题: https://social.msdn.microsoft.com/Forums/azure/en-US/home?forum=WAVirtualMachinesVirtualNetwork,Azure支持将提供帮助。
答案 1 :(得分:0)
尝试:
[Concat(900,CopyIndex(1))]
将偏移索引(基于0)并为您提供所需的数字。
答案 2 :(得分:0)
这是用于复制NAT规则的语法(我在标准后端端口上添加RDP规则):
"copy": [
{
"name": "inboundNatRules",
"count": "[parameters('numberOfWebInstances')]",
"input": {
"name": "[concat(parameters('lbNatRulePrefix'), copyindex('inboundNatRules'))]",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('lbFrontEndIpId')]"
},
"frontendPort": "[add(50001, copyIndex('inboundNatRules'))]",
"backendPort": 3389,
"enableFloatingIP": false,
"idleTimeoutInMinutes": 4,
"protocol": "tcp"
}
}
}
],
然后要将规则应用于NIC,您实际上需要在NIC本身上添加一些代码。以下是LB规则和NAT规则:
"loadBalancerBackendAddressPools": [
{
"id": "[concat(variables('lbID'), '/backendAddressPools/', parameters('lbPoolName'))]"
}
],
"loadBalancerInboundNatRules": [
{
"id": "[concat(variables('lbID'),'/inboundNatRules/' , parameters('lbNatRulePrefix'), copyindex())]"
}
]
答案 3 :(得分:-1)
$LoadBalancer = Get-AzureRmLoadBalancer -ResourceGroupName $ResourceGroupName -Name $LoadBalancerName
$publicIP1 = Get-AzureRmPublicIpAddress -name $pipName -resourcegroupname $ResourceGroupName
$frontendIP1 = Get-AzureRmLoadBalancerFrontendIpConfig -LoadBalancer $LoadBalancer -Name $FrontendIpConfigName
$LoadBalancer | Add-AzureRmLoadBalancerInboundNatRuleConfig -Name "nat_rule_tcp_IP1_49157" -FrontendIpConfiguration $frontendIP1 -IdleTimeoutInMinutes 4 -Protocol TCP -FrontendPort 49157 -BackendPort 49157 | Set-AzureRmLoadBalancer