假设我必须在azure上部署200多台虚拟机。每个vm都有一个网站,每个vm都必须有唯一的域/ip地址。
我可以将每个vm部署到单独的cloude服务(并且有不同的ip),但是每次订阅的cloude服务的限制是200,因此我只能使用200个vm(网站)。
但是,如果我在一个云服务中部署多个vm(限制为每个云服务50个vm),该怎么办?我这样,我可以有50个vm的每云服务* 200云服务每次订阅!
问题是vm必须有不同的域/ ip,当我将多个vm部署到一个cloude服务时,所有vm都有相同的域和ip。
用于将多个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);
}
}发布于 2016-05-24 08:06:59
如果希望每个VM在云服务中拥有自己的IP,那么需要查看实例级公共IP,它们是分配给每个VM的单独IP,而不是云服务。
但是,我建议您也考虑完全放弃使用云服务,转而使用新的基于资源管理器的堆栈。如果您不知道Azure的所有V2资源都离开了云服务模型,而是使用新的资源管理器格式。这种新格式对于您所做的工作有一些重要的优点:
云服务仍然存在,而且还没有宣布要删除它们,但是ARM模型似乎更适合您所要做的事情。
https://serverfault.com/questions/778571
复制相似问题