zoukankan      html  css  js  c++  java
  • Windows Azure Virtual Network (5) 设置Azure Virtual Machine固定Private IP

      《Windows Azure Platform 系列文章目录

       

      注意:本文介绍的是Global Azure (http://www.windowsazure.com),如果你使用的是由世纪互联运维的Azure China,请参考下面的连接。

      Azure China (8) 使用Azure PowerShell创建虚拟机,并设置固定Virtual IP Address和Private IP 

      熟悉Azure Virtual Network的读者都知道,如果我们设置了Azure Virtual Network (VNet)的IP Rang是xxx.xxx.0.0 - xxx.xxx.0.255

      那第一个加入VNet的虚拟机Private IP为0.4(0.0到0.3的IP地址被系统占用),第二个加入VNet的虚拟机Private IP为0.5,以后加入VNet的虚拟机Private IP地址为在已创建的Azure Private IP上加1。

      但是这样会产生3个问题:

      1.不能手动设置Private IP地址,Private IP是系统自动生成的,无法预先设置。

      2.无法修改Private IP地址。在系统自动分配Private IP之后,想手动修改Private IP也是不可能的。

      3.无法固定Private IP地址。在某些情况下,Azure管理人员关闭了VM,造成VM的状态为Stop(Deallocate)的情况下,再次启动Azure VM会造成Private IP改变。

      最新的PowerShell (版本号: PowerShell cmdlets for Windows Azure Version 0.7.3)命令增加了新的PowerShell命令,允许用户设置Azure VM Private IP。这4个命令是:

      -  Get-AzureStaticVNetIP

      -  Set-AzureStaticVNetIP

      -  Remove-AzureStaticVNetIP

      -  Test-AzureStaticVNetIP

      接下来,笔者会详细介绍以上的PowerShell命令。

      在开始演示之前,请按照[New Portal]Windows Azure Virtual Machine (16) 使用Azure PowerShell创建Azure Virtual Machine中的内容,通过PowerShell将本地证书上传至Azure云端。

      在上一章内容中,笔者已经创建Azure Virtual Network:MyVNet。同时创建了2台Azure VM,分别为:

    IP 说明
    192.168.0.0-192.168.0.3 Azure Virtual Network 保留
    192.168.0.4 AD Server
    192.168.0.5 Web Server 001

      在这里,笔者将介绍如何创建第2台Web服务器,即Web Server 002进行负载均衡,并且观察Web Server 002的Private IP设置。

      1.确认某个Private IP是否可用

      我们要用到的命令是Test-AzureStaticVNetIP:

    Test-AzureStaticVNetIP –VNetName <VNetName> –IPAddress <Address>

      比如我要查询MyVNet这个虚拟网络中,Private IP为192.168.0.4是否可用,PowerShell命令为:

    Test-AzureStaticVNetIP –VNetName MyVNet –IPAddress 192.168.0.4

      执行结果为:

      

      可以看到IsAvailable值为False(因为192.168.0.4已经被AD Server占用了)。

      然后Azure会在AvailableAddresses中,提供其他可用的IP地址,比如192.168.0.6,192.168.0.7等等

      

      2.创建新的虚拟机,同时设置Private IP

      我们用到的命令是Set-AzureStaticVNetIP

    Set-AzureStaticVNetIP -IPAddress  <YourIPAddress>

    来创建个更加复杂的Azure Virtual Machine

    首先我们指定默认的存储,在Powershell输入以下命令:

    Set-AzureSubscription -SubscriptionName 'Windows Azure MSDN - Visual Studio Ultimate' -CurrentStorageAccount 'leivms'

       按照以下规格创建虚拟机:

    -  DNS Name为LeiWeb (需要负载均衡)

    -  显示名称为LeiWeb002

    -  VM Size为Basic_A1 (1Core/1.75GB)

    -  VM Image为Windows Server 2012 DataCenter 201403.01-en.us

    -  Windows用户名为leizhang,密码为Pass@word1

    -  storage account为leivms

    -  地缘组为EastAsiaGroup

    -  虚拟网络为 MyVNet,子网为Subnet-1

    -  Private IP设置为192.168.0.7

    然后我们输入以下命令:

    $vm = New-AzureVMConfig -Name 'LeiWeb002' -InstanceSize Basic_A1 -ImageName (Get-AzureVMImage)[52].ImageName 
    
    $vm | Add-AzureProvisioningConfig `  -Windows ` -AdminUsername 'leizhang' `  -Password 'Pass@word1'
    
    $vm | Set-AzureSubnet -SubnetNames 'Subnet-1' |  Set-AzureStaticVNetIP -IPAddress 192.168.0.7
    
    $vm | New-AzureVM -ServiceName 'LeiWeb' -VNetName 'MyVNet'

      执行结果,如下图:

      

      我们也可以在Management Portal上查看到Azure正在开始创建LeiWeb002这台虚拟机,截图下图:

      

      执行完毕后,我们可以查看到虚拟机LeiWeb002的Private IP设置为 192.168.0.7。如下图:

      

      另外告诉各位读者一个特大喜讯:如果你在VNet中的Virtual Machine已经通过Set-AzureStaticVNetIP命令,设置了Private IP。

      即使你的VM关机后状态变成Stop_Deallocate,重新开机后这台VM的Private IP还是不会改变的。 O YEAH!!!

      3.修改Private IP

      这里用到的命令为Set-AzureStaticVNetIP

    Set-AzureStaticVNetIP -IPAddress <NewIPAddress>

      之前笔者创建的LeiWeb002的Private IP为192.168.0.7,如果需要重新设置怎么办?

      LeiWeb002这台虚拟机的信息如下:

      -  DNS: LeiWeb.cloudapp.net

      -  Virtual Machine: LeiWeb002

      -  设置新的Private IP : 192.168.0.6

      然后执行以下PowerShell命令:

    Get-AzureVM -ServiceName LeiWeb -Name LeiWeb002 | Set-AzureStaticVNetIP -IPAddress 192.168.0.6 | Update-AzureVM

      执行结果截图如下:

      

      我们可以通过Management Portal查看LeiWeb002这台虚拟机的Private IP已经被修改为192.168.0.6

      

      

      最后我们回顾一下配置的虚拟机信息:

    IP 说明
    192.168.0.0-192.168.0.3 Azure Virtual Network 保留
    192.168.0.4 AD Server
    192.168.0.5 Web Server 001

    192.168.0.6 Web Server 002

  • 相关阅读:
    .Net平台AOP技术概览
    ARP&ICMP
    .NET面向上下文、AOP架构模式(概述)
    Attribute在拦截机制上的应用
    .NET面向上下文、AOP架构模式(实现)
    使用RequireJS优化Web应用前端
    使用asp.net MVC4创建兼容各种设备显示的web应用程序
    entity framework for asp.net mvc
    jquery多功能软键盘插件
    优美登录页面源码(一)
  • 原文地址:https://www.cnblogs.com/threestone/p/3802747.html
Copyright © 2011-2022 走看看