2016-01-21 12 views
0

我使用CentOS-2nics-lb-cluster azure模板生成负载平衡和NAT规则,该规则为其创建的虚拟机中的每个虚拟机启用特定的SSH端口。用于为每个虚拟机创建公共静态IP地址的Azure模板

我现在的ssh配置的样子

ssh [email protected] -p 50000 // aka vm0 
ssh [email protected] -p 50001 // aka vm1 

就我而言,我真的需要创建一个唯一的主机名每个虚拟机的

ssh [email protected] -p 22 
ssh [email protected] -p 22 

可有人建议如何我可以改变下面的模板部分来实现这个?

{ 
    "apiVersion": "2015-05-01-preview", 
    "name": "[variables('lbName')]", 
    "type": "Microsoft.Network/loadBalancers", 
    "location": "[resourceGroup().location]", 
    "dependsOn": [ 
    "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]" 
    ], 
    "properties": { 
    "frontendIPConfigurations": [ 
     { 
     "name": "LoadBalancerFrontEnd", 
     "properties": { 
      "publicIPAddress": { 
      "id": "[variables('publicIPAddressID')]" 
      } 
     } 
     } 
    ], 
    "backendAddressPools": [ 
     { 
     "name": "BackendPool1" 
     } 
    ], 
    "inboundNatRules": [ 
     { 
     "name": "ssh0", 
     "properties": { 
      "frontendIPConfiguration": { 
      "id": "[variables('frontEndIPConfigID')]" 
      }, 
      "protocol": "tcp", 
      "frontendPort": 50000, 
      "backendPort": 22, 
      "enableFloatingIP": false 
     } 
     }, 
     { 
     "name": "ssh1", 
     "properties": { 
      "frontendIPConfiguration": { 
      "id": "[variables('frontEndIPConfigID')]" 
      }, 
      "protocol": "tcp", 
      "frontendPort": 50001, 
      "backendPort": 22, 
      "enableFloatingIP": false 
     } 
     }, 
     { 
     "name": "ssh2", 
     "properties": { 
      "frontendIPConfiguration": { 
      "id": "[variables('frontEndIPConfigID')]" 
      }, 
      "protocol": "tcp", 
      "frontendPort": 50002, 
      "backendPort": 22, 
      "enableFloatingIP": false 
     } 
     } 
    ], 
    "loadBalancingRules": [ 
     { 
     "name": "LBRule", 
     "properties": { 
      "frontendIPConfiguration": { 
      "id": "[variables('frontEndIPConfigID')]" 
      }, 
      "backendAddressPool": { 
      "id": "[variables('lbPoolID')]" 
      }, 
      "protocol": "tcp", 
      "frontendPort": 80, 
      "backendPort": 80, 
      "enableFloatingIP": true, 
      "idleTimeoutInMinutes": 10, 
      "probe": { 
      "id": "[variables('lbProbeID')]" 
      } 
     } 
     } 
    ], 
+0

每个虚拟机主机名是什么,我需要,并通过ssh在同一个端口上的每一个能力。 – emeraldjava

+0

其实忽略我以前的评论,我是多任务处理,误读你要找的东西!您可以添加额外的IP来执行您正在查找的内容,但我不确定这是如何通过模板完成的。我需要进行一些调查以找出正确的语法 - –

+0

您是否可以扩展手动步骤,以便通过天蓝色的用户界面向特定VM添加额外的IP? – emeraldjava

回答

1

要具有唯一的主机名和相同的端口连接到每个虚拟机,你就需要一个公网IP地址分配给每个虚拟机。但请注意,IPv4公有IP地址很稀缺,建议使用NAT规则访问负载均衡器后面的虚拟机。您能否提供额外的背景知道为什么在同一个端口&上连接唯一的主机名很重要?

万一这是绝对需要的,下面是模板的相关部分添加公共IP地址给虚拟机。您需要创建一个资源,然后将其分配给NetworkInterfaces资源,然后将该资源分配给VirtualMachines资源。

看看这里的完整的模板,https://github.com/Azure/azure-quickstart-templates/blob/master/101-vm-sshkey/azuredeploy.json#L127

{ 
    "apiVersion": "[variables('apiVersion')]", 
    "type": "Microsoft.Network/publicIPAddresses", 
    "name": "[variables('publicIPAddressName')]", 
    "location": "[variables('location')]", 
    "properties": { 
    "publicIPAllocationMethod": "[variables('publicIPAddressType')]", 
    "dnsSettings": { 
     "domainNameLabel": "[parameters('dnsLabelPrefix')]" 
    } 
    } 
}, 
{ 
    "apiVersion": "[variables('apiVersion')]", 
    "type": "Microsoft.Network/networkInterfaces", 
    "name": "[variables('nicName')]", 
    "location": "[variables('location')]", 
    "dependsOn": [ 
    "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", 
    "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" 
    ], 
    "properties": { 
    "ipConfigurations": [ 
     { 
     "name": "ipconfig1", 
     "properties": { 
      "privateIPAllocationMethod": "Dynamic", 
      "publicIPAddress": { 
      "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]" 
      }, 
      "subnet": { 
      "id": "[variables('subnet1Ref')]" 
      } 
     } 
     } 
    ] 
    } 
}, 
{ 
    "apiVersion": "[variables('apiVersion')]", 
    "type": "Microsoft.Compute/virtualMachines", 
    "name": "[parameters('vmName')]", 
    "location": "[variables('location')]", 
    "dependsOn": [ 
    "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]", 
    "[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" 
    ], 
    "properties": { 
    "hardwareProfile": { 
     "vmSize": "[parameters('vmSize')]" 
    }, 
    "osProfile": { 
     "computerName": "[parameters('vmName')]", 
     "adminUsername": "[parameters('adminUsername')]", 
     "linuxConfiguration": { 
     "disablePasswordAuthentication": "true", 
     "ssh": { 
      "publicKeys": [ 
      { 
       "path": "[variables('sshKeyPath')]", 
       "keyData": "[parameters('sshKeyData')]" 
      } 
      ] 
     } 
     } 
    }, 
    "storageProfile": { 
     "imageReference": { 
     "publisher": "[variables('imagePublisher')]", 
     "offer": "[variables('imageOffer')]", 
     "sku": "[parameters('ubuntuOSVersion')]", 
     "version": "latest" 
     }, 
     "osDisk": { 
     "name": "osdisk", 
     "vhd": { 
      "uri": "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/', variables('osDiskName'),'.vhd')]" 
     }, 
     "caching": "ReadWrite", 
     "createOption": "FromImage" 
     } 
    }, 
    "networkProfile": { 
     "networkInterfaces": [ 
     { 
      "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]" 
     } 
     ] 
    }, 
    "diagnosticsProfile": { 
     "bootDiagnostics": { 
     "enabled": "true", 
     "storageUri": "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net')]" 
     } 
    } 
    } 
}