简体   繁体   English

如何将VM上传到Azure

[英]How do I upload a VM to Azure

I see a lot of confusion about how to connect to Azure and upload a VM. 我对如何连接到Azure和上载VM感到很多困惑。 It involves creating a management certificate with makecert and uploading with csupload , and there are a lot of flags to get wrong. 它涉及到使用makecert创建管理证书并使用csupload上传,并且有很多错误标志。 So I thought I'd ask the question and answer it to save someone some trouble. 所以我想我会问这个问题并回答,以免给别人带来麻烦。

(cut from initial question and pasted as an answer) (从初始问题中切出并粘贴为答案)


Basic Principles 基本原则

  1. You must have Visual Studio and the Azure SDK installed. 您必须安装Visual Studio和Azure SDK。

  2. To connect to Azure, you create a security certificate on your local machine that identifies you. 若要连接到Azure,您需要在本地计算机上创建一个安全证书来标识您的身份。 Then you go to Azure and import the certificate. 然后,您转到Azure并导入证书。 Now your local machine and Azure are able to talk to each other securely. 现在,您的本地计算机和Azure可以安全地相互通信。 For this reason you can't start the work on one machine and finish it on another. 因此,您无法在一台机器上开始工作而在另一台机器上完成工作。 Work on one machine. 在一台机器上工作。

  3. You must have the certificate in your Current User certificate store and also exported to your hard drive. 您必须在“当前用户”证书存储区中拥有证书, 并且还必须将其导出到硬盘驱动器。 You need a copy on the hard drive to upload to Azure, and you need it in the certificate store because when you connect to Azure that's where it will look for it. 您需要硬盘驱动器上有一个副本才能上载到Azure,并且需要在证书存储区中使用它,因为当您连接到Azure时,它将在其中寻找它。 You can create it on your hard drive and import it, or you can create it in the certificate store and export it. 您可以在硬盘驱动器上创建它并导入它,也可以在证书存储中创建它并导出它。 The following instructions show you how to do the latter. 以下说明向您展示了如何进行后者。

Create the Certificate 创建证书

  1. Open a Visual Studio command prompt as an Administrator. 以管理员身份打开Visual Studio命令提示符。 (right click on the menu item, and click "run as administrator". (右键单击菜单项,然后单击“以管理员身份运行”。

  2. Copy/paste the following: 复制/粘贴以下内容:

    makecert -sky exchange -r -n "CN=MyCertificateName" -pe -a sha256 -len 2048 -ss My "MyCertificateName.cer" makecert -sky exchange -r -n“ CN = MyCertificateName” -pe -a sha256 -len 2048 -ss My“ MyCertificateName.cer”

    This will create the certificate and install it in your Current User certificate store. 这将创建证书并将其安装在“当前用户”证书存储中。 It will not create a copy on your hard drive. 它不会在硬盘驱动器上创建副本。 It's the "My" key word that causes the certificate to be stored in the certificate store for your current account. 是“我的”关键字使证书存储在当前帐户的证书存储中。

  3. Open the certificate manager by typing certmgr in the start menu command. 通过在开始菜单命令中键入certmgr打开证书管理器。 You should see Certificates - Current User at the top. 您应该在顶部看到“证书-当前用户”。 Open Personal/Certificates and you should see the certificate you just created. 打开“个人/证书”,您应该看到刚刚创建的证书。

  4. Right click the certificate and click All Tasks, Export. 右键单击证书,然后单击“所有任务”,“导出”。 Click Next. 点击下一步。 Select No do not export the private key. 选择否不导出私钥。 Click Next. 点击下一步。 Select the DER encoded format. 选择DER编码格式。 Click Next. 点击下一步。 Save the certificate on your hard drive somewhere with the same name as you used to create it (doesn't have to be the same but it avoids confusion). 将证书以与创建证书时相同的名称保存在硬盘驱动器上(不必相同,但可以避免混淆)。

Import the Certificate into Azure 将证书导入到Azure

  1. Log into Azure. 登录到Azure。

  2. Click Settings then Management Certificates then Upload. 单击设置,然后单击管理证书,然后单击上载。

  3. Browse to the management certificate that you just exported and saved, and upload it. 浏览到您刚刚导出并保存的管理证书,然后上载它。

  4. Copy the Subscription Identifier and Thumbprint from the uploaded certificate and paste them into a text file. 从上载的证书中复制“订阅标识符”和“指纹”,然后将其粘贴到文本文件中。 Save the file on your local hard drive. 将文件保存在本地硬盘上。 You need these numbers handy for the next step. 下一步需要这些数字。

  5. If you want to be safe, delete the certificate that you exported to your hard drive. 为了安全起见,请删除导出到硬盘驱动器的证书。 You don't need it there any more. 您不再需要它了。 Azure will look for the certificate in your certificate store when it authorizes you, not on your hard drive. 授权后,Azure会在证书存储中查找证书,而不是在硬盘驱动器上。

At this point you are able to make a secure connection between your computer/account and Azure. 此时,您可以在计算机/帐户和Azure之间建立安全连接。 You will now use this secure connection to upload your Virtual Machine. 现在,您将使用此安全连接来上传虚拟机。

Upload your Virtual Machine 上传您的虚拟机

  1. First establish a secure connection to Azure. 首先建立与Azure的安全连接。 Open an Azure command prompt as an Administrator and enter the following: 以管理员身份打开Azure命令提示符,然后输入以下内容:

    csupload Set-Connection "SubscriptionId=YourSubscriptionIdGoesHere;CertificateThumbprint=YourCertificateThumbPrintGoesHere;ServiceManagementEndpoint= https://management.core.windows.net " csupload设置连接“ SubscriptionId = YourSubscriptionIdGoesHere; CertificateThumbprint = YourCertificateThumbPrintGoesHere; ServiceManagementEndpoint = https://management.core.windows.net

  2. Finally it's time to upload the file. 最后是时候上传文件了。 Open the Azure portal, select your storage account and copy the blobs service endpoint URL. 打开Azure门户,选择您的存储帐户,然后复制blobs服务终结点URL。 Enter the following at the same Azure command prompt as above: 在与上述相同的Azure命令提示符下输入以下内容:

    csupload Add-PersistentVMImage -Destination "YourBlobServiceEndPointUrlGoesHere/vhds/YourVhdNameGoesHere" -Label YourVhdNameGoesHere-LiteralPath "ThePathToYourVhdOnTheLocalComputerGoesHere" -OS Windows csupload Add-PersistentVMImage-目标“ YourBlobServiceEndPointUrlGoesHere / vhds / YourVhdNameGoesHere”-标签YourVhdNameGoesHere-LiteralPath“ ThePathToYourVhdOnTheLocalComputerGoesHere” -OS Windows

The VHD should begin to upload. VHD应该开始上传。

Here's an easier way, you will need: 这是一种更简单的方法,您将需要:
Windows Azure PowerShell Windows Azure PowerShell

  1. Open "Windows Azure PowerShell" 打开“ Windows Azure PowerShell”
    -OR- open a PS prompt and run: -或-打开PS提示符并运行:
    Set-ExecutionPolicy RemoteSigned Set-ExecutionPolicy RemoteSigned
    Import-Module "C:\\Program Files (x86)\\Microsoft SDKs\\Windows Azure\\PowerShell\\Azure\\Azure.psd1" 导入模块“ C:\\ Program Files(x86)\\ Microsoft SDKs \\ Windows Azure \\ PowerShell \\ Azure \\ Azure.psd1”

2. Get-AzurePublishSettingsFile 2. Get-AzurePublishSettingsFile
(Will prompt you to save a .publishsettings file required in the next step) (将提示您保存下一步所需的.publishsettings文件)

3. Import-AzurePublishSettingsFile "C:\\Temp\\Windows Azure...credentials.publishsettings" 3. Import-AzurePublishSettingsFile“ C:\\ Temp \\ Windows Azure ... credentials.publishsettings”

4. add-azurevhd -destination "https://.blob.core.windows.net/vhds/File.vhd" -localfilepath "C:\\Users\\Public\\Documents\\Hyper-V\\Virtual hard disks\\File.vhd" 4. add-azurevhd-目的地“ https://.blob.core.windows.net/vhds/File.vhd” -localfilepath“ C:\\ Users \\ Public \\ Documents \\ Hyper-V \\ Virtual disks \\ File.vhd ”

For more info see: 有关更多信息,请参见:
Get Started with Windows Azure Cmdlets Windows Azure Cmdlet入门

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM