《Windows Azure Platform 系列文章目录

 

 

  本文介绍的是国外的Azure Global。如果是国内由世纪互联运维的Azure China,请参考这篇文档:

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

 

 

  之前给大家介绍很多关于Windows Azure的内容,基本上都是通过Windows Azure Management Portal来创建的。这种创建方式虽然直观简单,但是如果IT管理员需要同时创建1000台Azure服务的话,工作的代价是非常巨大的。

  其实我们可以通过Windows Azure PowerShell,通过命令行的方式来管理Windows Azure。这样在进行诸如批量创建Azure Virtual Machine的操作会变得非常简单。接下来就开始本章内容。

 

  如果你是第一次运行Azure PowerShell,请按照之前的文章,下载Azure PowerShell Settings文件并上传至云端。

  

  了解Azure的帮助命名

  1.我们首先运行命令:help azure,来看看Windows Azure提供了哪些命令行。我只截取了部分内容,如下图:

  Azure PowerShell (5) 使用Azure PowerShell创建简单的Azure虚拟机和Linux虚拟机
    




Windows Azure Platform 系列文章目录
Azure China (8) 使用Azure PowerShell创建虚拟机,并设置固定Virtual IP Address和Private IP

  在上图中我们可以看到,Azure PowerShell提供了非常多的命令。比如我们之前讲解过的Add-AzureVhd等命令。

  2.我们再运行命令:Get-AzureVMImage,这条命令是列出所有的Azure Virtual Machine镜像,其中包含Windows 和 Linux的。我只截取了部分内容,如下图:

  Azure PowerShell (5) 使用Azure PowerShell创建简单的Azure虚拟机和Linux虚拟机
    




Windows Azure Platform 系列文章目录
Azure China (8) 使用Azure PowerShell创建虚拟机,并设置固定Virtual IP Address和Private IP

  

  开始创建Azure虚拟机

  1.指定当前的存储

Set-AzureSubscription -SubscriptionName '<SubscriptionName>' -CurrentStorageAccount '<StorageAccount>'

  比如我想指定订阅为'Windows Azure MSDN - Visual Studio Ultimate',存储账户为'leivms'。

  执行以下命令: 

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

 

  2.如果我想通过Azure PowerShell新建Virtual Machine

  -VM Name为LeiAzureVM001

  -VM Size为ExtraSmall

  -VM Image为Windows Server 2012 Datacenter

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

  -DNS Name为LeiAzure

  -高可用组为AvbSet

  -数据中心选择East Asia

 

  3.先要设置镜像为Windows Server 2012 Datacenter,

$imageList = Get-AzureVMImage `
| where {$_.ImageName -eq "a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-201407.01-en.us-127GB.vhd"}

$image=$imageList[0]

   执行结果如下:

  Azure PowerShell (5) 使用Azure PowerShell创建简单的Azure虚拟机和Linux虚拟机
    




Windows Azure Platform 系列文章目录
Azure China (8) 使用Azure PowerShell创建虚拟机,并设置固定Virtual IP Address和Private IP

  上图的$image命令可以显示我们需要的Windows Server 2012 DataCenter镜像的相关信息

  

  如果我想模糊查询AzureImage的话,可以通过星号(*)通配符,来模糊查询。

  比如笔者只想查询Windows Server 2012 Datacenter的镜像,PowerShell如下:

$imageList = Get-AzureVMImage `
| where {$_.ImageName -like "*Windows-Server-2012-Datacenter*"}

$image=$imageList[0]

 

  4.创建虚拟机

New-AzureVMConfig -Name 'LeiAzureVM001' -InstanceSize 'ExtraSmall' -ImageName $image.ImageName -AvailabilitySetName 'AvbSet' ` | Add-AzureProvisioningConfig -Windows -AdminUsername 'leizhang' -Password 'Pass@word1' ` | New-AzureVM -ServiceName 'LeiAzure' -Location 'East Asia'

  执行结果如下图:

Azure PowerShell (5) 使用Azure PowerShell创建简单的Azure虚拟机和Linux虚拟机
    




Windows Azure Platform 系列文章目录
Azure China (8) 使用Azure PowerShell创建虚拟机,并设置固定Virtual IP Address和Private IP

 

  5.查询执行结果

  我们在PowerShell中看到Create Succeeded,其实创建Azure VM的过程是异步的。这时候我们查看Azure Management Portal,发现VM正在被创建。如下图:

Azure PowerShell (5) 使用Azure PowerShell创建简单的Azure虚拟机和Linux虚拟机
    




Windows Azure Platform 系列文章目录
Azure China (8) 使用Azure PowerShell创建虚拟机,并设置固定Virtual IP Address和Private IP

  我们还可以通过Management Portal看到创建成功的虚拟机

Azure PowerShell (5) 使用Azure PowerShell创建简单的Azure虚拟机和Linux虚拟机
    




Windows Azure Platform 系列文章目录
Azure China (8) 使用Azure PowerShell创建虚拟机,并设置固定Virtual IP Address和Private IPAzure PowerShell (5) 使用Azure PowerShell创建简单的Azure虚拟机和Linux虚拟机
    




Windows Azure Platform 系列文章目录
Azure China (8) 使用Azure PowerShell创建虚拟机,并设置固定Virtual IP Address和Private IP

 

 

 

 

 

  OK,我们已经创建完第一台虚拟机了,如果需要创建第2台虚拟机LeiAzureVM002,加入到之前创建的DNS: LeiAzure.cloudapp.net

  并且需要加入同一个高可用组'AvbSet',这句PowerShell语句按照下面执行:

New-AzureVMConfig -Name 'LeiAzureVM002' -InstanceSize 'ExtraSmall' -ImageName $image.ImageName -AvailabilitySetName 'AvbSet' ` | Add-AzureProvisioningConfig -Windows -AdminUsername 'leizhang' -Password 'Pass@word1' ` | New-AzureVM -ServiceName 'LeiAzure' 

  

 

 

==========================================================

  请注意在上面的文章中,我们创建第一个Azure VM,需要同时创建Azure DNS,所以需要Location参数,如下:

New-AzureVMConfig -Name 'LeiAzureVM001' -InstanceSize 'ExtraSmall' -ImageName $image.ImageName -AvailabilitySetName 'AvbSet' ` | Add-AzureProvisioningConfig -Windows -AdminUsername 'leizhang' -Password 'Pass@word1' ` | New-AzureVM -ServiceName 'LeiAzure' -Location 'East Asia'

  

  我们创建第二个Azure VM,会复用之前创建的Azure DNS,所以不需要Location参数,如下:

New-AzureVMConfig -Name 'LeiAzureVM002' -InstanceSize 'ExtraSmall' -ImageName $image.ImageName -AvailabilitySetName 'AvbSet' ` | Add-AzureProvisioningConfig -Windows -AdminUsername 'leizhang' -Password 'Pass@word1' ` | New-AzureVM -ServiceName 'LeiAzure' 

 

==========================================================

 

 

  执行结果如下:

 Azure PowerShell (5) 使用Azure PowerShell创建简单的Azure虚拟机和Linux虚拟机
    




Windows Azure Platform 系列文章目录
Azure China (8) 使用Azure PowerShell创建虚拟机,并设置固定Virtual IP Address和Private IPAzure PowerShell (5) 使用Azure PowerShell创建简单的Azure虚拟机和Linux虚拟机
    




Windows Azure Platform 系列文章目录
Azure China (8) 使用Azure PowerShell创建虚拟机,并设置固定Virtual IP Address和Private IP

 

 

 

 

  创建简单的Linux虚拟机

  如果我想创建一个简单的Linux虚拟机,OS为CentOS。

  -VM Name为LeiLinuxVM001

  -VM Size为Medium

  -VM Image为CentOS 6.4

  -Windows用户名为adminuser, 密码为Abc@123456

  -DNS Name为LeiLinuxVM001

  -高可用组为AvbSet

  -数据中心选择East Asia

 

 

  1.获得CentOS虚拟机镜像,通过模糊查询获得CentOS镜像

$imageList = Get-AzureVMImage `
| where {$_.ImageName -like "*CentOS*"}

$image=$imageList[0]

 

  2.创建虚拟机命令:

New-AzureVMConfig -Name 'LeiLinuxVM001' -InstanceSize Medium -ImageName $image.ImageName -AvailabilitySetName 'AvbSet' | Add-AzureProvisioningConfig -Linux -LinuxUser 'adminuser' -Password 'Abc@123456' |  New-AzureVM -ServiceName 'LeiLinuxVM001' -Location 'East Asia'

  执行结果

Azure PowerShell (5) 使用Azure PowerShell创建简单的Azure虚拟机和Linux虚拟机
    




Windows Azure Platform 系列文章目录
Azure China (8) 使用Azure PowerShell创建虚拟机,并设置固定Virtual IP Address和Private IP

  观察执行结果:

Azure PowerShell (5) 使用Azure PowerShell创建简单的Azure虚拟机和Linux虚拟机
    




Windows Azure Platform 系列文章目录
Azure China (8) 使用Azure PowerShell创建虚拟机,并设置固定Virtual IP Address和Private IPAzure PowerShell (5) 使用Azure PowerShell创建简单的Azure虚拟机和Linux虚拟机
    




Windows Azure Platform 系列文章目录
Azure China (8) 使用Azure PowerShell创建虚拟机,并设置固定Virtual IP Address和Private IP

 

 

 

  本博-三石Blog(下文简称本博),在本博客文章结尾处右下脚未注明转载、来源、出处的作品(内容)均为本博原创,本站对于原创作品内容对其保留版权, 请勿随意转载,如若真有需要的朋友可以发Mail联系我;转载本博原创作品(内容)也必须遵循“署名-非商业用途-保持一致”的创作共用协议,请务必以文 字链接的形式标明或保留文章原始出处和博客作者(Lei Zhang)的信息,关于本博摄影作品请务必注意保留(www.cnblog.com/threestone)等相关水印版权信息,否则视为侵犯原创版权 行为;本博谢绝商业网站转载。版权所有,禁止一切有违中华人民共和国著作权保护法及相关法律和本博(法律)声明的非法及恶意抄袭。

 

相关文章:

  • 2021-09-16
  • 2021-11-14
  • 2021-11-10
  • 2021-04-16
  • 2021-12-26
  • 2022-02-15
  • 2022-12-23
猜你喜欢
  • 2022-01-17
  • 2021-04-14
  • 2022-01-26
  • 2021-12-13
  • 2021-10-17
  • 2021-08-10
  • 2022-12-23
相关资源
相似解决方案