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)[].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 |
Windows Azure Virtual Network (5) 设置Azure Virtual Machine固定Private IP的更多相关文章
- Windows Azure Virtual Network (7) 设置Azure Virtual Machine固定公网IP (Virtual IP Address, VIP) (2)
<Windows Azure Platform 系列文章目录> 本文介绍的是,当用户在创建Azure Virtual Machine的时候,忘记绑定公网IP,需要重新绑定公网IP的具体操作 ...
- Windows Azure Virtual Network (6) 设置Azure Virtual Machine固定公网IP (Virtual IP Address, VIP) (1)
<Windows Azure Platform 系列文章目录> 注意:本文介绍的是Global Azure (http://www.windowsazure.com),如果你使用的是由世纪 ...
- Windows Azure Virtual Network (8) 创建Azure Point-to-Site点到站点 VPN
<Windows Azure Platform 系列文章目录> 我们在使用Azure的时候,常常有这样的需求: -我需要将企业内网的主机连接到微软Azure公有云平台 -我需要保证企业内部 ...
- Windows Azure Virtual Network (10) 使用Azure Access Control List(ACL)设置客户端访问权限
<Windows Azure Platform 系列文章目录> 本文介绍的是国内由世纪互联运维的China Azure. 我们在创建完Windows Azure Virtual Machi ...
- Azure PowerShell (13) 批量设置Azure ARM Network Security Group (NSG)
<Windows Azure Platform 系列文章目录> 刚刚在帮助一个合作伙伴研究需求,他们的虚拟机全面的网络安全组(Network Security Group, NSG)会经常 ...
- [SDK2.2]Windows Azure Virtual Network (1) 概念
<Windows Azure Platform 系列文章目录> Windows Azure Virtual Network是非常重要的概念,其主要作用有以下两点: 1.将多台Azure V ...
- Windows Azure Cloud Service (44) 将Cloud Service加入Virtual Network Subnet,并固定Virtual IP Address(VIP)
<Windows Azure Platform 系列文章目录> 在之前的文章中,笔者已经详细介绍了如何将Virtual Machine加入Virtual Network,并且绑定固定的Pr ...
- Azure China (8) 使用Azure PowerShell创建虚拟机,并设置固定Virtual IP Address和Private IP
<Windows Azure Platform 系列文章目录> 本文介绍的是由世纪互联运维的Windows Azure China. 相比于Global Azure (http://www ...
- Windows Azure Virtual Network (11) 创建VNet-to-VNet的连接
<Windows Azure Platform 系列文章目录> 我们知道,Azure Virtual Network可以 1.将对台Azure VM加入到同一个网段里,同时绑定内网IP地址 ...
随机推荐
- hibernate常用API详解
根据个人使用Hibernate的经验,介绍一下Hibernate的多种不同的查询和CUD操作,这些东西在日常开发中非常常用,希望对大家有所帮助. 以下示例均以两张表为例:member和userinfo ...
- nohup
在启动weblogic的时候我们经常看到如下的命令: nohup ./startWebLogic.sh >out.log 2>&1 & 从09年开始用weblogic到现在 ...
- java 泛型的几点备忘
1.在java虚拟机中是没有泛型的,所有泛型类的参数都会被擦除,如下: public void test(List<String> list, int num){} public void ...
- kali linux Python开发环境初始化
kali linux Python 黑客编程1 开发环境初始化 为什么要选择Python? Python作为目前Linux系统下最流行的编程语言之一,对于安全工作者的作用可以和C++相提并论.Pyth ...
- 解决ng界面长表达式(ui-set)
本文来自网友sun shine的问题,问题如下: 您好, 我想求教一个问题. 在$scope中我的对象名字写的特别深, 在 html中我又多次用到了同一个对象, 对不对在 html中让它绑定到一个临时 ...
- Linux head和tail命令
200 ? "200px" : this.width)!important;} --> 介绍 head和tail是一组想对应的命令,默认分别显示文件的开头和末尾10行记录. ...
- 换个角度理解云计算之MapReduce
上一篇简单讲了一下HDFS,简单来说就是一个叫做“NameNode”的大哥,带着一群叫做“DataNode”的小弟,完成了一坨坨数据的存储,其中大哥负责保存数据的目录,小弟们负责数据的真正存储,而大哥 ...
- 关于JavaScript内存泄漏的质疑
近几天看了些关于JavaScript内存管理的文章,相对于Java JVM的内存管理,显得简单些. 在学习的过程中,发现有不少网友谈到了循环引用,说循环引用会造成内存泄漏,垃圾回收器无法回收. 实际上 ...
- node.js小结 2
下载node安装npm什么的就不说了 入门总结 http://www.cnblogs.com/Darren_code/archive/2011/10/31/nodejs.html 进入node_HOM ...
- java ExecutorService
ExecutorService 通常Executor对象会创建并管理一组执行Runnable对象的线程,这组线程被称为线程池,Executor基于生产者-消费者模式.提交任务的执行者是生产者(产生待完 ...