Azure Lei Zhang的博客

weibo: LeiZhang的微博/QQ: 185165016/QQ群:319036205/邮箱:leizhang1984@outlook.com/TeL:139-161-22926

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

  《Windows Azure Platform 系列文章目录》 

 

  

  默认情况下,通过Azure Management Portal创建的Public IP和Private IP都是随机分配的。

  用户可以通过Azure PowerShell来设置固定Public IP和Private IP,请参考笔者的文档:

  Windows Azure Virtual Network (5) 设置Azure Virtual Machine固定Private IP

      Windows Azure Virtual Network (6) 设置Azure Virtual Machine固定公网IP (Virtual IP Address, VIP) (1)

      Windows Azure Virtual Network (7) 设置Azure Virtual Machine固定公网IP (Virtual IP Address, VIP) (2)

 

 

 

 

  在我们日常使用Windows Azure Virtual Machine的时候,如果服务不再被使用,我们就可以停止VM以节省成本。

  一般情况下,有三种方式可以安全停止Azure VM:

  1)使用Azure Management Portal,停止VM 

  2)使用远程桌面连接VM,在远程桌面关闭VM 

  3)使用Windows Azure PowerShell停止VM

  在本章中,我将给大家详细介绍以上三种安全停止Azure VM和固定IP的关系。

   

  注意:本章内容只介绍Single Azure VM。

  我们创建Azure VM并且命名为LeiSingleVM, DNS地址为:http://LeiSingleVM.cloudapp.net

  这台VM的VIP和Internal IP如下图:

  

  

  

  1.使用Azure Management Portal,停止VM

  1)我们可以使用Azure Management Portal的SHUT DOWN按钮,停止Azure VM。如下图:

  

  当我们对某台Azure VM按下SHUT DOWN按钮的时候,该VM的状态会变成Stopped ( Deallocated )。如下图

  

  那这个状态表示什么意思?Deallocated从字面上看是未分配的意思,也就是说,如果你的VM处于Deallocated,那么这台VM的CPU、内存和网络等硬件资源都将处于非活动状态,并且这台VM将不会继续收取费用。嗯,到目前为止看起来一切都不错。但是Deallocated有一个副作用:之前我们说了,Deallocated是释放了硬件资源,但是这台VM下次重新启动时,将会获得一个不同的Internal IP

  Tips:如果你想使用Azure Portal关闭VM,并且还想保持Internal IP,请使用Azure Virtual Network。

  那Public Virtual IP (VIP) Address是否会改变呢?因为本章我们考虑的是单个VM的情况,如果用户使用Azure Portal的SHUT DOWN按钮,停止Azure VM,那这台VM的VIP Address就一定会改变

  那我们点击START按钮,重新启动这台Azure VM。

  

  我们比较一下Azure VM在SHUT DOWN前后,VIP Address与Internal IP Address的变化:

  

   结论:在使用Azure Portal SHUTDOWN VM后,VIP和INTERNAL IP都会改变。

 

  2.使用远程桌面连接VM,在远程桌面关闭VM 

  根据上一步执行的结果,现在Azure VM的IP信息如下:

  VIP Address: 137.116.161.18

  Internal IP Address: 100.80.68.42

  我们使用远程桌面连接LeiSingleVM,并且在远程桌面关闭这台VM。稍等片刻后,我们会发现VM的状态变为Stopped。如下图:

   

  Azure VM在Stopped的状态,仍然会产生计算的费用,因为Azure Fabric 会为这台VM保留硬件资源。更加重要的一点是:在Stopped的状态下,Azure的VIP Address和Internal VIP Address将不会改变。

  我们使用Azure Management Portal Start VM,观察VM在Stopped状态下,VIP Address和Internal IP Address的变化:

  

   结论:在使用RDP STOP VM后,VIP和INTERNAL IP都不会改变。

 

  3.使用Windows Azure PowerShell停止VM

  在最新的Azure PowerShell里,我们在使用Stop-AzureVM命令关闭Azure VM时,可以使用 -StayProvisioned 参数。这个参数的一般性语法如下:

Stop-AzureVM -ServiceName '<DNSNAME>' -Name '<VMNAME>' [-StayProvisioned]

  1)当我们在Azure PowerShell执行Stop-AzureVM命令,没有使用 -StayProvisioned参数,则VM关闭后状态为Stopped(Deallocated),执行结果就类似于我们使用Azure Management Portal来关闭VM。VIP和Internal IP都会改变。

  2)当我们在Azure PowerShell执行Stop-AzureVM命令,使用 -StayProvisioned参数,则VM关闭后状态为Stopped,执行结果就类似于我们使用远程桌面连接,在远程桌面关闭Azure VM。VIP和Internal IP都不会改变。

  如果我想关闭本章创建的Azure VM,并且想保持VIP Address和Internal IP Address,则我们执行以下语句

Stop-AzureVM -ServiceName 'LeiSingleVM' -Name 'LeiSingleVM' -StayProvisioned

  执行结果如下图:

  

 

   我们还可以通过Start-AzureVM,来启动Azure VM。执行语句如下:

Start-AzureVM -ServiceName 'LeiSingleVM' -Name 'LeiSingleVM'

  执行结果如下图:

  

  

 

总结:

  关闭Azure VM方式 Management Portal  远程桌面连接 Azure PowerShell with -StayProvisioned  Azure PowerShell without -StayProvisioned
VIP Address是否改变
Internal IP是否改变
是否继续计费

  

参考资料:http://blogs.technet.com/b/keithmayer/archive/2013/06/19/windows-azure-virtual-machines-there-s-more-than-1-way-to-shutdown-a-vm.aspx

posted on 2013-08-02 14:02  Lei Zhang的博客  阅读(1531)  评论(1编辑  收藏  举报