Azure目前有两种工作模式:ASM和ARM。
在国内的Azure,我们都是使用ASM的模式。但这种模式有很多限制,比如每个VM必须有一个公网地址,部署不能批量部署等等。ARM对Azure的整体架构做了巨大的修改。在ASM中的很多限制都去掉了。下图是两种模式主要的差别:
今年中Azure在中国将全面支持ARM的模式。目前需要注意的是,在China Azure上需要采用PowerShell的版本是1.2.2。最新版的1.3.2和1.4.0有一些服务不能创建。具体的下载地址是:
本文将介绍一些简单的基于ARM模式的Azure资源的创建和管理方式。
1.创建Resource Group
首先要添加ARM的账户:
Add-AzureRmAccount -EnvironmentName AzureChinaCloud
选择这个账号:
Select-AzureSubscription -SubscriptionName "xxxx" -Account [email protected]
创建Resouce Group
New-AzureRmResourceGroup -Name hwarm01 -Location "China East" ResourceGroupName : hwarm01 Location : chinaeast ProvisioningState : Succeeded Tags : ResourceId : /subscriptions/42e8b20d-29ec-40a5-b020-b2229f3dda56/resourceGroups/hwarm01
2. 创建网络相关内容
2.1 创建VNet
$subnet1 = New-AzureRmVirtualNetworkSubnetConfig -Name Subnet-1 -AddressPrefix 172.17.1.0/24 $subnet2 = New-AzureRmVirtualNetworkSubnetConfig -Name Subnet-2 -AddressPrefix 172.17.2.0/24 $subnet3 = New-AzureRmVirtualNetworkSubnetConfig -Name Subnet-3 -AddressPrefix 172.17.3.0/24 $vnet = New-AzureRmVirtualNetwork -Name hwarmvnet01 -ResourceGroupName hwarm01 -Location "China East" -AddressPrefix 172.17.0.0/16 -Subnet $subnet1,$subnet2,$subnet3
2.2 创建保留IP
$piplb = New-AzureRmPublicIpAddress -ResourceGroupName hwarm01 -Name hwpiplb01 -Location "China East" -AllocationMethod Static
2.3创建HASet
$has = New-AzureRmAvailabilitySet -ResourceGroupName hwarm01 -Name hwarmhas01 -Location "China East"
2.4 创建负载均衡
$fendip = New-AzureRmLoadBalancerFrontendIpConfig -Name fendip -PublicIpAddressId $piplb.Id $bendip = New-AzureRmLoadBalancerBackendAddressPoolConfig -Name bendip $inboundNATRule1 = New-AzureRmLoadBalancerInboundNatRuleConfig -name ssh1 -FrontendIpConfigurationId $fendip.Id -Protocol Tcp -FrontendPort 22122 -BackendPort 22 $inboundNATRule2 = New-AzureRmLoadBalancerInboundNatRuleConfig -name ssh2 -FrontendIpConfigurationId $fendip.Id -Protocol Tcp -FrontendPort 22222 -BackendPort 22 $lbprobe = New-AzureRmLoadBalancerProbeConfig -Name hwlbprobe -Protocol Tcp -Port 80 -IntervalInSeconds 15 -ProbeCount 2 $lbrule = New-AzureRmLoadBalancerRuleConfig -Name hwlbrule -FrontendIpConfigurationId $fendip.Id -BackendAddressPoolId $bendip.Id -ProbeId $lbprobe.Id -Protocol Tcp -FrontendPort 80 -BackendPort 80 -LoadDistribution SourceIP $lb = New-AzureRmLoadBalancer -Name hwlb -ResourceGroupName hwarm01 -Location "China East" -FrontendIpConfiguration $fendip -BackendAddressPool $bendip -Probe $lbprobe -InboundNatRule $inboundNATRule1 -LoadBalancingRule $lbrule
2.5 创建网卡
$nic1 = New-AzureRmNetworkInterface -Name nic1 -ResourceGroupName hwarm01 -Location "China East" -PrivateIpAddress 172.17.1.4 -SubnetId $vnet.Subnets[0].Id -LoadBalancerBackendAddressPoolId $lb.BackendAddressPools[0].id -LoadBalancerInboundNatRuleId $lb.InboundNatRules[0].Id $nic2 = New-AzureRmNetworkInterface -Name nic2 -ResourceGroupName hwarm01 -Location "China East" -PrivateIpAddress 172.17.1.5 -SubnetId $vnet.Subnets[0].Id -LoadBalancerBackendAddressPoolId $lb.BackendAddressPools[0].id -LoadBalancerInboundNatRuleId $lb.InboundNatRules[1].Id
3. 创建存储相关的
3.1. 创建存储账号
New-AzureRmStorageAccount -ResourceGroupName hwarm01 -Name hwarmsa01 -Type Standard_LRS -Location "China East"
3.2创建container
$sa = Get-AzureRmStorageAccount -ResourceGroupName hwarm01 -Name hwarmsa01 $sa | New-AzureStorageContainer -Permission Off vhds
3.3 定义OSDisk, DataDisk的URI
$OSdiskName = "hwarmvm01-osdisk.vhd" $OSDiskURI = $sa.PrimaryEndpoints.Blob.AbsoluteUri + "vhds/" + $OSdiskName $dataDiskName = "hwarmvm01-datadisk.vhd" $dataDiskURI = $sa.PrimaryEndpoints.Blob.AbsoluteUri + "vhds/" + $dataDiskName
4. 定义VM的属性
4.1 定义VM基本属性
$vmname = "hwarmvm01" $vmsize = "Standard_A1" $cred = Get-Credential -UserName hengwei -Message hwarmvm01 $vm = New-AzureRmVMConfig -VMName $vmname -VMSize $vmsize -AvailabilitySetId $has.Id
4.2定义VMImage的信息
Get-AzureRmVMImage -Location "China East" -PublisherName OpenLogic -Offer CentOS -Skus 6.5 Version FilterExpression Skus Offer PublisherName Location Id ------- ---------------- ---- ----- ------------- -------- -- 6.5.20150904 6.5 CentOS OpenLogic chinaeast /Subscriptions/42e8b20d-29ec-40a5-b020-b22... 6.5.20160329 6.5 CentOS OpenLogic chinaeast /Subscriptions/42e8b20d-29ec-40a5-b020-b22... $vmimage = Get-AzureRmVMImage -Location "China East" -PublisherName OpenLogic -Offer CentOS -Skus 6.5 -Version 6.5.20160329
4.3定义VM操作系统信息
$vm = Set-AzureRmVMOperatingSystem -Linux -VM $vm -Credential $cred -ComputerName $vmname
4.4定义VM磁盘信息
$vm = Set-AzureRmVMSourceImage -VM $vm -PublisherName $vmimage.PublisherName -Offer $vmimage.Offer -Skus $vmimage.Skus -Version $vmimage.Version $vm = Set-AzureRmVMOSDisk -VM $vm -Name $OSdiskName -VhdUri $OSDiskURI -CreateOption fromImage $vm = add-AzureRmVMDataDisk -VM $vm -Name $dataDiskName -VhdUri $dataDiskURI -CreateOption empty -DiskSizeInGB 100
4.5定义VM网卡信息
$vm = Add-AzureRmVMNetworkInterface -VM $vm -id $nic1.Id
5. 创建虚拟机
New-AzureRmVM -ResourceGroupName hwarm01 -Location "China East" -VM $vm
时间: 2024-10-12 06:08:56