I have summarized here all the steps you need to take in order to deploy an Azure VM.
Step 1: Get your certificates
I assume that you have an active Azure subscription and you have installed visual studio 2010, the azure sdk and tools and activated the VM role. You will need a management certificate for your subscription to deploy services and 1 or more service certificates to communicate with those securely. To generate a x509 certificate for use with the management API:
1. Open the IIS manager, click on your server.
2. Select "Server Certificates" in the main panel.
3. Click "Create Self-Signed Certificate" in the actions panel
4. Give the certificate a friendly name.
5. Close IIS manager and run certmgr.msc
6. Find your certificate in "Trusted Root Certification Authorities"
7. Right-Click on it, select All Tasks / Export
8. Do not export the private key, choose the DER format, give it a name.
9. Navigate to the Windows Azure management portal.
10. Select Hosted Services / Management Certificates / Add a Certificate
11. Browse to the management certificate file and upload it.
Step 2: Prepare the VM
I assume that you are familiar with Hyper-V and how to build a virtual machine on a hyper-v host.
- Create a virtual machine on hyper-v. Note that the maximum size of virtual hard disk you specify will determine what size of Azure VM you will be able to choose. An extra-small machine will mount a vhd up to 15 GB, small one up to 35 and medium or more up to 65 GB. This is just the size of the system VHD. You will still receive local storage, mounted as a separate volume.
- Install Windows Server 2008 R2 on the VHD. It is the only supported o/s as of writing.
- Install the Azure integration components in the VM. They are contained in the wavmroleic.iso file, which is typically located in c:\progam files\windows azure sdk\<version>\iso. You need to mount that file on the VM and then run the automatic installation process. This provisions the device drivers and management services required by the Azure hypervisor and fabric controller. Note that the setup process asks you for a local administrator password and reboots the VM. The password is encrypted and stored in c:\unattend.xml for future unattended deployment.
- Install and configure any application, role or update as you normally would.
- Configure the windows firewall within the VM to open the ports that your application requires. It is recommended that you use fixed local ports.
- Open and administrator command prompt and run c:\windows\system32\sysprep\sysprep.exe
- Select "OOBE", Generalize and Shutdown
This process removes any system-specific data (including the name and SID) from the image, in preparation for re-deployment on Azure. If your application is dependent on those data, you will have to take appropriate measures at startup on Azure (e.g. run a setup script for your application). The VHD is now ready to be uploaded. It is recommended to make a copy of it to keep as a template.
Note that any deployment to Azure starts from this vhd. No status is saved to local disk if the Azure VMs is recycled for any reason.
Step 3: Upload the VM to Azure
For this you will need a command-line utility provided with the Azure SDK.
- Open a windows azure command prompt as administrator.
csupload Add-VMImage -Connection "SubscriptionId=<YOUR-SUBSCRIPTION-ID>; CertificateThumbprint=<YOUR-CERTIFICATE-THUMBPRINT>" -Description "<IMAGE DESCRIPTION>" -LiteralPath "<PATH-TO-VHD-FILE>" -Name <IMAGENAME>.vhd -Location <HOSTED-SERVICE-LOCATION> -SkipVerify
The subscription ID can be retrieved from the Azure portal and the certificate thumbprint refers to the management certificate you created and uploaded before. The thumbprint can be retrieved from the portal as well. The description is an arbitrary string, the literal path is the full absolute path on the local disk where you stored your vhd. The image name is the name of the file once stored in Azure and the location is one of those available in the Azure portal. Note that the location must be specific, e.g. "North Central US". A region is not accepted (e.g. Anywhere US). SkipVerify will save you some time.
This command will create a blob in configuration storage and load your vhd file in it for future use, but not create a service or start a VM for you. In the Azure portal the stored virtual machine templates can be found under "VM Images"
Step 4: Prepare the service model
Azure requires a service definition and a service configuration file before deploying any role. These are .xml files that are packaged and uploaded to the fabric controller for interpretation. You can generate one for the VM using Visual Studio 2010.
1. Open Visual Studio 2010 and create a new Windows Azure project.
2. Do NOT add any role to the project from the project setup wizard.
3. In the solution explorer panel, right click on the project name and select New Virtual Machine Role. Note that a service may be made of several roles, including multiple VMs.
4. In the VHD configuration dialog, specify your Azure account credentials and which of the stored virtual machine templates you’d like to use.
5. In the Configuration panel specify how many instances you’d like and what type. Remember the size constraints on the system VHDs.
6. In Endpoints, specify which ports and protocol must be open for your applications within the virtual machine (they should match those configured before).
7. Note that RDP connections are configured elsewhere.
8. Once the VM role configuration is done, right-click on the project name and select Publish. You have an option to create the service configuration package only, to be uploaded later via the portal, or to actually deploy the project. I am assuming that you have not got a service defined yet. It is advisable to configure RDP connections for debugging purposes at least during staging.
9. Select Enable connections, then specify a service certificate. This will contain a private key used to encrypt your credentials. If you have none, you can create one from this interface. If you do create a new certificate, click View, Details and Copy to File to export it. Make sure to include the private key.
10. Specify a user name and password to connect to this virtual machine. Change the account expiration date as necessary (but set it before the certifcate expires).
11. Select "Create Service Package Only" and save the package file.
Step 5. Create the service in Azure
1. In the Azure Management Portal, select Hosted Services / New Service
2. Populate the form, specifying a name for your service and deployment options. Note that the location you select must be the same specified at upload time for the virtual machine you want to use. Select the configuration package and file that you saved before. Add the certificate that you exported before for RDP.
3. Click OK to deploy. Start your deployed machines.
Step 6: Connect and enjoy.
From the machine where you generated the RDP certificate, connect to your virtual machines and test. Simply select the virtual machine in the Azure portal and click "connect". A RDP file will be generated for you to save and open. Once debugging is finished, it is recommended to disable RDP connections for production.
Powered by Qumana