《Windows Azure Platform 系列文章目录

  update 2017-12-21

  我把Azure PowerShell升级到5.0.0版本,发现语句有些细微区别:

#这里Linux用户名和密码
$adminName = "用户名"
$adminPassword = "密码" #设置DNS Name和机器名
$serviceName = "DNSName"
$vmName ="VMName" #VM所在的数据中心
$location = "China East" #VM大小
$vmSize ="A7" #VNet,子网,和内网IP
$vNetName = 'My-VNet'
$subnetName='Subnet-1'
$privateIP='10.0.0.1' #外挂Disk大小
$disksize=500
$disklabel= $vmName + "DataDisk"
$lun=0
$hcaching="None" $imageList = Get-AzureVMImage ` | where {$_.ImageName -like "*CentOS-65*"} $image=$imageList[0] #创建VM
$vm1 = New-AzureVMConfig -Name $vmName -InstanceSize $vmSize -ImageName $image.ImageName #这里不能指定TimeZone
$vm1 | Add-AzureProvisioningConfig -Linux -LinuxUser $adminName -Password $adminPassword $vm1 | Set-AzureSubnet -SubnetNames $subnetName $vm1 | Set-AzureStaticVNetIP -IPAddress $privateIP $vm1 | Add-AzureDataDisk -CreateNew -DiskSizeInGB $disksize -DiskLabel $disklabel -LUN $lun -HostCaching $hcaching New-AzureVM -ServiceName $serviceName -VM $vm1 -VNetName $vNetName -Location 'China East'

  本文介绍的是由世纪互联运维的Windows Azure China。

  相比于Global Azure (http://www.windowsazure.com),国内由世纪互联运维的Windows Azure在PowerShell仅有细微的差别。

  Azure Global的IP Rang信息,可以参考:http://www.microsoft.com/en-us/download/details.aspx?id=41653

  国内由世纪互联运维的Azure China的IP Rang信息,可以参考:http://www.microsoft.com/en-us/download/details.aspx?id=42064 

  如果读者用的是百度查询IP地址,经常会发现Azure上海的IP地址经常会显示来自北京,这是由于百度的IP库比较老,请读者注意

  在介绍本文之前,建议读者熟悉Azure PowerShell的基本命令,请参考笔者之前的文章:

      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)

  接下来,笔者会比较快速的介绍相关PowerShell命令:

  如果你是第一次运行Azure PowerShell。我们要在本地创建证书文件。以便本地计算机和Azure建立可靠的安全连接。

  1.以管理员身份,运行Azure PowerShell,下载publishsettings文件

Get-AzurePublishSettingsFile -Environment AzureChinaCloud

  如果不想运行Azure PoweShell的话,

  国外的Azure Global,请在浏览器中输入地址http://go.microsoft.com/fwlink/?LinkID=301775

  在登陆框中,输入你的用户名和密码

  国内世纪互联运维的Azure China,请在浏览器中输入地址:http://go.microsoft.com/fwlink/?LinkID=301776

  在登陆框中,输入你的OrgID和密码

  2.将publishsettings下载到本地磁盘,然后执行上传publishsettings命令

Import-AzurePublishSettingsFile <PathToFile>

  上面步骤1、2执行成功后,下次运行Azure PowerShell将不必再次运行上面的运行。接下来可以运行我们的命令了。

  3.创建新的存储账号(步骤略),选择当前的订阅,并设置存储账号

Set-AzureSubscription -SubscriptionName '[SubscriptionName]' -CurrentStorageAccount '[StorageName]'

  4.在上海数据中心(China East),获得固定的Public IPV4地址

$NginxReservedIP = New-AzureReservedIP -ReservedIPName 'NginxPublicIP' -Label 'NginxPublicIP' -Location 'China East'

  查看这个IP地址

Get-AzureReservedIP -ReservedIPName 'NginxPublicIP'

  

  5.创建虚拟网络Virtual Network,命名为MyVNet (位置选择China East)。注意Virtual Network不能属于地缘组里。

  -  MyVNet IP Rang为10.0.0.0-10.0.0.255,

  -  同时创建2个Subnet:Nginx-subnet和Nodejs-subnet

  

  6.通过模糊查询,查询到CentOS 7.0镜像

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

  7.创建3台虚拟机:

  -  DNS为MyNginx,并且绑定Public IP (NginxPublicIP)

  -  机器名分别为Nginx01,Nginx02和Nginx03

  -  三台机器加入虚拟机网络MyVNet。子网为Nginx-subnet (10.0.0.0-10.0.0.127),

     设置内网IP分别为10.0.0.4,10.0.0.5和10.0.0.6

  -  虚拟机大小为Large

  -  管理员用户名为:adminuser。 密码为:MyVM@6789

  -  高可用性集名称为:NginxAvbSet

  -  并设置该虚拟机的时区为UTC+8时区(北京时间)

  创建第1台虚拟机(Nginx01,内网IP是10.0.0.4)的命令如下:

New-AzureVMConfig -Name 'Nginx01' -InstanceSize 'Large' -ImageName $image.ImageName  -AvailabilitySetName 'NginxAvbSet' ` | Add-AzureProvisioningConfig -Linux -LinuxUser 'adminuser' -Password 'MyVM@6789' -TimeZone 'China Standard Time' | Set-AzureSubnet -SubnetNames 'Nginx-subnet' | Set-AzureStaticVNetIP -IPAddress '10.0.0.4' | New-AzureVM -ServiceName 'MyNginx' -VNetName 'MyVNet' –ReservedIPName 'NginxPublicIP' -Location 'China East'

 

  创建第2台虚拟机(Nginx02,内网IP是10.0.0.5)的命令如下:

New-AzureVMConfig -Name 'Nginx02' -InstanceSize 'Large' -ImageName $image.ImageName  -AvailabilitySetName 'NginxAvbSet' ` | Add-AzureProvisioningConfig -Linux -LinuxUser 'adminuser' -Password 'MyVM@6789' -TimeZone 'China Standard Time' | Set-AzureSubnet -SubnetNames 'Nginx-subnet' | Set-AzureStaticVNetIP -IPAddress '10.0.0.5' | New-AzureVM -ServiceName 'MyNginx' -VNetName 'MyVNet' 

  

  创建第3台虚拟机(Nginx03,内网IP是10.0.0.6)的命令如下:

New-AzureVMConfig -Name 'Nginx03' -InstanceSize 'Large' -ImageName $image.ImageName  -AvailabilitySetName 'NginxAvbSet' ` | Add-AzureProvisioningConfig -Linux -LinuxUser 'adminuser' -Password 'MyVM@6789' -TimeZone 'China Standard Time' | Set-AzureSubnet -SubnetNames 'Nginx-subnet' | Set-AzureStaticVNetIP -IPAddress '10.0.0.6' | New-AzureVM -ServiceName 'MyNginx' -VNetName 'MyVNet' 

==========================================分隔符=============================================

  上面的内容,我们介绍的是创建Linux虚拟机,接下来笔者介绍一下如何使用PowerShell,创建Windows虚拟机。

  我们直接从上面的步骤6开始,通过模糊查询,查询到Windows Server 2012虚拟机

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

  或者通过精确查询,查询到Windows Server 2008 R2 SP中文版OS

$imageList = Get-AzureVMImage `
| where {$_.ImageName -eq "55bc2b193643443bb879a78bda516fc8__Win2K8R2SP1-Datacenter-201503.01-zh.cn-127GB.vhd"} $image=$imageList[]

  55bc2b193643443bb879a78bda516fc8__Windows-Server-2012-R2-201504.01-zh.cn-127GB.vhd

  7.创建2台虚拟机。

  -  DNS为LeiVM,并且绑定Public IP (NginxPublicIP)

  -  机器名分别为LeiVM01,LeiVM02

  -  三台机器加入虚拟机网络MyVNet。子网为subnet-1 (10.0.0.0-10.0.0.127),

     设置内网IP分别为10.0.0.4,10.0.0.5

  -  虚拟机大小为Large

  -  管理员用户名为:adminuser。 密码为:MyVM@6789

  -  高可用性集名称为:LeiAvbSet

  创建LeiVM01的PowerShell如下:

New-AzureVMConfig -Name 'LeiVM' -InstanceSize Large -ImageName $image.ImageName -AvailabilitySetName 'LeiAvbSet' ` | Add-AzureProvisioningConfig -Windows -AdminUsername 'adminuser' -Password 'MyVM@6789' | Set-AzureSubnet -SubnetNames 'Subnet-1' | Set-AzureStaticVNetIP -IPAddress '10.0.0.4' | New-AzureVM -ServiceName 'LeiVM' -VNetName 'MyVNet' –ReservedIPName 'NginxPublicIP' -Location 'China East'

  创建LeiVM02的PowerShell如下:

New-AzureVMConfig -Name 'LeiVM02' -InstanceSize Large -ImageName $image.ImageName -AvailabilitySetName 'LeiAvbSet' ` | Add-AzureProvisioningConfig -Windows -AdminUsername 'adminuser' -Password 'MyVM@6789' | Set-AzureSubnet -SubnetNames 'Subnet-1' | Set-AzureStaticVNetIP -IPAddress '10.0.0.4' | New-AzureVM -ServiceName 'LeiVM' -VNetName 'MyVNet'

==========================================分隔符=============================================

创建一台SQL Server 2012 SP1的 Azure Virtual Machine

并设置该虚拟机的时区为UTC+8时区(北京时间)

同时关闭该虚拟机的自动更新功能

$imageList = Get-AzureVMImage | where {$_.ImageName -eq "74bb2f0b8dcc47fbb2914b60ed940c35__SQL-Server-2012SP1-Enterprise-SQL11-SP1-CU3-11.0.3350.0-Win2012-ENU"}

$image=$imageList[]

New-AzureVMConfig -Name 'LeiSQLVM01' -InstanceSize 'Medium' -ImageName $image.ImageName  -AvailabilitySetName 'LeiSQLAvbSet' ` | Add-AzureProvisioningConfig -Windows -AdminUsername 'azureadmin' -Password 'MyVM@6789' -TimeZone 'China Standard Time' -DisableAutomaticUpdates | Set-AzureSubnet -SubnetNames 'SQL-Subnet' | Set-AzureStaticVNetIP -IPAddress '10.0.0.132' | New-AzureVM -ServiceName 'LeiSQLCS' -VNetName 'LeiSQLAlwaysOnVNet' -Location 'China East'

Update 2015-12-9,今天发现一个Azure PowerShell,可以导出所有的Azure VM Template Name,方便以后使用:

$images = Get-AzureVMImage
$count = $images.Count
for($i=0;$i -lt $count;$i++){ $i.ToString() + " : " + $images[$i].ImageName; }

部分截图信息如下:

Azure China (8) 使用Azure PowerShell创建虚拟机,并设置固定Virtual IP Address和Private IP的更多相关文章

  1. Azure China (5) 管理Azure China Powershell

    <Windows Azure Platform 系列文章目录> 本文介绍的是国内由世纪互联运维的Azure China Cloud Update 2015-09-01 发现一个新的命令,在 ...

  2. azure 1元试用,如何创建虚拟机等

    付了1元后,直接进 https://manage.windowsazure.cn 创建虚拟机即可.

  3. Azure China (4) 管理Azure China Storage Account

    <Windows Azure Platform 系列文章目录> Update 2015-05-10 强烈建议使用AzCopy工具,AzCopy命令行工具,是经过优化的.高性能Azure S ...

  4. Azure China (10) 使用Azure China SAS Token

    <Windows Azure Platform 系列文章目录> 本文介绍的是国内由世纪互联运维的Azure China 注意:本文介绍的是Azure China Storage Priva ...

  5. Azure China (9) 在Azure China配置CDN服务

    <Windows Azure Platform 系列文章目录> 本文介绍的是国内由世纪互联运维的Azure China Update 2015-11-20:Azure China CDN服 ...

  6. Azure China (11) 使用Azure China Storage Public Blob

    <Windows Azure Platform 系列文章目录> 本文介绍的是国内由世纪互联运维的Azure China 注意:本文介绍的是Azure China Storage Publi ...

  7. Linux虚拟机Centos 设置固定的静态IP

    经过两天的研究(研究到深夜1点),百度了很多文章与加了几个linux的群,终于得到一种方式是可以正常设置静态IP且正常的ssh连接的方式. 第一种方式:NAT模式 参考文章 -- 虚拟机中的CentO ...

  8. [转载]CentOS 7虚拟机下设置固定IP详解

    在 复制 他人作品之前,是因为我再此“跌倒”过一次,虽然原主说是永久地址,但是地址失效 不可避免.所以就原封不动的copy了过来,我自己也是按照他的一步一步配置的,我成功了,相信你们也会成功. 如果不 ...

  9. CentOS 7虚拟机下设置固定IP详解

    说明 1.笔记本主机IP为设置自动获取,不管什么情况下,不受虚拟机影响,只要连接外网就可以正常上网: 2.只要笔记本主机可以正常访问外网,启动虚拟机中的CentOS 7系统就可以正常访问外网,无需再进 ...

随机推荐

  1. css3之景深

    perspective属性:(目前仅仅支持-webkit-perspective属性,视点距离) 值:number perspective-origin属性:(视点位置) 值:number% numb ...

  2. HTML 学习记录

    <h1>This is a heading </h1> 标题 h后面的数字是字体大小 <p>This is a paragraph.</p>段落 < ...

  3. Get&Post简单说明

    一.GET请求和POST请求简单说明 创建GET请求 1 // 1.设置请求路径 2 NSString *urlStr=[NSString stringWithFormat:@"http:/ ...

  4. .net 发展史

    2002年年初 -Visual Studio 2002 & .Net Framework 1.0 2003年春天 -Visual Studio 2003 & .Net Framewor ...

  5. XAMARIN +VS2015 ANDROID 开发判断gps 是否打开。

    在获取位置的时候首先要判断gps是否打开,如果没有打开就要提示打开,当然最友好的就是直接调转到打开界面. LocationManager alm = (LocationManager)this.Get ...

  6. Struts2注解使用说明

    Struts2注解 1 Struts2注解的作用 使用注解可以用来替换struts.xml配置文件!!! 2 导包 必须导入struts2-convention-plugin-2.3.15.jar包, ...

  7. 开园第一篇 - 论移动开发环境 IOS与Android的差异

    首先,在真正写技术之前做个自我简介.本人08年开始学c语言 一年后,转vc++.开始接触MFC MFC做了两年.转眼11年了我考上了一个不知名的大专.搞C++发现没有市场了因为当时酷狗腾讯的软件已经日 ...

  8. Oracle中rownum和rowid的理解(转)

    本文转自地址http://www.linuxidc.com/Linux/2012-04/58300.htm rownum,rowid都叫伪列. 但是,rownum是逻辑上的编号,且其值总是从1开始,每 ...

  9. Java日志系统及框架分析

    最近在考虑将容器(Tomcat)内的应用日志统一成slf4j + logback,主要目的有: 快速定位应用日志输出路径,方便日志的采集: 能动态调整日志的级别,方便线上问题定位: 方便在容器层面做扩 ...

  10. SSM+DUBBO/ZK异常

    1.Could not find resource(mybatis本身不支持通配符,是spring提供的ant匹配法) 2.ClassNotFoundException: org.I0Itec.zkc ...