JavaScript aktivieren, um diese Seite anzuzeigen.

Dieses Skript ist ein Beispiel für die Bereitstellung einer SEPPmail VM über PowerShell.

 

empty

Achtung:

Führen Sie das Skript nur entsprechend angepasst aus.

Vergewissern Sie sich, dass Sie die Folgen und Auswirkungen verstehen.

 

Beschreibung

Das Skript beginnt mit der Herstellung einer Verbindung zu einem Azure-Account mit dem Befehl Connect-AzAccount. Dieser Schritt ist für die Ausführung von Azure-Befehlen erforderlich, die mit Azure Resources interagieren. Anschliessend erstellt es mit New-AzResourceGroup eine neue Azure Resources Group am angegebenen Ort. Azure Resources Groups sind Container, die zusammengehörige Resources für eine Azure-Lösung enthalten. Nach der Erstellung der Resources Group erstellt das Skript einen neuen Azure Storage Account mit dem Namen «seppmailvm» innerhalb der erstellten Resources Group. Der Storage Account  verwendet die «Standard_LRS» SKU, die angibt, dass es die Standard Performance Stufe mit  Locally Redundant Storage verwendet.

 

Es ruft die Schlüssel für das neu erstellte Speicherkonto mit Get-AzStorageAccountKey ab. Die Schlüssel des Speicherkontos werden zur Authentifizierung des Zugriffs auf die Daten im Speicherkonto verwendet.

 

Das Skript richtet einen neuen Container namens «vhdcontainer» innerhalb des Storage Account ein, um VHD-Dateien zu speichern. Dies geschieht mit New-AzStorageContainer. Container im Azure Blob Storage werden verwendet, um eine Reihe von Blobs (Dateien) zu gruppieren und sind analog zu Verzeichnissen in einem Dateisystem.

 

Schliesslich wird mit New-AzStorageContext ein Storage Context erstellt, der im Wesentlichen eine Möglichkeit darstellt, Authentifizierungsinformationen und Storage Account Details für nachfolgende Operationen auf dem Storage Account bereitzustellen.

 

Notwendige Module

Az.Storage

Az.Compute

Az.Resources

Az.Accounts

Az.Network

Az.Security

 

Sie benötigen azcopy auf Ihrer Maschine.

 

Code

 

Connect-AzAccount

$loc = 'Switzerland North'

$rg = New-AzResourceGroup -Name nomoreStore -Location $loc

$sa = New-AzStorageAccount -ResourceGroupName $rg.ResourceGroupName -Name seppmailvm -SkuName Standard_LRS -Location $loc

$saKey = Get-AzStorageAccountKey -StorageAccountName $sa.StorageAccountName -ResourceGroupName $rg.ResourceGroupName

$sastoken = New-AzStorageAccountSASToken -Context $context -Service Blob -ResourceType Container,Object -Permission 'racwdlup' -ExpiryTime (Get-Date).AddDays(7) -Protocol HttpsOnly

$ctName = 'vhdcontainer'

$context = New-AzStorageContext -StorageAccountName $sa.StorageAccountName -StorageAccountKey $saKey[0].Value

$ct = New-AzStorageContainer -Name $ctName -Context $context -Permission Off

$DiskName = 'SEPPmail'

$blobUri = "https://$($sa.StorageAccountName).blob.core.windows.net/$($ct.Name)/$diskName.vhd"

$copyDest = $bloburi + '?' + $sastoken

azcopy copy 'C:\pathtoyourfile\System.vhd' $copyDest

$osType = 'Linux'

$diskSizeGB = 60 # auf die Grösse der eigenen VHD setzen

$diskConfig = New-AzDiskConfig -SkuName 'Standard_LRS' -Location $loc -CreateOption Import -SourceUri $blobUri -OsType $osType -DiskSizeGB $diskSizeGB -StorageAccountId $sa.id

$vmDisk = New-AzDisk -Disk $diskConfig -ResourceGroupName $rg.ResourceGroupName -DiskName $diskName

# Create a VM Network

$subnetConfig = New-AzVirtualNetworkSubnetConfig -Name SMDevSubnet -AddressPrefix 10.50.0.0/24

$vnet = New-AzVirtualNetwork -ResourceGroupName $rg.ResourceGroupName -Location $loc -Name SEPPmailVnet -AddressPrefix 10.50.0.0/16 -Subnet $subnetConfig

$publicIp = New-AzPublicIpAddress -Name SEPPmailPublicIP -ResourceGroupName $rg.ResourceGroupName -Location $loc -AllocationMethod Static

$nic = New-AzNetworkInterface -Name SEPPmailNic -ResourceGroupName $rg.ResourceGroupName -Location $loc -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $publicIp.Id

# Setup VM Config

$vmConfig = New-AzVMConfig -VMName SEPPmailAzure -VMSize Standard_DS2_v2

$vmConfig = Set-AzVMOSDisk -VM $vmConfig -ManagedDiskId $vmdisk.Id -CreateOption Attach -Linux

$vmConfig = Add-AzVMNetworkInterface -VM $vmConfig -Id $nic.Id

# Create VM

$SEPPmailVM = New-AzVM -ResourceGroupName $rg.ResourceGroupName -Location $loc -VM $vmConfig

# Open Port 8443 to the public Interface

$rule = New-AzNetworkSecurityRuleConfig -Name SEPPmailInboundRule -Description "Allow TCP 8443" -Access Allow -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 8443

$nsg = New-AzNetworkSecurityGroup -ResourceGroupName $rg.ResourceGroupName -Location $loc -Name SEPPmailInboundNSG -SecurityRules $rule

$nic.NetworkSecurityGroup = $nsg

$nic | Set-AzNetworkInterface

 

 

  

Tastaturnavigation

F7 für Tastaturnavigation
ALT halten und Buchstaben drücken

Diese Info: ALT+q
Seitentitel: ALT+t
Seiteninhalt: ALT+b
Inhalte: ALT+c
Suche: ALT+s
Ebene höher: ESC