【问题标题】:How to RDP into Azure VMSS VMs如何 RDP 到 Azure VMSS 虚拟机
【发布时间】:2018-04-22 07:13:05
【问题描述】:

按照下面的链接,我能够创建一个带有自定义 VHD 的 Azure VMSS,它支持负载平衡和自动缩放。
Updating VHD of Azure VM ScaleSet

但是使用上面的链接,我必须在同一个 VNET 中创建一个新的 VM,以便 RDP 进入 VMSS 中的 VM。

有什么方法可以直接 RDP 进入 VMSS 中的 VM 吗?

【问题讨论】:

    标签: azure virtual-machine load-balancing autoscaling


    【解决方案1】:

    如果您不想创建跳转框,在某些地区 Azure Bastion 是替代方法。如果单击 VM 实例名称,您可以看到菜单刀片 Bastion

    【讨论】:

      【解决方案2】:

      有什么方法可以直接 RDP 进入 VMSS 中的 VM 吗?

      根据您的描述,我们可以在该负载均衡器中配置 NAT 规则。

      这是一个模板,使用现有的 VHD 创建 VMSS 并配置 NAT 规则(3389)、负载平衡规则(端口 80)和 CPU 自动缩放:

      {
        "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
        "contentVersion": "1.0.0.0",
        "parameters": {
          "vmSku": {
            "type": "string",
            "defaultValue": "Standard_D1",
            "metadata": {
              "description": "Size of VMs in the VM Scale Set."
            }
          },
          "sourceImageVhdUri": {
                  "type": "string",
                  "metadata": {
                      "description": "The source of the blob containing the custom image"
                  }
              },
          "vmssName": {
            "type": "string",
            "metadata": {
              "description": "String used as a base for naming resources. Must be 3-61 characters in length and globally unique across Azure. A hash is prepended to this string for some resources, and resource-specific information is appended."
            },
            "maxLength": 61
          },
          "instanceCount": {
            "type": "int",
            "metadata": {
              "description": "Number of VM instances (100 or less)."
            },
            "maxValue": 100
          },
          "adminUsername": {
            "type": "string",
            "metadata": {
              "description": "Admin username on all VMs."
            }
          },
          "adminPassword": {
            "type": "securestring",
            "metadata": {
              "description": "Admin password on all VMs."
            }
          },
          "frontEndLBPort": {
            "type": "int",
            "metadata": {
              "description": "The front end port to load balance"
            },
            "defaultValue": 80
          },
          "backEndLBPort": {
            "type": "int",
            "metadata": {
              "description": "The back end port to load balance"
            },
            "defaultValue": 80
          },
          "probeIntervalInSeconds": {
            "type": "int",
            "metadata": {
              "description": "The interval between load balancer health probes"
            },
            "defaultValue": 15
          },
          "numberOfProbes": {
            "type": "int",
            "metadata": {
              "description": "The number of probes that need to fail before a VM instance is deemed unhealthy"
            },
            "defaultValue": 5
          },
          "probeRequestPath": {
            "type": "string",
            "metadata": {
              "description": "The path used for the load balancer health probe"
            },
            "defaultValue": "/iisstart.htm"
          }
        },
        "variables": {
          "namingInfix": "[toLower(substring(concat(parameters('vmssName'), uniqueString(resourceGroup().id)), 0, 9))]",
          "longNamingInfix": "[toLower(parameters('vmssName'))]",
          "addressPrefix": "10.0.0.0/16",
          "subnetPrefix": "10.0.0.0/24",
          "virtualNetworkName": "[concat(variables('namingInfix'), 'vnet')]",
          "publicIPAddressName": "[concat(variables('namingInfix'), 'pip')]",
          "subnetName": "[concat(variables('namingInfix'), 'subnet')]",
          "loadBalancerName": "[concat(variables('namingInfix'), 'lb')]",
          "publicIPAddressID": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]",
          "lbID": "[resourceId('Microsoft.Network/loadBalancers',variables('loadBalancerName'))]",
          "natPoolName": "[concat(variables('namingInfix'), 'natpool')]",
          "bePoolName": "[concat(variables('namingInfix'), 'bepool')]",
          "lbFEName": "loadBalancerFrontEnd",
          "lbWebProbeName": "loadBalancerWebProbe",
          "natStartPort": 50000,
          "natEndPort": 50119,
          "natBackendPort": 3389,
          "nicName": "[concat(variables('namingInfix'), 'nic')]",
          "ipConfigName": "[concat(variables('namingInfix'), 'ipconfig')]",
          "frontEndIPConfigID": "[concat(variables('lbID'),'/frontendIPConfigurations/loadBalancerFrontEnd')]",
          "lbFEIPConfigID": "[concat(variables('lbID'),'/frontendIPConfigurations/',variables('lbFEName'))]",
          "lbBEAddressPoolID": "[concat(variables('lbID'),'/backendAddressPools/',variables('bePoolName'))]",
          "lbWebProbeID": "[concat(variables('lbID'),'/probes/',variables('lbWebProbeName'))]",
          "computeApiVersion": "2016-04-30-preview",
          "networkApiVersion": "2016-03-30",
          "storageApiVersion": "2015-06-15",
          "insightsApiVersion": "2015-04-01"
        },
        "resources": [
          {
            "type": "Microsoft.Network/virtualNetworks",
            "name": "[variables('virtualNetworkName')]",
            "location": "[resourceGroup().location]",
            "apiVersion": "[variables('networkApiVersion')]",
            "properties": {
              "addressSpace": {
                "addressPrefixes": [
                  "[variables('addressPrefix')]"
                ]
              },
              "subnets": [
                {
                  "name": "[variables('subnetName')]",
                  "properties": {
                    "addressPrefix": "[variables('subnetPrefix')]"
                  }
                }
              ]
            }
          },
          {
            "type": "Microsoft.Network/publicIPAddresses",
            "name": "[variables('publicIPAddressName')]",
            "location": "[resourceGroup().location]",
            "apiVersion": "[variables('networkApiVersion')]",
            "properties": {
              "publicIPAllocationMethod": "Dynamic",
              "dnsSettings": {
                "domainNameLabel": "[variables('longNamingInfix')]"
              }
            }
          },
          {
            "type": "Microsoft.Network/loadBalancers",
            "name": "[variables('loadBalancerName')]",
            "location": "[resourceGroup().location]",
            "apiVersion": "[variables('networkApiVersion')]",
            "dependsOn": [
              "[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]"
            ],
            "properties": {
              "frontendIPConfigurations": [
                {
                  "name": "LoadBalancerFrontEnd",
                  "properties": {
                    "publicIPAddress": {
                      "id": "[variables('publicIPAddressID')]"
                    }
                  }
                }
              ],
              "backendAddressPools": [
                {
                  "name": "[variables('bePoolName')]"
                }
              ],
              "inboundNatPools": [
                {
                  "name": "[variables('natPoolName')]",
                  "properties": {
                    "frontendIPConfiguration": {
                      "id": "[variables('frontEndIPConfigID')]"
                    },
                    "protocol": "tcp",
                    "frontendPortRangeStart": "[variables('natStartPort')]",
                    "frontendPortRangeEnd": "[variables('natEndPort')]",
                    "backendPort": "[variables('natBackendPort')]"
                  }
                }
              ],
              "loadBalancingRules": [
                {
                  "name": "weblb",
                  "properties": {
                    "frontendIPConfiguration": {
                      "id": "[variables('lbFEIPConfigID')]"
                    },
                    "backendAddressPool": {
                      "id": "[variables('lbBEAddressPoolID')]"
                    },
                    "probe": {
                      "id": "[variables('lbWebProbeID')]"
                    },
                    "protocol": "tcp",
                    "frontendPort": "[parameters('frontEndLBPort')]",
                    "backendPort": "[parameters('backEndLBPort')]",
                    "enableFloatingIP": false
                  }
                }
              ],
              "probes": [
                {
                  "name": "[variables('lbWebProbeName')]",
                  "properties": {
                    "protocol": "Http",
                    "port": "[parameters('backEndLBPort')]",
                    "intervalInSeconds": "[parameters('probeIntervalInSeconds')]",
                    "numberOfProbes": "[parameters('numberOfProbes')]",
                    "requestPath": "[parameters('probeRequestPath')]"
                  }
                }
              ]
      
            }
          },
          {
            "type": "Microsoft.Compute/virtualMachineScaleSets",
            "name": "[variables('namingInfix')]",
            "location": "[resourceGroup().location]",
            "apiVersion": "[variables('computeApiVersion')]",
            "dependsOn": [
              "[concat('Microsoft.Network/loadBalancers/', variables('loadBalancerName'))]",
              "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
            ],
            "sku": {
              "name": "[parameters('vmSku')]",
              "tier": "Standard",
              "capacity": "[parameters('instanceCount')]"
            },
            "properties": {
              "overprovision": "true",
              "upgradePolicy": {
                "mode": "Manual"
              },
              "virtualMachineProfile": {
                "storageProfile": {
                  "osDisk": {
                   "name": "vmssosdisk",
                   "createOption": "FromImage",
                   "osType": "Windows",
                   "image": {
                    "uri": "[parameters('sourceImageVhdUri')]"
                   }
                  }
                },
                "osProfile": {
                  "computerNamePrefix": "[variables('namingInfix')]",
                  "adminUsername": "[parameters('adminUsername')]",
                  "adminPassword": "[parameters('adminPassword')]"
                },
                "networkProfile": {
                  "networkInterfaceConfigurations": [
                    {
                      "name": "[variables('nicName')]",
                      "properties": {
                        "primary": "true",
                        "ipConfigurations": [
                          {
                            "name": "[variables('ipConfigName')]",
                            "properties": {
                              "subnet": {
                                "id": "[concat('/subscriptions/', subscription().subscriptionId,'/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'), '/subnets/', variables('subnetName'))]"
                              },
                              "loadBalancerBackendAddressPools": [
                                {
                                  "id": "[concat('/subscriptions/', subscription().subscriptionId,'/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Network/loadBalancers/', variables('loadBalancerName'), '/backendAddressPools/', variables('bePoolName'))]"
                                }
                              ],
                              "loadBalancerInboundNatPools": [
                                {
                                  "id": "[concat('/subscriptions/', subscription().subscriptionId,'/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Network/loadBalancers/', variables('loadBalancerName'), '/inboundNatPools/', variables('natPoolName'))]"
                                }
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            }
          },
          {
            "type": "Microsoft.Insights/autoscaleSettings",
            "apiVersion": "[variables('insightsApiVersion')]",
            "name": "autoscalewad",
            "location": "[resourceGroup().location]",
            "dependsOn": [
              "[concat('Microsoft.Compute/virtualMachineScaleSets/', variables('namingInfix'))]"
            ],
            "properties": {
              "name": "autoscalewad",
              "targetResourceUri": "[concat('/subscriptions/',subscription().subscriptionId, '/resourceGroups/',  resourceGroup().name, '/providers/Microsoft.Compute/virtualMachineScaleSets/', variables('namingInfix'))]",
              "enabled": true,
              "profiles": [
                {
                  "name": "Profile1",
                  "capacity": {
                    "minimum": "1",
                    "maximum": "10",
                    "default": "1"
                  },
                  "rules": [
                    {
                      "metricTrigger": {
                        "metricName": "Percentage CPU",
                        "metricNamespace": "",
                        "metricResourceUri": "[concat('/subscriptions/',subscription().subscriptionId, '/resourceGroups/',  resourceGroup().name, '/providers/Microsoft.Compute/virtualMachineScaleSets/', variables('namingInfix'))]",
                        "timeGrain": "PT1M",
                        "statistic": "Average",
                        "timeWindow": "PT5M",
                        "timeAggregation": "Average",
                        "operator": "GreaterThan",
                        "threshold": 60.0
                      },
                      "scaleAction": {
                        "direction": "Increase",
                        "type": "ChangeCount",
                        "value": "1",
                        "cooldown": "PT1M"
                      }
                    },
                    {
                      "metricTrigger": {
                        "metricName": "Percentage CPU",
                        "metricNamespace": "",
                        "metricResourceUri": "[concat('/subscriptions/',subscription().subscriptionId, '/resourceGroups/',  resourceGroup().name, '/providers/Microsoft.Compute/virtualMachineScaleSets/', variables('namingInfix'))]",
                        "timeGrain": "PT1M",
                        "statistic": "Average",
                        "timeWindow": "PT5M",
                        "timeAggregation": "Average",
                        "operator": "LessThan",
                        "threshold": 30.0
                      },
                      "scaleAction": {
                        "direction": "Decrease",
                        "type": "ChangeCount",
                        "value": "1",
                        "cooldown": "PT5M"
                      }
                    }
                  ]
                }
              ]
            }
          }
        ]
      }
      

      更多关于这个模板的信息,请参考这个link

      【讨论】:

      • 感谢@Jason 这么快回答。我测试了上面的模板,并能够将 RDP 导入到 VMSS 内的 VM 中。再次感谢您提供模板。
      • NAT 端口范围是否有原因?为什么它从 50000 到 50119?有必要在这个范围内包含这么多端口,还是只能是一个端口?
      猜你喜欢
      • 2016-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多