2016-05-23 56 views
-1

我想在一個雲服務中添加多個虛擬機。一個天青雲服務中具有不同網址的多個虛擬機?

現在,我可以在此雲服務中創建一個雲服務和一個虛擬機。在此之後,我試圖在同一個部署中將另一個虛擬機添加到相同的sloud服務中,並且此過程也是成功的,但我無法理解的是如何爲此新虛擬機設置不同的url!?

因爲現在,第一臺虛擬機的網址是myservicename.cloudapp.net,而第二臺虛擬機的網址是一樣的!他們有相同的IP。怎麼會這樣?當它具有相同的URL時,如何訪問第二臺虛擬機?

端口爲第一VM是:80,和第二VM是81

問題:

  1. 如何存取權限單個虛擬機?

  2. 有沒有一種方法來使網址的像:myservicename.vmname.cloudapp.net? 使第一VM網址爲:myservicename.vmname1.cloudapp.net和URL爲第二機器:myservicename.vmname2.cloudapp.net

代碼:

私人異步任務CreateVirtualMachine() { DeploymentGetResponse deploymentResponse =等待_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

的Azure雲服務(yourdns.cloudapp.net)具有一個 DNS名稱和一個 IP地址。該雲服務中的所有虛擬機位於該單個IP地址的後面。如果您設置了端點(例如端口80),那麼您可以讓該端點在所有虛擬機之間進行負載均衡。或者...您可能有一個端口直接映射到特定的虛擬機(例如,端口8080將轉到您的某個虛擬機的管理應用程序)。您會注意到,對於像ssh這樣的事情,每個虛擬機都會獲得自己的ssh端口,這是一個映射到特定虛擬機端口22的端點。

如果你希望你的虛擬機有不同的IP地址/ DNS名稱,你需要:

  • 其拆分成單獨的雲服務(.cloudapp.net
  • 部署他們在新的資源管理模式,你不再有.cloudapp.net結構。
+0

謝謝你的回答。 – gomila

+0

@gomila第一:你應該考慮一個「upvote」和/或接受一個答案是正確的方式說「謝謝」 - 而不是一個評論。第二:請不要在編輯中提出其他問題。問另一個問題。三:這些問題真的是針對ServerFault,而不是StackOverflow。四:根據您的編輯,我認爲您有一些術語混淆(例如,存儲帳戶與VM限制無關)。 –

相關問題