Benutzer:MovGP0/Azure/Virtual Machines
Zur Navigation springen
Zur Suche springen
MovGP0 | Über mich | Hilfen | Artikel | Weblinks | Literatur | Zitate | Notizen | Programmierung | MSCert | Physik |
|
Virtual Machines
[Bearbeiten | Quelltext bearbeiten]# Select subscription
Get-AzureSubscription | Select SubscriptionName
$subscription = "[CaseSensitiveSubscriptionName]";
Select-AzureSubscription $subscription;
# Get Region
Get-AzureLocation ` # get available Azure regions
| Where { $_.AvailableServices -contains PersistentVMRole } ` # that support Virtual Machines
| Where { $_.AvailableServices -contains HighMemory }; # supports the more performant A5..A9 VMs
$location = "[RegionName]";
Get-AzureStorageAccount | Select StorageAccountName, Location;
Test-AzureName -Storage -Name "[StorageAccountName]" # tests if the storage account name in available or reserved
New-AzureStorageAccount -StorageAccountName "[StorageAccountName]" -Location $location # create a new one
Set-AzureSubscription -SubsriptionName $subscription -CurrentStorageAccountName "[StorageAccountName]"
# Selecting Virtual Machine Image
Get-AzureVMImage # lists information about avilable VM images
Get-AzureVMImage | Select ImageFamily
$imageFamily = "[ImageFamilyName]";
$imageName = Get-AzureVMImage | Where ImageFamily -eq $imageFamily | Sort PublishedDate -Descending | Select -ExpandProperty ImageName -First 1;
Get-AzureRoleSize | Where SupportedByVirtualMachines -eq $True | Select RoleSizeLabel; # get available VM Host sizes
$vmSize = "[InstanceSize]";
# VMs are created an an Cloud service.
# VMs in the same cloud service can communicate directly with another and support local name resolution, and share the same load balancer (if set up)
Test-AzureName -Service -Name "[CloudServiceName]"; # test if the service name is already in use; 'cloudservicename.cloudapp.net'
$ServiceName = "[CloudServiceName]";
$vmName = "";
New-AzureQuickVM -Windows -ServiceName $ServiceName -Name $vmName -ImageName $imageName -Location $location -InstanceSize $vmSize -AdminUserName $adminUserName -Password $adminUserPassword
# Limitations
# - data disk configuration at creation time
# - no domain-join at creation time
# - no booting from disk
# CREATE AZURE VM CONFIGURATION
$vmConfig = New-AzureVMConfig -Name $vmName -InstanceSize $vmSize -ImageName $imageName `
| Add-AzureProvisioningConfig -Windows -AdminUserName $adminUserName -Password $adminUserPassword ` # changing properties of the config
# LUN = Locical Unit Number (locical number of the drive)
# instead of -CreateNew you can use -Import to use an existing named one, or -ImportFrom to give the URL of an VHD in an azure storage account.
| Add-AzureDataDisk -CreateNew -DiskSizeInGB 512 -DiskLabel "os" -LUN 0
# only Round-Robin load balancing is (currently) supported; probe is used to determine if service is active
| Add-AzureEndpoint -Name "HTTP" -Protocol 'tcp' -PublicPort 80 -LocalPort 80 -LBSetName "[LoadBalancerSetName]" -DefaultProbe
| Add-AzureEndpoint -Name "HTTPS" -Protocol 'tcp' -PublicPort 443 -LocalPort 443 -LBSetName "[LoadBalancerSetName]" -ProbeProtocol TCP -ProbePort 443
# cannot probe on UDP; only TCP and HTTP are supported
# can call a specific url
| Add-AzureEndpoint -Name "UDP" -Protocol 'udp' -PublicPort 5001 -LocalPort 5001 -LBSetName "[LoadBalancerSetName]" -ProbeProtocol HTTP -ProbePort 80 -ProbePath '/ping' -ProbeTimeIntervallInSeconds [5..15] -ProbeTimeoutInSeconds [11..31]
| Set-AzureEndpoint -Name "RemoteDesktop" -PublicPort 5099
| Remove-AzureEndpoint -Name "RemoteDesktop"
New-AzureVM -ServiceName $ServiceName -VMs $vmConfig;
Get-AzureVM -ServiceName $ServiceName
| Get-AzureEndpoint # get network configuration for VM
| Get-AzureDataDisk # get drive configuration
| Get-AzureOSDisk # get OS disk configutation only
| Update-AzureVM # publish (changes of) the VM to the Azure cloud
# getting a remote connection file (should not work since the endpoint got removed)
Get-AzureRemoteDesktopFile -ServiceName $ServiceName -Name $vmName -Launch
Get-AzureVM -ServiceName $serviceName -Name $vmName
| Stop-AzureVM -Force # only disk space will be billed, but no computing time
| Stop-AzureVM -StayProvisioned # shud down the VM, but billing continues
| Start-AzureVM
| Restart-AzureVM
# when network endpoint is behind a load balancer
Set-AzureLoadBalancedEndpoint -ServiceName $serviceName -ProbeProtocol HTTP -LBSetName "[LoadBalancerSetName]" -ProbePath '/ping'
# IP ADDRESS AND ACL CONFIGURATION
# Get VM Image
$imageName = Get-AzureVMImage `
| where ImageFamily -eq "Windows Server 2012 R2 Datacenter" `
| sort PublishedDate -Descending `
| select -ExpandProperty ImageName -First 1
# Reserve public IP Address
# Warning: when addressing a host with a public IP, the load balancer will not be hit
$reservedIP = New-AzureReservedIP -ReservedIPName "[NameOfIPRange]" -Location "West US"
Get-AzureReservedIP
# Configure ACL
$acl = New-AzureAclConfig `
| Set-AzureACLConfig -AddRule -Order 100 -Action Permit -RemoteSubnet '175.1.0.0/24' -Description "Management Network"
| Set-AzureACLConfig -AddRule -Order 200 -Action Permit -RemoteSubnet '137.117.17.7/32' -Description "Admin PC"
# Create a VM configuration
$vm1 = New-AzureVMConfig -Name $vmName -InstanceSize "Small" -ImageName $imageName `
| Add-AzureProvisioningConfig -Windows -AdminUsername $adminUser -Password $password
| Set-AzureEndpoint -Name "Remote Desktop" -ACL $acl `
# Create the VM
New-AzureVM -ServiceName $serviceName -Location $location -VMs $vm1 -ReservedIPName $reservedIP
# Update the public IP of an VM
Get-AzureVM -ServiceName $serviceName -Name $vmName
| Set-AzurePublicIP -PublicIPName "oldPublicIPName"
| Remove-AzurePublicIP -PublicIPName "newPublicIPName"
| Update-AzureVM
|}