Azure powershell使用平台镜像创建ARM非托管磁盘虚拟机


Select-AzureRmSubscription -SubscriptionName "xxxxxxxx"  # 选择订阅环境

 

# 网络选项

$myVirtualNetworkResourceGroup = " xxxxxxxx "  # 虚拟网络资源组 

$myVirtualNetworkName = " xxxxxxxx "  # 虚拟网络

$myVirtualNetworkSubnetName = " xxxxxxxx " # 虚拟子网

$myResourceGroupName = " xxxxxxxx "

$myLocation = " xxxxxxxx "

$myAvailabilitySetName = " xxxxxxxx "

$myNetworkInterfaceName = " xxxxxxxx "

 

$myPublicIpAddressName = " xxxxxxxx "

$myDomainName = " xxxxxxxx "

$myLoadBalancerFrontendName = " xxxxxxxx "  # 负载均衡器前端名称

$myLoadBalancerBackendName = " xxxxxxxx "  # 负载均衡器后端名称

$myLoadBalanceName = " xxxxxxxx "

$myStorageAccountName = " xxxxxxxx "

# $myOSDiskUri = "http://" + $myStorageAccountName + ".blob.core.chinacloudapi.cn/vhds/" + "myOSDisk.vhd"

$myVMName = " xxxxxxxx "

$myVMSize = "Standard_D3_V2"

$myUsername = "leo"    ###自定义用户名称

$myPassword = "xxxxxxxx"  ###虚拟机账户密码

 

 

# 创建资源组

$myResourceGroup = New-AzureRmResourceGroup -Name $myResourceGroupName -Location $myLocation

 

# 创建可用性集

$myAvailabilitySet = New-AzureRmAvailabilitySet -Location $myLocation -Name $myAvailabilitySetName -ResourceGroupName $myResourceGroupName

 

# 创建存储账号

$myStorageAccount = New-AzureRMStorageAccount -Location $myLocation -Name $myStorageAccountName -ResourceGroupName $myResourceGroupName -SkuName Standard_LRS

 

# 创建公共IP地址

$myPublicIpAddressName = New-AzureRmPublicIpAddress -ResourceGroupName $myResourceGroupName -AllocationMethod Dynamic -Name $myPublicIpAddressName -Location $myLocation -DomainNameLabel $myDomainName

 

# 创建前端池

$myLoadBalancerFrontend = New-AzureRmLoadBalancerFrontendIpConfig -Name $myLoadBalancerFrontendName -PublicIpAddress $myPublicIpAddressName

 

# 创建后端池

$myLoadBalancerBackend = New-AzureRmLoadBalancerBackendAddressPoolConfig -Name $myLoadBalancerBackendName

 

# 创建负载均衡集

$myLoadBalancer = New-AzureRmLoadBalancer -Location $myLocation -Name $myLoadBalanceName -ResourceGroupName $myResourceGroupName -FrontendIpConfiguration $myLoadBalancerFrontend -BackendAddressPool $myLoadBalancerBackend

 

# 新建网络接口

$myVirtualNetwork = Get-AzureRmVirtualNetwork -ResourceGroupName $myVirtualNetworkResourceGroup -Name $myVirtualNetworkName

$myVirtualNetworkSubnet = Get-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $myVirtualNetwork -Name $myVirtualNetworkSubnetName

$myNetworkInterface = New-AzureRmNetworkInterface -Name $myNetworkInterfaceName -ResourceGroupName  $myResourceGroupName -Location $myLocation -Subnet $myVirtualNetworkSubnet -LoadBalancerBackendAddressPool $myLoadBalancerBackend

 

# 创建登陆凭证

$myCred = New-Object System.Management.Automation.PSCredential($myUsername, (ConvertTo-SecureString $myPassword -AsPlainText -Force))

 

# 系统磁盘路径

$myURL = "http://" + $myStorageAccountName + ".blob.core.chinacloudapi.cn/vhds/" + $myVMName + "myOSDisk.vhd"

 

 

# 虚拟机配置

$vmConfig = New-AzureRmVMConfig -VMName $myVMName -VMSize $myVMSize -AvailabilitySetId $myAvailabilitySet.Id | `

Set-AzureRmVMOperatingSystem -Windows -ComputerName $myVMName -Credential $myCred | `

Set-AzureRmVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2016-Datacenter-zhcn -Version latest | `

Add-AzureRmVMNetworkInterface -Id $myNetworkInterface.Id | `

Set-AzureRmVMOSDisk -CreateOption FromImage -VhdUri $myURL -Windows

 

# 创建虚拟机

$myVM = New-AzureRmVM -ResourceGroupName $myResourceGroupName -Location $myLocation -VM $vmConfig


上一篇:23种设计模式之静态代理模式


下一篇:mysql+mycat搭建稳定高可用集群,负载均衡,主备复制,读写分离