Windows Azureで仮想マシンを使用するときにリソースを節約する

画像
Windows Azureで仮想マシンを操作するための2つのシナリオを検討してください。これにより、お金と時間を節約できます。


これらの問題を解決するために、Windows Azure用のPowerShellコマンドレットを使用します。

予備措置


Windows Azureに既にアカウントを持っていることを前提としています。
公式WebサイトからWindows用のPowerShellコマンドレットをダウンロードしてインストールします。
次に、発行およびサブスクリプション情報の設定を含むファイルを取得する必要があります。そのために、Windows Azure PowerShellを起動して実行します。
Get-AzurePublishSettingsFile 

その結果、 https://windows.azure.com/download/publishprofile.aspxページが開き、ファイルが保存されます。
次に、次を行います:
 Import-AzurePublishSettingsFile <mysettings>. publishsettings 

その後、サブスクリプションデータファイルを削除できます。

仮想マシンをエクスポートおよび削除します


仮想マシンの設定をXMLファイルにエクスポートするには、 Export-AzureVMコマンドレットを使用します。
 Export-AzureVM -ServiceName '<CloudService>' -Name '<VmName>' -Path 'c:\VMs\VMstate.xml' 

Remove-AzureVMを削除するには
 Remove-AzureVM -ServiceName '<CloudService>' -Name '<VmName>' 

同時に、Remove-AzureVMはVHDを削除せず、すべてのデータが失われることはありません。
仮想マシンの使用を開始する必要がある場合は、以前にエクスポートしたファイルとImport-AzureVMコマンドレットを使用します。
 Import-AzureVM -Path 'c:\VMs\VMstate.xml' | New-AzureVM -ServiceName '<CloudService>' -Location '<Location>' 

上記の手順の欠点は、複数のマシンをエクスポートおよび削除する必要がある場合、不便であることです。

Cloud Serviceのすべての仮想マシンをエクスポートおよび削除します


 Get-AzureVM -ServiceName '<CloudService>' | foreach { $path = 'c:\VMs\' + $_.Name + '.xml' Export-AzureVM -ServiceName '<CloudService>' -Name $_.Name -Path $path } Remove-AzureDeployment -ServiceName '<CloudService>' -Slot Production –Force 

仮想マシンを既存のクラウドサービスにインポートする


 $vms = @() Get-ChildItem 'c:\VMs\' | foreach { $path = 'c:\VMs\' + $_ $vms += Import-AzureVM -Path $path } New-AzureVM -ServiceName '<CloudService>' -VMs $vms 


Source: https://habr.com/ru/post/J147372/


All Articles