我正在尝试在一个云服务中添加多个虚拟机。
目前,我可以在此云服务中创建一个云服务和一个虚拟机。在此之后,我试图在同一部署中向同一个sloud服务添加另一个虚拟机,这个过程也很成功,但我无法理解的是如何为这个新虚拟机设置不同的URL!?
因为现在,第一个虚拟机的url是myservicename.cloudapp.net,而第二个虚拟机的url是相同的!!他们有相同的IP。怎么会这样?如何在具有相同网址的情况下访问第二个虚拟机?
第一个vm的端口是:80,第二个vm的端口是81。
问题:
如何访问个人vm?
有没有办法让网址像:myservicename.vmname.cloudapp.net? 所以第一个vm url是:myservicename.vmname1.cloudapp.net,以及第二个机器的url:myservicename.vmname2.cloudapp.net
代码:
私有异步任务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);
}
}
答案 0 :(得分:0)
azure云服务(yourdns.cloudapp.net
)具有一个 DNS名称和一个 IP地址。该云服务中的所有VM都位于该单个IP地址后面。如果您设置了端点(例如端口80),那么您可以在所有VM上对该端点进行负载均衡。或者......您可能有一个端口直接映射到特定VM(例如,端口8080将转到您的某个虚拟机上的管理员应用程序)。您会注意到,对于像ssh这样的东西,每个vm都有自己的ssh端口,这是一个映射到特定虚拟机上端口22的端点。
如果您希望您的虚拟机具有不同的IP地址/ DNS名称,则需要:
.cloudapp.net
).cloudapp.net
个构造。