在一个azure云服务中具有不同URL的多个虚拟机?

时间:2016-05-23 15:30:09

标签: azure azure-virtual-machine azure-cloud-services

我正在尝试在一个云服务中添加多个虚拟机。

目前,我可以在此云服务中创建一个云服务和一个虚拟机。在此之后,我试图在同一部署中向同一个sloud服务添加另一个虚拟机,这个过程也很成功,但我无法理解的是如何为这个新虚拟机设置不同的URL!?

因为现在,第一个虚拟机的url是myservicename.cloudapp.net,而第二个虚拟机的url是相同的!!他们有相同的IP。怎么会这样?如何在具有相同网址的情况下访问第二个虚拟机?

第一个vm的端口是:80,第二个vm的端口是81。

问题:

  1. 如何访问个人vm?

  2. 有没有办法让网址像:myservicename.vmname.cloudapp.net? 所以第一个vm url是:myservicename.vmname1.cloudapp.net,以及第二个机器的url:myservicename.vmname2.cloudapp.net

  3. 代码:

    私有异步任务CreateVirtualMachine()     {         DeploymentGetResponse deploymentResponse = await _computeManagementClient.Deployments.GetBySlotAsync(“myservicename”,DeploymentSlot.Production);

        if (deploymentResponse == null)
        {
            var parameters = new VirtualMachineCreateDeploymentParameters
            {
                DeploymentSlot = DeploymentSlot.Production,
                Name = "mservicename",
                Label = "myservicename"
            };
    
            parameters.Roles.Add(new Role
            {
                OSVirtualHardDisk = new OSVirtualHardDisk
                {
                    HostCaching = VirtualHardDiskHostCaching.ReadWrite,
                    SourceImageName = "imagename"
                },
    
                RoleName = "vmname",
                RoleType = VirtualMachineRoleType.PersistentVMRole.ToString(),
                RoleSize = VirtualMachineRoleSize.Small,
                ProvisionGuestAgent = true
            });
    
            parameters.Roles[0].ConfigurationSets.Add(new ConfigurationSet
            {
                ComputerName = "vmname",
                ConfigurationSetType = ConfigurationSetTypes.LinuxProvisioningConfiguration,
                HostName = "vmname",
                AdminUserName = "adminusername",
                AdminPassword = "adminpass",
                UserName = "username",
                UserPassword = "userpass",
                DisableSshPasswordAuthentication = false,
    
            });
    
            parameters.Roles[0].ConfigurationSets.Add(new ConfigurationSet
            {
                ConfigurationSetType = ConfigurationSetTypes.NetworkConfiguration,
                InputEndpoints = new List<InputEndpoint>()
                        {
                            new InputEndpoint()
                            {
                                Name = "HTTP",
                                Protocol = InputEndpointTransportProtocol.Tcp,
                                LocalPort =  80,
                                Port = 80
                            }
                        }
            });
    
            var response = await _computeManagementClient.VirtualMachines.CreateDeploymentAsync("mservicename", parameters);
    
        }
        else
        {
            var createParameters = new VirtualMachineCreateParameters
            {
                OSVirtualHardDisk = new OSVirtualHardDisk
                {
                    HostCaching = VirtualHardDiskHostCaching.ReadWrite,
                    SourceImageName = "imagename"
                },
    
                RoleName = "vmname",
                RoleSize = VirtualMachineRoleSize.Small,
                ProvisionGuestAgent = true,
    
                ConfigurationSets = new List<ConfigurationSet>
                    {
                        new ConfigurationSet
                        {
    
                            ComputerName = "vmname",
                            ConfigurationSetType = ConfigurationSetTypes.LinuxProvisioningConfiguration,
                            HostName = "vmname",
                            AdminUserName = "adminusername",
                            AdminPassword = "adminpass",
                            UserName = "username",
                            UserPassword = "userpass",
                            DisableSshPasswordAuthentication = false
                        },
                        new ConfigurationSet
                        {
                            ConfigurationSetType = ConfigurationSetTypes.NetworkConfiguration,
                            InputEndpoints = new List<InputEndpoint>()
                            {
                                new InputEndpoint()
                                {
                                    Name = "HTTP",
                                    Protocol = InputEndpointTransportProtocol.Tcp,
                                    LocalPort =  81,
                                    Port = 81
                                }
                            }
                        }
                    }
            };
    
            var responseCreate = await _computeManagementClient.VirtualMachines.CreateAsync("mservicename", deploymentResponse.Name, createParameters);
    
        }
    }
    

1 个答案:

答案 0 :(得分:0)

azure云服务(yourdns.cloudapp.net)具有一个 DNS名称和一个 IP地址。该云服务中的所有VM都位于该单个IP地址后面。如果您设置了端点(例如端口80),那么您可以在所有VM上对该端点进行负载均衡。或者......您可能有一个端口直接映射到特定VM(例如,端口8080将转到您的某个虚拟机上的管理员应用程序)。您会注意到,对于像ssh这样的东西,每个vm都有自己的ssh端口,这是一个映射到特定虚拟机上端口22的端点。

如果您希望您的虚拟机具有不同的IP地址/ DNS名称,则需要:

  • 将它们拆分为单独的云服务(.cloudapp.net
  • 将它们部署在新的资源管理器模型中,您不再拥有.cloudapp.net个构造。