使用ARM模板部署多个虚拟机,将privateip分配为静态 [英] Deploying multiple virtual machines with ARM templates having privateip allocated as static

查看:132
本文介绍了使用ARM模板部署多个虚拟机,将privateip分配为静态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从ARM模板部署几个虚拟机。我有代码,我能够使用动态私有IP部署多个虚拟机,但我无法弄清楚如何在模板中传递静态IP in循环。我有
部署了一个私有ip作为静态的vm,但实际上却遇到了多个分配静态ips的虚拟机。下面是代码。我们在网络机器顶部有一个负载均衡器。

I have a requirement of deploying couple of virtual machines from ARM templates. i have code and i am able to deploy multiple virtual machines with dynamic private ip but i am not able to figure out how to pass the static ip in loop in the template. I have deployed a single vm with private ip as static but really got stuck with multiple virtual machines assigning static ips. Below is the code.We have a load balancer sitting on top of the web machines.

推荐答案

您可以尝试以下模板吗?

Can you try the below template?

{
    "


schema":" https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
" contentVersion": "1.0.0.0",
" parameters" ;: {
" adminUsername":{
" type":" string",
" metadata" :{
" description":" VM的管理员用户名"
}
},
" adminPassword" ;: {
" type":" securestring",
" metadata":{
" ;描述"" VM的管理员密码"
}
},
" numberOfInstances" ;: {
" type":" int",
" defaultValue":2,
" minValue":2,
" maxValue":5,
" metadata":{
" description":"要部署的VM数量,此示例后限制为5正在使用单个存储帐户"
}
},
" OS":{
" type":" string",
" defaultValue":" Ubuntu",
" allowedValues":[
" Ubuntu",
" Windows"
],
" metadata":{
" description":" VM Platform for VM"
}
},
" location":{
" type":" string",
" defaultValue":" [resourceGroup() .location]",
" metadata":{
" description":"所有资源的位置。"
}
},
" vmSizes" ;: {
" type":" string",
" allowedValues":[
" ; Basic_A0",
" Standard_D1_v2"
],
" defaultValue":" Standard_D1_v2",
" metadata":{
" description":"用于VM的复制类型大小"。
}
}
},
" variables" ;: {
" virtualNetworkName":" myVNET",
" addressPrefix":" ; 10.0.0.0/16" ;,
" subnet1Name":" Subnet-1",
" subnet1Prefix":" 10.0.0.0/24" ;,
" subnet1Ref" :" [resourceId('Microsoft.Network/virtualNetworks/subnets',variables('virtualNetworkName'),variables('subnet1Name'))]",
" availabilitySetName":" myAvSet",
" Ubuntu":{
" publisher":" Canonical",
" offer":" UbuntuServer",
" sku":" 16.04.0 -LTS",
" version":" latest"
},
" Windows":{
" publisher":" MicrosoftWindowsServer",
" offer":" WindowsServer",
" sku":" 2016-Datacenter",
" version":" latest"
},
" imageReference":" [variables(parameters('OS'))]"
},
" resources" ;: [
{
" type":" Microsoft.Compute / availabilitySets",
" name":" [variables('availabilitySetName')]",
" apiVersion":" 2016-04-30-preview",
" location":" [parameters('location')] ",
" properties" ;: {
" platformFaultDomainCount":2,
" platformUpdateDomainCount":2,
" managed":true
}
},
{
" type":" Microsoft.Network/virtualNetworks",
" name":" [variables('virtualNetworkName')]" ,
" apiVersion":" 2016-03-30",
" location":" [parameters('location')]",
" properties&qu ot;:{
" addressSpace":{
" addressPrefixes":[
" [variables('addressPrefix')]"
]
},
" subnets":[
{
" name":" [variables('subnet1Name')]",
" properties" ;: {
" addressPrefix":" [variables('subnet1Prefix')]"
}
}
]
}
},
{
" type":" Microsoft.Network/networkInterfaces",
" name":"[concat('nic',copyindex())]",
" apiVersion":" 2016-03-30",
" location" ;:" [parameters('location')]",
" copy" ;: {
" name":" nicLoop",
" count":" [参数( 'numberOfInstances')]"
},
" dependsOn":[
" [variables('virtualNetworkName')]"
],
" properties" ;: {
" ipConfigurations":[
{
" name":" ipconfig1",
" ; properties":{
" privateIPAllocationMethod":" Dynamic",
" subnet":{
" id":" [variables('subnet1Ref')]"
}
}
}
]
}
},
{
" type":" Microsoft.Compute / virtualMachines",
" name":" [concat('myvm',copyIndex())]",
" apiVersion":" 2016-04-30-preview",
" location":"[parameters('location')]",
" copy":{
" name":" virtualMachineLoop",
"count":"[parameters('numberOfInstances')]"
},
" dependsOn":[
" nicLoop"
],
" properties" ;: {
" availabilitySet":{
" id":" [resourceId('Microsoft.Compute / availabilitySets',variables( 'availabilitySetName'))]"
},
" hardwareProfile":{
" vmSize":" [parameters('vmSizes')]"
},
" osProfile":{
" computerName":" [concat('vm',copyIndex())]",
" adminUsername" :" [parameters('adminUsername')]",
" adminPassword":" [parameters('adminPassword')]"
},
" storageProfile":{
" imageReference":" [variables('imageReference')]",
" osDisk":{
" createOption":" FromImage"
}
},
" networkProfile" ;: {
" networkInterfaces":[
{
" id":" [resourceId( 'Microsoft.Network/networkInterfaces',concat('nic',copyindex()))]"
}
]
}
}
}
]
}
schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "adminUsername": { "type": "string", "metadata": { "description": "Admin username for VM" } }, "adminPassword": { "type": "securestring", "metadata": { "description": "Admin password for VMs" } }, "numberOfInstances": { "type": "int", "defaultValue": 2, "minValue": 2, "maxValue": 5, "metadata": { "description": "Number of VMs to deploy, limit 5 since this sample is using a single storage account" } }, "OS": { "type": "string", "defaultValue": "Ubuntu", "allowedValues": [ "Ubuntu", "Windows" ], "metadata": { "description": "OS Platform for the VM" } }, "location": { "type": "string", "defaultValue": "[resourceGroup().location]", "metadata": { "description": "Location for all resources." } }, "vmSizes": { "type": "string", "allowedValues": [ "Basic_A0", "Standard_D1_v2" ], "defaultValue": "Standard_D1_v2", "metadata": { "description": "The type of replication to use for the VM size." } } }, "variables": { "virtualNetworkName": "myVNET", "addressPrefix": "10.0.0.0/16", "subnet1Name": "Subnet-1", "subnet1Prefix": "10.0.0.0/24", "subnet1Ref": "[resourceId('Microsoft.Network/virtualNetworks/subnets',variables('virtualNetworkName'),variables('subnet1Name'))]", "availabilitySetName": "myAvSet", "Ubuntu": { "publisher": "Canonical", "offer": "UbuntuServer", "sku": "16.04.0-LTS", "version": "latest" }, "Windows": { "publisher": "MicrosoftWindowsServer", "offer": "WindowsServer", "sku": "2016-Datacenter", "version": "latest" }, "imageReference": "[variables(parameters('OS'))]" }, "resources": [ { "type": "Microsoft.Compute/availabilitySets", "name": "[variables('availabilitySetName')]", "apiVersion": "2016-04-30-preview", "location": "[parameters('location')]", "properties": { "platformFaultDomainCount": 2, "platformUpdateDomainCount": 2, "managed": true } }, { "type": "Microsoft.Network/virtualNetworks", "name": "[variables('virtualNetworkName')]", "apiVersion": "2016-03-30", "location": "[parameters('location')]", "properties": { "addressSpace": { "addressPrefixes": [ "[variables('addressPrefix')]" ] }, "subnets": [ { "name": "[variables('subnet1Name')]", "properties": { "addressPrefix": "[variables('subnet1Prefix')]" } } ] } }, { "type": "Microsoft.Network/networkInterfaces", "name": "[concat('nic', copyindex())]", "apiVersion": "2016-03-30", "location": "[parameters('location')]", "copy": { "name": "nicLoop", "count": "[parameters('numberOfInstances')]" }, "dependsOn": [ "[variables('virtualNetworkName')]" ], "properties": { "ipConfigurations": [ { "name": "ipconfig1", "properties": { "privateIPAllocationMethod": "Dynamic", "subnet": { "id": "[variables('subnet1Ref')]" } } } ] } }, { "type": "Microsoft.Compute/virtualMachines", "name": "[concat('myvm', copyIndex())]", "apiVersion": "2016-04-30-preview", "location": "[parameters('location')]", "copy": { "name": "virtualMachineLoop", "count": "[parameters('numberOfInstances')]" }, "dependsOn": [ "nicLoop" ], "properties": { "availabilitySet": { "id": "[resourceId('Microsoft.Compute/availabilitySets', variables('availabilitySetName'))]" }, "hardwareProfile": { "vmSize": "[parameters('vmSizes')]" }, "osProfile": { "computerName": "[concat('vm', copyIndex())]", "adminUsername": "[parameters('adminUsername')]", "adminPassword": "[parameters('adminPassword')]" }, "storageProfile": { "imageReference": "[variables('imageReference')]", "osDisk": { "createOption": "FromImage" } }, "networkProfile": { "networkInterfaces": [ { "id": "[resourceId('Microsoft.Network/networkInterfaces',concat('nic', copyindex()))]" } ] } } } ] }

参考:  https://stackoverflow.com/questions/50593595/arm-template-how-create-multiple-vms-with-private-ips-in-one-resource-group 功能

Reference: https://stackoverflow.com/questions/50593595/arm-template-how-create-multiple-vms-with-private-ips-in-one-resource-group 

问候, 

Msrini


这篇关于使用ARM模板部署多个虚拟机,将privateip分配为静态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆