- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何根据参数 privateonly 或 public 附加公共(public) IP,尝试使用多个虚拟机创建它。我在这里给出了我正在运行的完整模板。
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for the resources."
}
},
"vmName": {
"type": "string",
"defaultValue": "vm",
"metadata": {
"description": "Name for the Virtual Machine."
}
},
"ClusterType": {
"type": "string",
"defaultValue": "3 vm apache",
"metadata": {
"description": "Type of cluster to deploy, this is using a single storage account"
}
},
"adminUsername": {
"type": "string",
"defaultValue": "centos",
"metadata": {
"description": "User name for the Virtual Machine."
}
},
"adminPasswordOrKey": {
"type": "string"
},
"vmSize": {
"type": "string",
"metadata": {
"description": "Size for the Virtual Machine."
}
},
"storageNewOrExisting": {
"type": "string",
"defaultValue": "new"
},
"storageAccountName": {
"type": "string",
"defaultValue": "[concat('storage', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Name of the storage account"
}
},
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"metadata": {
"description": "Storage account type"
}
},
"storageAccountResourceGroupName": {
"type": "string",
"defaultValue": "[resourceGroup().name]",
"metadata": {
"description": "Name of the resource group for the existing storage account"
}
},
"virtualNetworkNewOrExisting": {
"type": "string",
"defaultValue": "new",
"metadata": {
"description": "Determines whether or not a new virtual network should be provisioned."
}
},
"virtualNetworkName": {
"type": "string",
"defaultValue": "VirtualNetwork",
"metadata": {
"description": "Name of the virtual network"
}
},
"addressPrefixes": {
"type": "array",
"defaultValue": [
"10.0.0.0/16"
],
"metadata": {
"description": "Address prefix of the virtual network"
}
},
"subnetName": {
"type": "string",
"defaultValue": "default",
"metadata": {
"description": "Name of the subnet"
}
},
"subnetPrefix": {
"type": "string",
"defaultValue": "10.0.0.0/24",
"metadata": {
"description": "Subnet prefix of the virtual network"
}
},
"virtualNetworkResourceGroupName": {
"type": "string",
"defaultValue": "[resourceGroup().name]",
"metadata": {
"description": "Name of the resource group for the existing virtual network"
}
},
"vmDataDiskSize":{
"type": "string",
"defaultValue": "50",
"metadata": {
"description": "Minimum data disk size should be 50 GB"
},
"publicIpName": {
"type": "string",
"defaultValue": "rxnode",
"metadata": {
"description": "Name of public IP Address"
}
}
},
"variables": {
"publisher": "OpenLogic",
"offer": "CentOS",
"sku": "7.3",
"version": "latest",
"vmBootDiskSize": 50,
"nicName": "[concat(parameters('vmName'), '-nic-')]",
"numberOfVM": "[int(first(parameters('ClusterType')))]",
"apacheinstallation": "[contains(parameters('ClusterType'), 'apache')]",
"networkSecurityGroupName": "[concat(parameters('vmName'), '-nsg-ssh')]",
"publicIpName": "[concat(parameters('vmName'),'-publicip')]"
"privateIp": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[resourceId(parameters('virtualNetworkResourceGroupName'), 'Microsoft.Network/virtualNetworks/subnets/', parameters('virtualNetworkName'), parameters('subnetName'))]"
}
},
"copy": [
{
"name": "publicIPAddress",
"count": "[variables('numberOfVM')]",
"input": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', concat(variables('publicIpName'), copyIndex('publicIPAddress')))]"
}
}
]
},
"resources": [
{
"condition": "[equals(parameters('storageNewOrExisting'), 'new')]",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2018-02-01",
"name": "[parameters('storageAccountName')]",
"location": "[parameters('location')]",
"kind": "Storage",
"sku": {
"name": "[parameters('storageAccountType')]"
}
},
{
"condition": "[equals(parameters('publicIpName'), 'None')]",
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2018-04-01",
"name": "[concat(variables('publicIpName'), copyIndex())]",
"location": "[parameters('location')]",
"copy": {
"name": "ipLoop",
"count": "[variables('numberOfVM')]"
},
"sku": {
"name": "Basic"
},
"properties": {
"publicIPAllocationMethod": "Dynamic"
}
},
{
"condition": "[equals(parameters('virtualNetworkNewOrExisting'), 'new')]",
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2018-04-01",
"name": "[parameters('virtualNetworkName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": "[parameters('addressPrefixes')]"
},
"subnets": [
{
"name": "[parameters('subnetName')]",
"properties": {
"addressPrefix": "[parameters('subnetPrefix')]"
}
}
]
}
},
{
"name": "[variables('networkSecurityGroupName')]",
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2018-04-01",
"location": "[parameters('location')]",
"properties": {
"securityRules": [
{
"name": "default-allow-ssh",
"properties": {
"priority": 1000,
"sourceAddressPrefix": "*",
"protocol": "Tcp",
"destinationPortRange": "22",
"access": "Allow",
"direction": "Inbound",
"sourcePortRange": "*",
"destinationAddressPrefix": "*"
}
},
{
"name": "allow-webport-8080",
"properties": {
"priority": 1200,
"sourceAddressPrefix": "*",
"protocol": "Tcp",
"destinationPortRange": "8080",
"access": "Allow",
"direction": "Inbound",
"sourcePortRange": "*",
"destinationAddressPrefix": "*"
}
}
]
}
},
{
"apiVersion": "2018-04-01",
"type": "Microsoft.Network/networkInterfaces",
"name": "[concat(variables('nicName'), copyIndex())]",
"location": "[parameters('location')]",
"copy": {
"name": "nicLoop",
"count": "[variables('numberOfVM')]"
},
"dependsOn": [
"ipLoop",
"[parameters('virtualNetworkName')]",
"[variables('networkSecurityGroupName')]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": "[if(equals(variables('publicipName'), 'None'), variables('privateIp'), union(variables('privateIp'), variables('publicIPAddress')[copyIndex()]))]" }
],
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
}
}
},
{
"apiVersion": "2018-04-01",
"type": "Microsoft.Compute/virtualMachines",
"name": "[concat(parameters('vmName'), copyIndex())]",
"location": "[parameters('location')]",
"copy": {
"name": "virtualMachineLoop",
"count": "[variables('numberOfVM')]"
},
"dependsOn": [
"[parameters('storageAccountName')]",
"nicLoop"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[concat(parameters('vmName'), copyIndex())]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPasswordOrKey')]",
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"ssh": {
"publicKeys": [
{
"path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]",
"keyData": "[parameters('adminPasswordOrKey')]"
}
]
}
}
},
"storageProfile": {
"imageReference": {
"publisher": "[variables('publisher')]",
"offer": "[variables('offer')]",
"sku": "[variables('sku')]",
"version": "[variables('version')]"
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"diskSizeGB": "[variables('vmBootDiskSize')]"
},
"copy": [
{
"name": "dataDisks",
"count": 1,
"input": {
"caching": "ReadWrite",
"diskSizeGB": "[parameters('vmDataDiskSize')]",
"lun": "[copyIndex('dataDisks')]",
"name": "[concat(parameters('vmName'), '-datadisk', copyIndex(), copyIndex('dataDisks'))]",
"createOption": "Empty"
}
}
]
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', concat(variables('nicName'), copyindex()))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[reference(resourceId(parameters('storageAccountResourceGroupName'), 'Microsoft.Storage/storageAccounts/', parameters('storageAccountName')), '2018-02-01').primaryEndpoints.blob]"
}
}
}
}
],
"outputs": {
}
}
这里我将 json 上下文放入 if 条件中。如果需要附加公共(public)IP,那么它将传递json上下文到publicIPAddress,否则它将传递空值。
最佳答案
您可以使用带有预定义变量的union()
函数来实现这一点。更干净+我不确定你的方法是否适用于所有转义(我认为你不允许使用 json()
函数构建真正的 json;至少我尝试过 - 失败了)。
"variables": {
"publicIP": {
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', concat(variables('publicIpName')))]"
}
},
"privateIp": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[resourceId(parameters('virtualNetworkResourceGroupName'), 'Microsoft.Network/virtualNetworks/subnets/', parameters('virtualNetworkName'), parameters('subnetName'))]"
}
}
}
然后在你的 ipConfigurations 中你可以这样做:
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": "[if(equals(variables('publicipName'), 'None'), variables('privateIp'), union(variables('privateIp'), variables('publicIp'))]"
}
],
当不需要公共(public) IP 时,这将使用 privateIp 变量,并在需要时添加公共(public) IP。
编辑:如果将 copyIndex 与 publicIp 一起使用,您需要执行以下操作:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {
"name": "testo",
"copy": [
{
"name": "publicIPAddress",
"count": 3,
"input": {
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', concat(variables('name'), '-ip-', copyIndex('publicIPAddress')))]"
}
}
}
],
"privateIp": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "resourceId"
}
}
},
"resources": [
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[concat(variables('name'), '-ip-', copyIndex())]",
"location": "[resourceGroup().location]",
"copy": {
"name": "ipLoop",
"count": 3
},
"properties": {
"publicIPAllocationMethod": "Dynamic"
}
},
{
"apiVersion": "2018-04-01",
"type": "Microsoft.Network/networkInterfaces",
"name": "[concat(variables('name'), copyIndex())]",
"location": "[resourceGroup().location]",
"dependsOn": [
"ipLoop"
],
"copy": {
"name": "nicLoop",
"count": 3
},
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": "[union(variables('privateIp'), variables('publicIPAddress')[copyIndex()])]"
}
]
}
}
]
}
关于azure - 根据多个 VM 的 public 或 privateonly 等参数将公共(public) IP 连接到网卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54473535/
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭11 年前。 Improve th
我是 Azure 平台的初学者。我在公司的 Azure 基础架构中遇到了虚拟机问题,在我从操作系统重新启动后,该虚拟机无法启动,我尝试了所有其他故障排除功能,但仍遇到以下问题: 重新部署选项。 我想确
我在 Mac 上使用 XAMPP-VM,我尝试使用 xampp 管理器上显示的地址通过 ssh 连接到 VM: 192.168.65.2 我意识到我不知道 VM 的 root 密码和任何 ssh-ke
我知道你可以在 Dalvik 的 VM 中运行几乎所有的 Java,而你可以在 Java 的 VM 中运行,但是限制不是很清楚。有没有人遇到任何主要的绊脚石?有什么大图书馆有问题吗?任何编译成 Jav
Azure VM 备份失败,出现错误 - GuestAgentSnapshotTaskStatusErrorAzure 备份服务无法与 VM 代理通信以触发快照(以进行备份),因为 VM 代理可能处于
我想知道当虚拟机停止时,虚拟机的软件成本部分是否收费。我想运行 Azure SQL VM Enterprise。 VM 每月的软件成本为“1,116 美元/月”。 如果我停止使用,我仍需支付该软件的费
有 2 台安装了 Proxmox (Proxmox-ve 4.2) 的物理服务器,每台都处理几个虚拟机和容器。这些服务器(几乎)完全隔离,它们之间没有集群/共享存储/附加存储等。 已在 proxmox
我想知道当虚拟机停止时,虚拟机的软件成本部分是否收费。我想运行 Azure SQL VM Enterprise。 VM 每月的软件成本为“1,116 美元/月”。 如果我停止使用,我仍需支付该软件的费
有 2 台安装了 Proxmox (Proxmox-ve 4.2) 的物理服务器,每台都处理几个虚拟机和容器。这些服务器(几乎)完全隔离,它们之间没有集群/共享存储/附加存储等。 已在 proxmox
Parrot Virtual Machine 有什么好处?对于最终用户(软件开发人员)? 例如,如果我可以直接针对 Perl 或 Python 进行编程,我为什么还要在 Parrot 下为它们编程呢?
例如,Python 和 Java 有一个 VM,而 C 和 Haskell 没有。 (如果我错了,请纠正我) 想了想线路两边都有哪些语言,找不到原因。 Java 在很多方面都是静态的,而 Haskel
我知道虚拟机镜像有两种类型:通用型和专用型。 如果操作系统已通用化/取消配置,则必须关闭虚拟机才能将其捕获为 VM 镜像。一旦 VM 被捕获为 VM 镜像,该虚拟机将自动删除。 如果操作系统是专用,则
我知道虚拟机镜像有两种类型:通用型和专用型。 如果操作系统已通用化/取消配置,则必须关闭虚拟机才能将其捕获为 VM 镜像。一旦 VM 被捕获为 VM 镜像,该虚拟机将自动删除。 如果操作系统是专用,则
背景信息 我正在开发一种支持网络的嵌入式设备,旨在与服务器进行通信。因为此服务器将运行 Linux(但我需要 Windows 工具进行开发),我正在运行带有 Ubuntu Server 14.04 的
我有一个 Azure 云服务 mywebapp.cloudapp.net,它由两个 Azure VM - mywebappvm1 和 mywebappvm2 组成。两个虚拟机位于同一可用性集中并具有相
有什么方法可以在不重新启动虚拟机的情况下调整现有虚拟机的大小,还是总是像停止虚拟机然后重新启动一样? 据我了解,我可以更改虚拟机的大小而无需重新启动它。请指导我,因为我不希望虚拟机在调整大小时出现任何
我是 Azure 新手。我正在尝试使用 powershell 在 Azure 中创建资源。 我的要求是从虚拟机创建镜像。我遵循了以下方法: 流程 1:手动执行 通用化虚拟机:登录虚拟机 -> 打开命令
我创建了虚拟网络,并且想要将新虚拟机部署到该虚拟网络。网络 我尝试使用以下命令创建虚拟机: az vm create --resource-group myGroup --name VMTestNet
上下文 作为一个大学项目,我们希望更改 pharo 虚拟机以使用对象表,看看会发生什么。 我们使用pharo-vm clone from github和VMMaker。构建虚拟机工作正常。 首先,我们
我是巴拿马型的新手,刚刚安装,但收到以下错误消息: A different VM with name panamax-vm has been created already. 我试图通过使用 pana
我是一名优秀的程序员,十分优秀!