如何以编程方式使用新资源管理器模型将多个虚拟机部署到单个云服务?

How to deploy multiple virtual machines to single cloud service with the new Resource Manager model programmatically?

目前我正在使用此代码将多个 VM 部署到单个云服务:

private async Task 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);

        }
    }

如何使用新的资源管理器完成此操作?我在 Visual Studio 2015 年工作,MVC 应用程序。

问题是在将多个虚拟机部署到云服务时,所有虚拟机都具有相同的 domain/ip。但我希望每个虚拟机都有自己的域。我听说这可以用资源管理器来完成,但我真的不知道资源管理器到底是什么,也不知道如何使用它。

此外,我知道将每个 VM 部署到单个云服务会为每个 VM 提供唯一的域名,但这意味着我必须为每个虚拟机创建新的云服务,而我真正需要的是部署多个vm 到单个云服务。

这可以通过资源管理来完成吗?

新的资源管理器模型没有云服务的概念,您只需将 VM 部署到虚拟网络中,然后通过 public IP 地址将其直接连接到 Internet。然后您可以将您想要的任何域名附加到该 public IP。

无法在资源管理中创建云服务。

根据之前的回答,资源管理器部署模型不存在云服务概念。本文概述了在同一资源组中部署多个虚拟机的一些方法:https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-multiple-vms/