Tuesday, December 27, 2011

Deploying on Windows Azure


In the previous article we have seen how to create a package for deployment. Now in this article we will see how to deploy it in azure.

1)      Open the management portal https://windows.azure.com
2)      Click on the Hosted Services, Storage Accounts & CDN tab, and then click Hosted Services, and click New Hosted Service.

3)      Now select the subscription. Enter the name of the service and url prefix. Then select a region  and do not deploy option. And then click OK. We will create deployment after creating the service.

4)      It will start creating hosted service. Once the hosted service is created. You can add certificate and deployment to the service.
5)      Now select the Certificates in the newly created hosted service and click Add certificate. Now add the certificate that is used to create remote desktop connections while creating the deployment. Select the certificate and enter password and click OK.

6)      Now select the service and click New Staging Deployment.


7)      Now enter name of the deployment. Browse for the package file and configuration file and click OK. By default when you package a solution, visual studio will place these file under bin -> Debug -> app.Publish folder.

8)      It will start deployment. Once the deployment is ready you can browse to the DNS name of the deployment and can see it.

Creating the Service Model for VM role in Windows Azure


Now in this article we will create a service model for the image uploaded in azure.

1)      Start Visual Studio 2010. Create new project. From the Visual C# template, click Cloud. Give a name to the project and click OK.

2)      Now Click OK, without selecting any role.

3)      Now add a new VM role. For this right click the Roles select Add and then select New Virtual Machine Role.


In case if didn’t find the “New Virtual Machine Role”, you have to run the scripts below to add new registry key or just change the following [dword] registry key: 
HKEY_CURRENT_USER\SOFTWARE\Wow6432Node\Microsoft\Windows Azure Tools for Microsoft Visual Studio 2010\1.0\VirtualMachineRoleEnabled​=1
4)      Now in properties of the VMRole, select Virtual Hard Disk tab, and select an account for the VHD. If you are using it for first time then you will not find any account there, and either you have to import or manage it.

5)      Now click on manage, It opens a window and then click New.

6)      Now select a certificate

7)      You can either choose an existing certificate, or can create a new one. To create a new certificate click “Create”. It asks for a friendly name. Give name and click OK.
8)      You can view the certificate. Just select the certificate and click View.

9)      You can install the certificate and create a .pfx for it. Just click on the Install.

10)   Now you have to upload the newly created certificate to the management portal. For this click “Copy the full path”. Now click on the “Window Azure Portal”

11)   On the portal, click on the Add Certificate.

12)   Now select the certificate, by pasting the path of the certificate. And click OK.


13)   Now enter the subscription Id on which certificate is uploaded and click OK.

14)   Now select the account and click Close.

15)   Now it will try to get the vhd’s of the account. Then select the VHD uploaded.

16)   Now configure endpoints to allow external connection. For this click on the Endpoints tab, and then click Add Endpoint. Now define Http as the protocol and port 80 for both public and private ports.

17)   Now configure the remote desktop connection for the role. Right click the VM role solution and click Package…


18)   Now click the enable Remote desktop for all roles.


19)   Now here select an existing certificate or you can create a new one. And enter username and password for remote desktop connection. Also select the expiration date. And then click OK.

20)   Now click on the Package.

21)   It creates the .cspkg and .cscfg file for deployment. And open the location in windows explorer.

Uploading the Disk Image to Windows Azure


In this article we will see how to upload .vhd image to Windows Azure. You cannot upload image directly from the portal, but it can be done through command prompt. To upload image

1)      Open Windows Azure SDK Command Prompt as an administrator from Start -> All Programs -> Windows Azure SDK v1.x
2)      At command prompt execute the following command
 csupload Add-VMImage -Connection "SubscriptionId=; CertificateThumbprint=" -Description "Base image Windows Server 2008 R2" -LiteralPath "" -Name baseimage.vhd -Location
Where
·         is your subscription Id
·         is the thumbprint of the certificate on the management portal.
·         Set the description as Base image Windows Server 2008 R2
·         is the full path of the .vhd file.
·         Set the name of the image as baseimage.vhd. So, that the name of the image on portal will be baseimage.vhd
·         set the location where the hosted service will be deployed. The location can be “East Asia”, “North Central US”, “North Europe”, “South Central US”, “Southeast Asia”, “West Europe”.
3)      In the Windows Azure VHD Verification Tool dialog, click OK to allow the VHD to be mounted.

4)      Now it mounts the .vhd file and verifies it. In this process it generates a compressed file (.preped file) in the same folder as the original image file.


5)      After that it creates a new blob for uploading the image file and starts uploading the compressed image to the azure account. It will take significant amount of time. After completion it shows the details.


6)      Once the image is uploaded successfully it shows the status of the image as Committed.


Installing Windows Azure Integration Components on VM role


In this article we will see how to install integration components on the virtual machine. The integration components must be installed on the machine before base image is uploaded to the Azure. The integration components start each time the OS starts. It handles the integration between the role instance and Azure environment. Windows Azure Integration components support:

·         Windows setup for deployment
When a VM role instance comes online, the generalized image that is used to create the instance must run through a setup specialization phase. This specialization phase is performed by the System Preparation Tool (sysprep), provided by the Windows Azure Integration Components.  To automate the specialization, it creates an answer file named c:\unattend.xml.
·         Interaction with the Windows Azure environment
It installs the Service runtime API’s, so that the VM role can get information about the Azure environment, like instance ID, upgrade domain etc. This information is only available to the code that is running under an Administrator or LocalSystem account in the VM role instance.
·         Local storage resources
You can access the local resources using the Service runtime API’s or at c:\Resources\.
·         Certificate installation
You can install the certificates to the LocalMachine store location. It is not possible to install certificates to the CurrentUser store location or any other store location. Do not install the certificate before uploading, because while generalizing the image, System Preparation Tool (sysprep) will destroy the private key of the certificate.

Now we will see how to install Integration components on VM role.
1)      From the Hyper-V manager, right click the VM role and click Connect, and start it. Now Click on the Media -> DVD Drive -> Insert Disk…

2)      Now open the location for wavmroleic.iso. It will be located at C:\Program Files\Windows Azure SDK\v1.6\iso.

3)      It opens an AutoPlay dialogue. Now click Open folder to view files using Windows Explorer.

4)      Now click double click the WaIntegrationComponents-x64.msi (Windows Installer) file.

5)      Click next on the Setup wizard.

6)      Now at Operating system Configuration wizard, enter Password and click Next.

7)      Now Click Install.

8)      If it asks for installing the device software, click Install.

9)      It will take some time for installation. When the installation completes, click Finish.

10)   Now it will ask you to restart the system. Click Yes to restart the system.

11)   Now launch the System Preparation Tool from the location C:\system32\sysprep\sysprep.exe. Set the System Cleanup Action to “Enter System Out-of-Box Experience (OOBE)”, check the option labeled Generalize, set the Shutdown Options to Shutdown, and then press OK.

12)   Now the image is ready for deployment.

Preparing Base Image for Deployment


Now we had a .vhd image containing default installation of Windows server 2008 R2. Now in this article we will install components required for the deployment to windows azure. Connect to the virtual machine created and starts it.

1)      After login, it shows the desktop of virtual machine. Now from All Programs -> Administrative Tools, launch Server Manager.
2)      Select the role node and click Add Roles.

3)      In the Server Roles step, select the Web Server (IIS), and click Next.


4)      Now on the Web Server (IIS) step click Next.


5)      On the Role Services step click Next.

6)      Now on the Confirmation step, check Web server is included for the installation. And then click Install.

7)      When installation is complete, click Close.

8)      Next, in Server Manager, select the Features node and then click Add Features. We can see that Web Server IIS tools are already in the features list.

9)      In the Features step, expand the .Net framework 3.5.1 Features and tick .Net Framework 3.5.1 and click Next.

10)   On the Confirmation step, Click Install.

11)   After the features are installed, on Results step, click Close.

12)   Now open the Windows Update control panel, and on the Change Settings page, select the option labeled Never check for updates (not recommended) and then click OK.
13)   Now check for available updates and install the updates.

Monday, December 26, 2011

Creating a Base image for Virtual Machine Role on Windows Azure


Creating a Base image for Virtual Machine Role on Windows Azure

In this article we will see how to create a base image for Virtual machine role on windows Azure. I am assuming you have windows server 2008 R2 and hyper V installed on the server.
1)      Open Hyper-V manager and connect to Hyper-V server.


2)      Now select the server, then right- click on it. And select New and click Virtual Machine…


3)      It opens a New Virtual Machine Wizard. On the Specify Name and Location tab, specify the name for virtual machine. If you want to change location of the image, you can also do this by specifying the new location, and click Next.


4)      Now in the Assign Memory step specify the memory allocated to VM. This amount can range from 8MB- 10236 MB. In our demo we will set it to 2048 MB, and click Next.


5)      Next, in the Configure Networking step, select Local Area Connection - Virtual Network and then click Next.


6)      Next, in the Connect Virtual Hard disk step, select the Create a virtual hard disk. Specify the name of the disk. If you want to change the location you can change it here. Set the size of the disk. If you want to choose an existing disk, you have to choose Use an existing virtual hard disk option, and browse to the disk location. If you are using an existing disk, you can skip the OS installation section.
Note - The image file must contain a single partition with the OS installation and must not include a recovery partition.


7)      Now, since we are creating a new disk we need to specify how OS (Windows server 2008 R2 Enterprise Edition) will be installed. Here are different options, either you can install OS later, or can install it from CD/DVD or from a network. Here we are using an .iso image for installing OS. So select the option Install an operating system from a boot CD/DVD-ROM. And select the image file and browse to the location. Now click next.


8)      Click finish to create the virtual machine.


9)      Now in the Hyper-V it shows the newly created virtual machine. If it not showing then refresh it.


10)   Now right click the newly created machine and click Connect… Now click on the start as shown in figure to start the virtual machine.


11)   Now it will start installing the windows server 2008 R2 from the specified location. If it doesn’t start installation then might be installation location is incorrect. If the location is correct it asks for choosing language, currency format. Now click next.

12)   Click Install Now to start installation.


13)   Choose the windows Server 2008 R2 full installation and click Next. And accept the terms and conditions.

14)   Now choose the custom installation.

15)   When it prompts for installation like

By default installation creates a recovery partition automatically. But for VM role we need only single partition. So to configure it Now press SHIFT+F10 to open command prompt. At command prompt enter following commands:
diskpart
select disk 0
create partition primary
exit
diskpart command will launch the diskpart tool. Now select the disk 0 and make this partition as primary. And exit from the diskpart tool.
Now close the command prompt.
16)   Now continue the installation.
17)   Once the installation is complete it reboots and ask for login for the first time.
Now enter the login password and continue.