Virtual Machine Role by r7Be86

VIEWS: 4 PAGES: 96

									Hands-On Lab
Windows Azure Virtual Machine Roles

Lab version:    2.0.0
Last updated:   6/25/2012




                                      Page | 1
CONTENTS

OVERVIEW ................................................................................................................................................... 3

EXERCISE 1: CREATING AND DEPLOYING A VIRTUAL MACHINE ROLE IN WINDOWS AZURE ...... 5
       Task 1 – Building a Base Virtual Machine Image................................................................................... 5
       Task 2 – Preparing the Base Image for Deployment ........................................................................... 16
       Task 3 – Installing the Windows Azure VM Role Integration Components ........................................ 29
       Task 4 – Uploading the Disk Image to Windows Azure....................................................................... 37
       Task 5 – Creating the Service Model ................................................................................................... 41
       Task 6 – Creating the Hosted Service and Deploying the Package ..................................................... 48

EXERCISE 2: TROUBLESHOOTING WITH REMOTE DESKTOP ........................................................... 54
       Task 1 – Connecting to a Role Instance with Remote Desktop .......................................................... 54
       Task 2 – Using Powershell to Access the Windows Azure Runtime Environment .............................. 60

EXERCISE 3: UPDATING AND SERVICING A VIRTUAL MACHINE ROLE ........................................... 63
       Task 1 – Creating a Differencing Disk .................................................................................................. 63
       Task 2 – Updating a Virtual Machine Role OS Image .......................................................................... 73

SUMMARY .................................................................................................................................................. 77

APPENDIX A: CONFIGURING YOUR WINDOWS AZURE MANAGEMENT PORTAL CREDENTIALS IN
VISUAL STUDIO ........................................................................................................................................ 77

APPENDIX B: INSTALLING WINDOWS SERVER 2008 R2 .................................................................... 84




                                                                                                                                                 Page | 2
Overview
The majority of the time Web and Worker roles configured with startup tasks are a better solution than
the VM Role. The VM Role gives users freedom to control the operating system image. With this control
comes the loss of automated consistent OS servicing. The developer is responsible for making sure that
the OS image is up to date through the creation of difference disks. OS servicing increases the cost of
development, testing and maintenance.
What a VM Role Cannot Do
The VM Role shares the same programming model and network limitations of the Web and Worker
roles. One of the key tenets of the Windows Azure programming model is that the hosted service
(application) behaves correctly when any instance of a role fails. This means that programs must be
stateless so that data is not lost when a role fails. Applications such as SharePoint, SQL Server, Small
Business Server, and Terminal Server are stateful applications that are not supported in the VM Role.
The lack of UDP traffic means that a Domain Controller (Active Directory) will not work in a VM Role.
What a VM Role Can Do
The VM Role is a perfect fit for the following scenarios:
       Long running application installations
       Error-prone application installations
       Application installations requiring manual interaction

In these cases, a startup task will not work, thus the only solution is to use a VM Role.
In this hands-on lab, you will explore Virtual Machine roles and you will learn how to create custom OS
images that you deploy to Windows Azure.


Objectives
In this hands-on lab, you will learn how to:

       Prepare custom OS images that you can deploy to Windows Azure
       Connect to your Windows Azure role instances with Remote Desktop for troubleshooting
       Use differencing disks to apply updates to your Virtual Machine roles



Prerequisites
The following is required to complete this hands-on lab:
                                                                                                   Page | 3
       Windows Server 2008 R2 with Hyper-V role enabled

       Hyper-V Manager
       Microsoft .NET Framework 4.0

       Microsoft Visual Studio 2010
       Windows Azure Tools for Microsoft Visual Studio 1.6

       Setup media for Windows Server 2008 R2 Enterprise Edition (Trial software available here)




 Note: This hands-on lab requires a high-speed Internet connection to upload VM image files to your
 Windows Azure subscription.



 Note: Important: Currently, access to VM Role is available through an invite-only beta program. Unless
 you have enrolled in this program, you will not be able to complete this hands-on lab.




Exercises
This hands-on lab includes the following exercises:
    1. Creating and Deploying a Virtual Machine Role in Windows Azure
    2. Troubleshooting with Remote Desktop
    3. Updating and Servicing a Virtual Machine Role


Estimated time to complete this lab: 90 minutes.

 Note: This hands-on lab involves certain procedures, for example, uploading VM image files to
 Windows Azure, that could potentially be time consuming. The estimate reflects the time required to
 complete each step that requires your active involvement and not the overall time required to
 complete every task.



 Note: When you first start Visual Studio, you must select one of the predefined settings collections.
 Every predefined collection is designed to match a particular development style and determines
 window layouts, editor behavior, IntelliSense code snippets, and dialog box options. The procedures in
 this lab describe the actions necessary to accomplish a given task in Visual Studio when using the
 General Development Settings collection. If you choose a different settings collection for your
                                                                                               Page | 4
 development environment, there may be differences in these procedures that you need to take into
 account.




Exercise 1: Creating and Deploying a
Virtual Machine Role in Windows Azure
In this exercise, you prepare the base image that you will deploy to Windows Azure.
In Hyper-V Server, you create a new virtual machine and perform a default installation of Windows
Server 2008 R2. After booting the virtual machine, you log in, install and configure the required OS
features, and then install the Windows Azure VM Role Integration Components. In a more realistic
scenario, at this point, you would typically install additional software.
Once you have installed and configured all the required software, you apply the System Preparation Tool
(sysprep.exe) to generalize the image, shut it down, and then you upload it to Windows Azure.
Next, you create a service model and configure it to use the deployed image, generate a service
package, and then deploy it to your subscription using the Windows Azure Management Portal.


Task 1 – Building a Base Virtual Machine Image
In this task, you create a virtual machine in Hyper-V to build a base image of Windows Server 2008 R2.
    1. Open Hyper-V Manager in the Start menu and connect to your Hyper-V Server.




                                                                                                  Page | 5
   Figure 1
   Hyper-V Manager console


2. In Hyper-V Manager, right-click the server name, point to New, and then select Virtual
   Machine. Click Next at the welcome screen to start the New Virtual Machine Wizard.




                                                                                            Page | 6
   Figure 2
   Creating a new virtual machine to prepare an image


3. In the Specify Name and Location step, set the name to VM Role and then click Next.




                                                                                         Page | 7
   Figure 3
   Choosing the name of the new virtual machine


4. In the Assign Memory step, set the amount of memory to 2048 MB and then click Next.




                                                                                         Page | 8
   Figure 4
   Configuring the amount memory assigned to the virtual machine


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




                                                                                        Page | 9
   Figure 5
   Configuring networking options for the virtual machine



     Note: The network connection will be used by the virtual machine to access Windows Update
     and apply required updates.



6. Now, in the Connect Virtual Disk step, select the option labeled Create a virtual hard disk. Set
   the Name of the disk to baseimage.vhd, change the location to a suitable folder in your Hyper-V
   server, set the disk Size to 30GB, and then click Next to continue.




                                                                                         Page | 10
Figure 6
Creating a new virtual hard disk



 Note: The VHD size must fit the quota allocated for the chosen VM size for you role. In this
 case, setting the size to 30GB allows you to deploy the VM in a “small” role.



If you already have a VHD file with a clean installation of Windows Server 2008 R2, you may use
that instead. To do this, select the option labeled Use an existing virtual hard disk and browse
to the location of the VHD file. Note that the image file must contain a single partition with the
OS installation and must not include a recovery partition.



 Note: If you use an existing image, after you create the virtual machine, you may skip the OS
 installation section of this task and proceed to the next task.




                                                                                         Page | 11
   Figure 7
   Using an existing virtual hard disk


7. In the Installation Options step, choose the option that is the most suitable for the type of
   setup media that you have, and then click Next.




                                                                                            Page | 12
Figure 8
Installing an operating system from the setup media



 Note: To create a base image for the Virtual Machine Role, you require setup media for
 Windows Server 2008 R2 Enterprise Edition. Click here to download trial software.




                                                                                     Page | 13
   Figure 9
   Completing the Virtual Machine Wizard


8. Click Finish to create the virtual machine.
9. In Hyper-V Manager, in the results pane, under Virtual Machines, right-click the name of the
   newly created virtual machine and then select Connect.

     Note: If Hyper-V manager does not list the virtual machine, you may need to right-click the
     server name and select Refresh.



10. In the toolbar of the Virtual Machine Connection window, click the Start icon.




                                                                                          Page | 14
   Figure 10
   Starting the virtual machine in Hyper-V



     Note: Virtual Machine Connection is a tool that you use to connect to a virtual machine so that
     you can install or interact with the guest operating system.



11. Start the virtual machine to launch the Windows Server 2008 R2 installation procedure.

     Note: If the installation does not start automatically, you may have specified an incorrect
     location of the setup media for Windows Server 2008 R2 in the Installation Options page of
     the New Virtual Machine wizard.



12. Install Windows Server 2008 R2 Enterprise edition using default settings. The only special
    requirement for a valid VM Role image is to allocate the entire virtual hard disk file to a single
    partition where you install the operating system. To avoid creating a recovery partition during
    the installation, follow these steps:



                                                                                              Page | 15
               a. Choose the Custom (advanced) installation type to select the partition where you
                  will install Windows.
               b. Press Shift + F10 to open a command prompt during GUI-mode setup.
               c. At the command prompt, enter the following commands:
                   Command Prompt
                   diskpart
                   select disk 0
                   create partition primary
                   exit



               d. Close the command prompt window.
               e. Install Windows in the newly created partition.
        For additional installation information, see Appendix B: Installing Windows Server 2008 R2.



Task 2 – Preparing the Base Image for Deployment
Typically, VM roles are best suited for deploying legacy systems that involve complex installation and
configuration procedures or for those applications whose setup you cannot script; otherwise, a web or
worker role together with start-up tasks typically provide a simpler solution and the benefit of lower
management requirements. For the scope of this lab, because the objective is simply to confirm that you
can deploy and start a VM Role image successfully, you will enable the Web Server role in your virtual
machine. Note, however, that a web role with full-IIS support provides equivalent functionality and that
you would not normally use a VM role for this purpose.
In this task, you prepare the image containing a default installation of Windows Server 2008 R2
Enterprise that you created in the previous task by installing the components required for deployment
to Windows Azure.
    1. If necessary, in Hyper-V Manager, open a new Virtual Machine Connection window, and sign-in
       to the virtual machine that you created previously.
    2. In the guest operating system, if not already open, start Server Manager from All Programs |
       Administrative Tools.
    3. Select the Roles node and then click Add Roles.




                                                                                              Page | 16
   Figure 11
   Adding a new server role


4. In the Server Roles step, select the Web Server (IIS) role in the list and click Next.




                                                                                            Page | 17
   Figure 12
   Installing the Web Server role


5. In the Web Server (IIS) step, click Next.




                                               Page | 18
   Figure 13
   Web Server (IIS) step


6. In the Role Services step, click Next without selecting any additional components.




                                                                                        Page | 19
   Figure 14
   Configuring Web Server role components


7. In the Confimation step, ensure that the Web Server role is included in the list of services and
   then click Install.




                                                                                           Page | 20
   Figure 15
   Confirming the installation selections


8. Wait for the installation to complete and then click Close.




                                                                 Page | 21
   Figure 16
   Successful installation of the Web Server role


9. Next, in Server Manager, select the Features node and then click Add Features.




                                                                                    Page | 22
   Figure 17
   Installing additional features


10. In the Features step, expand .NET Framework 3.5.1 Features, select.NET Framework 3.5.1 and
    then click Next.




                                                                                      Page | 23
   Figure 18
   Installing the .NET Framework prerequisite



     Note: The VM Role Integration Components require .NET Framework 3.5.1. You will install
     these components in the next task.



11. In the Confirmation step, click Install.




                                                                                       Page | 24
   Figure 19
   Confirming the installation of the .NET Framework features


12. In the Results step, click Close.




                                                                Page | 25
   Figure 20
   Successful installation of the .NET Framework feature


13. Open the Windows Update control panel from Start | All Programs | Windows Update.
14. In the Windows Update page, select Change Settings.




                                                                                   Page | 26
   Figure 21
   Changing Windows Update settings


15. In the Change Settings page, select the option labeled Never check for updates (not
    recommended) and then click OK.




                                                                                          Page | 27
   Figure 22
   Disabling Windows Updates in the VM Role image


16. Next, click Check for updates and install all available updates.




                                                                       Page | 28
       Figure 23
       Installing Windows Updates before deploying the VM Image



         Note: If prompted, you may need to reboot and repeat the check for updates in case there are
         additional updates to install.



Task 3 – Installing the Windows Azure VM Role Integration Components
In this task, you install the Windows Azure VM Role Integration Components.
    1. In the Virtual Machine Connection window, in the Media menu, point to DVD Drive and then
       select Insert Disk. In the Open dialog, browse to the location of the ISO file for the VM Role
       Integration Components, wavmroleic.iso, and then click Open.




                                                                                              Page | 29
   Figure 24
   Connecting the VM Role Integration Components installation ISO file to the virtual CD/DVD drive



     Note: If you have not installed the Windows Azure SDK in your Hyper-V server, you will need
     to copy the wavmroleic.iso file from another computer were you installed the SDK to the
     Hyper-V server’s hard disk. You will find this file in the iso folder of the Windows Azure SDK
     installation directory.



2. After you connect the ISO file to the DVD drive of the virtual machine, wait for the AutoPlay
   dialog to appear and then click Open folder to view files using Windows Explorer.




   Figure 25
   Browsing the VM Role Integration Components ISO file



     Note: If the AutoPlay feature is not enabled, open a Windows Explorer window and browse to
     the CD/DVD drive.

                                                                                           Page | 30
3. In the Windows Explorer window, locate the WaIntegrationComponents-x64.msi (Windows
   Installer) file and double-click it to start the installation.




   Figure 26
   Launching the installation of the VM Role Integration Components


4. At the Welcome screen, click Next to proceed.




                                                                                 Page | 31
   Figure 27
   Windows Azure VM Role Integration Components Setup Welcome screen


5. In the Operating System Configuration step, enter an Administrator Password, confirm it, and
   then click Next.




                                                                                       Page | 32
   Figure 28
   Configuring the administrator password


6. Click Install to begin the installation of the Integration Components.




                                                                            Page | 33
   Figure 29
   Beginning the installation of the VM Role Integration Components


7. When prompted to install device software, click Install to proceed.




   Figure 30
   Installing required device drivers


8. Wait for the installation to complete, which should only take a few seconds.


                                                                                  Page | 34
   Figure 31
   Monitoring the progress of the installation


9. Click Finish to exit the setup program.




                                                 Page | 35
   Figure 32
   Successful installation of the VM Role Integration Components


10. Once the installation of the components has finished, you will be prompted to restart the
    system. Click Yes to continue.




   Figure 33
   Restarting the system to complete the installation of the integration components


11. Wait for the system to restart and log in to the guest machine once again.
12. Now, inside the VM, open the Start menu, type %windir%\system32\sysprep\sysprep.exe and
    then press Enter to launch the System Preparation Tool. Set the System Cleanup Action to


                                                                                          Page | 36
        “Enter System Out-of-Box Experience (OOBE)”, check the option labeled Generalize, set the
        Shutdown Options to Shutdown, and then press OK.




       Figure 34
       Launching the System Preparation Tool



         Note: The Sysprep tool (Sysprep.exe) prepares the image by cleaning up various user and
         machine settings and log files, as well as removing any hardware-dependent information.



    13. Wait for the system to completely shutdown. Your image is now ready for deployment.



Task 4 – Uploading the Disk Image to Windows Azure
In this task, you upload the VHD file to the Management Portal.
    1. Open a Windows Azure SDK Command Prompt as an administrator from Start | All Programs |
       Windows Azure SDK v1.x.
    2. At the command prompt, execute the following command line, where:

         <YOUR-SUBSCRIPTION-ID>                 ID of your Windows Azure subscription that you obtain from
                                                the Management Portal

         <YOUR- CERTIFICATE-THUMBPRINT>         Thumbprint of the management certificate that you can
                                                generate in Visual Studio and upload to the Management
                                                Portal (see Appendix A: Configuring your Windows Azure
                                                Management Portal Credentials in Visual Studio)

         <PATH-TO-VHD-FILE>                     Path to the disk image file, baseimage.vhd, that you built in
                                                Hyper-V

                                                                                                     Page | 37
    <HOSTED-SERVICE-LOCATION>                Windows Azure data center location where the hosted service
                                             will be deployed (choose, “East Asia”, “North Central US”,
                                             “North Europe”, “South Central US”, “Southeast Asia”, “West
                                             Europe”)



   Windows Azure Command Prompt
   csupload Add-VMImage -Connection "SubscriptionId=<YOUR-SUBSCRIPTION-ID>;
   CertificateThumbprint=<YOUR-CERTIFICATE-THUMBPRINT>" -Description "Base image
   Windows Server 2008 R2" -LiteralPath "<PATH-TO-VHD-FILE>" -Name baseimage.vhd
   -Location <HOSTED-SERVICE-LOCATION>



     Note: The –Connection parameter contains settings required to access and manage your
     subscription. If you regularly use the csupload tool, you may store this connection string in
     your local disk using the Set-Connection command and then execute commands without
     specifying the connection details each time.



3. Press Enter to start execution.
4. In the Windows Azure VHD Verification Tool dialog, click OK to allow the VHD to be mounted. If
   the AutoPlay dialog appears, close it.




   Figure 35
   Mounting the VHD for verification



     Note: Initially, the tool executes a preparation phase where it mounts the VHD file and verifies
     it. It then processes the file to create a smaller compressed copy. The file it generates has a
     .preped extension and it stores it by default in the same folder as the original image file. To
     change the folder where csupload stores this file, use the –TempLocation parameter and then
     specify the path to the alternate location.


                                                                                              Page | 38
   Figure 36
   Preparation phase of the csupload tool


5. After the preparation phase completes, the tool creates a new blob to hold the image file and
   then begins to upload the compressed image to your Windows Azure account.




   Figure 37
   Uploading phase of the csupload tool




                                                                                         Page | 39
     Note: Base image files are typically large and, depending on the speed of your Internet
     connection, may take a significant amount of time to upload.



6. In the Management Portal, select the Hosted Services, Storage Accounts & CDN tab, and then
   VM Images. Notice that the list includes the baseimage.vhd file that you are currently uploading
   and that its status is shown as Pending.




   Figure 38
   Available VM Images including the image currently being uploaded


7. Wait for the upload to complete, which may take several hours, if your connection is not very
   fast.




                                                                                          Page | 40
       Figure 39
       VM image successfully uploaded to Windows Azure


    8. Examine the status of the VM role image in the Management Portal and verify that it has now
       changed to Committed.




       Figure 40
       Image committed successfully after finishing the upload



Task 5 – Creating the Service Model
                                                                                           Page | 41
After completing the previous task, you now have a VM image deployed to your Windows Azure
account. In this task, you create a service model and configure it to reference this image.
    1. Start Microsoft Visual Studio 2010.
    2. In Visual Studio, create a new Windows Azure Project. You may choose any language, Visual C#
       or Visual Basic, because you will only use Visual Studio to create the service model and generate
       the service package. Set the name of the project to MyVMRole, change the location to the
       Source folder of the lab, ensure that the option labeled Create directory for solution is checked,
       and set the solution name to Begin. Click OK to create the project.




       Figure 41
       Creating a new Windows Azure Project


    3. In the New Windows Azure Project dialog, click OK without adding any roles. You will create a
       Virtual Machine role in the following steps.




                                                                                               Page | 42
   Figure 42
   Creating a project to host the Virtual Machine Role


4. Once the solution is created, right-click the Roles folder inside the MyVMRole project, point to
   Add, and then select New Virtual Machine Role.




   Figure 43
   Adding a new Virtual Machine Role to the project



     Note: Currently, access to VM Role is available through an invite-only beta program. If you
     enroll in this program, you will receive instructions for enabling the required functionality in
     the Windows Azure Tools for Visual Studio; otherwise, you may not see the required menu
     option.
                                                                                              Page | 43
5. In the properties window for the new role, select the Virtual Hard Disk tab. To show the
   window, expand the Roles node in Solution Explorer and then double-click the VMRole1 role.
6. Before you can choose an image to use for your VM role, you need to configure Visual Studio to
   access your Windows Azure account. If you have used Visual Studio previously to deploy service
   packages to Windows Azure, you may already have created the required credentials. For
   instructions on how to do this, see Appendix A: Configuring your Windows Azure Management
   Portal Credentials in Visual Studio.
7. Once you configure the credentials, choose them in the drop down list labeled Select or create
   your Windows Azure account credentials. After you do this, Visual Studio accesses your
   subscription and retrieves a list of available virtual machine images.
8. Expand the drop down list labeled Select VHD and choose the image named baseimage.vhd,
   which contains the installation of Window Server 2008 R2 Enterprise Edition that you uploaded
   earlier.




   Figure 44
   Choosing a VHD for your virtual machine role



     Note: The drop down lists every VHD that you upload to your subscription.




                                                                                         Page | 44
9. Configure an endpoint to allow external connections to the Web server in the VM Role. To do
   this, in the role properties window, switch to the Endpoints tab. Click Add Endpoint to create a
   new entry in the endpoints list. Set the name of the endpoint to HttpIn, select Input in the Type
   column, http as the Protocol and type 80 for both Public Port and Private Port values.




   Figure 45
   Configuring an external endpoint for the virtual machine role



     Note: In this hands-on lab, you enable the Web Server feature in the VM image to provide a
     simple mechanism to determine when the role starts successfully; hence the need to declare
     the input endpoint.



10. Next, configure the Remote Desktop connections for your role. To do this, right-click the
    MyVMRole cloud service project in Solution Explorer and select Package. In the Package
    Windows Azure Application dialog box, check Enable Remote Desktop for all Roles. It will
    prompt the Remote Desktop Configuration dialog.




                                                                                           Page | 45
   Figure 46
   Preparing for deployment


11. Expand the drop down list labeled Create or select a certificate to encrypt the user credentials
    and select Create.
12. In the Create Certificate dialog, enter a name to identify the certificate, for example,
    AzureRemote, and then click OK.




   Figure 47
   Creating a certificate for Remote Desktop connections


13. Now, back in the Remote Desktop Configuration dialog, choose the newly created certificate
    from the drop down list, enter the name of the user that you will use to connect remotely to
    your role–this can be any name of your choice–enter a password and confirm it, and leave the
    account expiration date unchanged.




                                                                                               Page | 46
   Figure 48
   Configuring Remote Desktop settings


14. Before you close the dialog, click View next to the certificate drop down list. In the Certificate
    dialog, switch to the Details tab and click Copy to File. Follow the wizard to export the
    certificate to a file, making sure that you choose the option to export the private key. Save the
    resulting file to a suitable location in your hard disk. You will need to upload this file to the
    Management Portal later, once you create a hosted service for your role.
15. Click OK to close the Remote Desktop Configuration.
16. Finally, create a package to deploy your virtual machine role. To do this, click Package and then
    wait until Visual Studio creates it. Once the package is ready, Visual Studio opens a window
    showing the folder that contains the generated files.




                                                                                             Page | 47
        Figure 49
        Creating a service package in Visual Studio



Task 6 – Creating the Hosted Service and Deploying the Package
In this task, you create a new hosted service for your Virtual Machine role and then deploy the service
package.
    1. Return to the browser window showing the Management Portal.
    2. Create a hosted service for your virtual machine role. To do this, select the Hosted Services,
       Storage Accounts & CDN tab followed by Hosted Services, and then click New Hosted Service
       on the ribbon.




        Figure 50
        Creating a hosted service for your virtual machine




                                                                                                Page | 48
3. In the Create a new Hosted Service dialog, enter a Service Name, for example, MyVMRole, and
   the URL that you wish to assign to the service. Remember that this URL is public, therefore, it
   needs to be unique and can only contain characters that are valid in a URL. The dialog validates
   the name as you type it and warns you if the name you choose has already been taken. Pick the
   region where you want to host the service from the drop down list labeled Choose a region and
   ensure that it is the same region where you uploaded the VM image in the previous task.
   Finally, in the Deploy pane, select the option labeled Do not deploy, and then click OK.




   Figure 51
                                                                                          Page | 49
   Configuring the hosted service


4. Upload the certificate used to encrypt the Remote Desktop password to the newly created
   service. To do this, expand the node for your hosted service to display and select the
   Certificates node and then click Add Certificate on the ribbon.




   Figure 52
   Configuring service certificates




                                                                                      Page | 50
5. In the Upload an X.509 Certificate dialog, click Browse and navigate to the location where you
   stored the certificate for Remote Desktop that you created and exported during the previous
   task, enter the assigned password, confirm it, and then click Create.




   Figure 53
   Uploading the Remote Desktop certificate to the service


6. Once you create the service, select it in the items pane of the Management Portal page, and
   then click New Production Deployment on the ribbon.




   Figure 54
   Creating a new deployment for the service




                                                                                         Page | 51
7. In the Create a new Deployment dialog, click Browse Locally next to the Package Location text
   box and then navigate to the location where Visual Studio generated the service package during
   the previous task. You should have a Windows Explorer window already open showing the
   correct location. Choose the service package file with a .cspkg extension and click Open. Repeat
   the same procedure to choose the Configuration File with a .cscfg extension in the same
   location. Finally, enter a label to identify your deployment, and click OK.




   Figure 55
   Deploying a service package for the Virtual Machine role


8. Once you start the deployment, you can monitor its progress in the Management Portal’s UI.
   Observe the various states that the deployment undergoes as the role starts up and initializes.




   Figure 56
   Viewing the status of the hosted service

                                                                                          Page | 52
9. Wait until the status of the deployment is shown as Ready.




   Figure 57
   Hosted service successful start


10. To verify that the role started successfully, open the home page of your VM role in your
    browser. You can find its URL in the Properties window of your deployment, which corresponds
    to the web server (port 80) endpoint that you defined while creating the service model.




   Figure 58
   Accessing the input endpoint of the VM role


11. Verify that you can access the default page in IIS, as shown in the image below.




                                                                                       Page | 53
        Figure 59
        Accessing the web server running in the VM role




Exercise 2: Troubleshooting with Remote
Desktop
Remote Desktop allows you to connect to a role instance for troubleshooting purposes. In this exercise,
you connect to an instance of your VM role and use Powershell to access the service runtime
environment.


Task 1 – Connecting to a Role Instance with Remote Desktop

                                                                                              Page | 54
In this task, you connect to your running role instances using Remote Desktop.
    1. Once the role’s status changes to Ready, expand the deployment in the center pane to show its
       instances and select the line labeled VM Instance–there should only be a single instance for the
       current deployment– and then click Connect on the ribbon.




        Figure 60
        Connecting to a role instance with Remote Desktop


    2. Download the Remote Desktop connection file from the Management Portal. Depending on
       your browser security configuration, the browser may block the download and prompt you for
       confirmation. If this happens, you may need to allow the download to proceed and then repeat
       the previous step once the page refreshes. In the File Download dialog, click Open.




                                                                                              Page | 55
   Figure 61
   Downloading the Remote Desktop connection file


3. If prompted by a security warning from your browser, click Allow to proceed.




   Figure 62
   Allowing the remote desktop connection to proceed


4. Click Connect in the Remote Desktop Connection dialog.


                                                                                  Page | 56
   Figure 63
   Downloading the Remote Desktop connection file


5. In the Windows Security dialog, enter the credentials that you specified earlier when you
   configured the Remote Desktop connection for the role, and then click OK.




   Figure 64
   Entering your Remote Desktop credentials



                                                                                         Page | 57
6. Wait until the connection is established.




   Figure 65
   Waiting for the connection to be established


7. Remote Desktop prompts you with a dialog warning that the identity of the remote computer
   cannot be verified. Click Yes to proceed.




   Figure 66
   Verifying the identity of the remote computer


8. Once authenticated, the connection is quickly established and a window showing the desktop
   for the chosen role instance should open.

                                                                                      Page | 58
Figure 67
Remote Desktop connected to the virtual machine role instance



 Note: If you have trouble connecting with your credentials, you can configure the remote
 desktop credentials from the Management Portal. To do this, select the role that you want to
 configure, and then click User Access in the Remote Access section of the ribbon.




Figure 68
Configuring Remote Desktop for a role


                                                                                     Page | 59
        Figure 69
        Configuring the Remote Desktop credentials using the Management Portal


    9. At this point, you may use the remote desktop connection to explore your virtual machine
       running in the cloud.



Task 2 – Using Powershell to Access the Windows Azure Runtime Environment
In this task, you use a Powershell snap-in to stop network traffic to the current role instance.
    1. In the Remote Desktop session, open a Powershell console window as an administrator.
    2. At the command prompt, type the following command to add a Powershell snap-in to the
       current session. This snap-in is installed with the integration components and provides access to
       the Windows Azure runtime environment.
        Powershell
        Add-PSSnapin Microsoft.WindowsAzure.ServiceRuntime



    3. To view all the commands available in the snap-in, enter the following command:
        Powershell
        Get-Command -module Microsoft.WindowsAzure.ServiceRuntime



                                                                                                   Page | 60
   Figure 70
   Viewing available commands in the service runtime Powershell snap-in



     Note: You may view additional information for any of these commands by executing:
       Get-Help <command-name>
     where <command-name> is the name of the command.



4. To remove the current role instance from the load balancer rotation and prevent traffic from
   being forwarded to this instance, type the following command:
   Powershell
   Set-RoleInstanceStatus -Busy




                                                                                         Page | 61
   Figure 71
   Stopping network traffic to the current role instance


5. Examine the status of the deployment in the Management Portal and notice that it now shows
   the status of the hosted service as Busy.




   Figure 72
   Role instance status showing that it has been removed from the load balancer rotation


6. Close the Powershell window and then examine the status of the role instance at the
   Management Portal. Notice that after a brief delay, the status returns to Ready and the role is
   ready once again to receive external traffic.

     Note: The status of the role instance can also be restored by executing the following
     command:
       Set-RoleInstanceStatus -Ready




                                                                                             Page | 62
Exercise 3: Updating and Servicing a
Virtual Machine Role
Servicing and adding new features to a Virtual Machine role are possible without requiring you to
upload a complete replacement image to your Windows Azure subscription. Instead, you can deliver
updates through differencing disks whose parent is the original base image and which contain all the
necessary changes. After preparing a differencing disk, you upload it and associate it with its base image.
Once the disk is stored in your subscription, you can update the service configuration to replace the
image used by the hosted service with the differencing disk.


Task 1 – Creating a Differencing Disk
In this task, you update the image running in the Virtual Machine role. For the scope of this lab, the
objective is simply to replace the default image in the IIS Welcome page located inside the
C:\inetpub\wwwroot folder.
    1. Open Hyper-V Manager in the Start menu and connect to your Hyper-V Server.
    2. Right click your server name, select New and then Hard Disk.
    3. In the New Virtual Hard Disk Wizard, click Next to skip past the welcome screen.
    4. In the Choose Disk Type step, select the Differencing disk option and click Next to proceed.




                                                                                                 Page | 63
   Figure 73
   Creating a differencing disk


5. Now, in the Specify Name and Location step, set the Name of the disk to diffimage.vhd, change
   the location to a suitable folder in your Hyper-V server, and then click Next.




                                                                                       Page | 64
   Figure 74
   Choosing the name and location of the disk


6. In the Configure Disk step, browse to the base image that you previously deployed and choose
   it as the parent of the new differencing virtual hard disk. Click Next to proceed.




                                                                                       Page | 65
   Figure 75
   Configuring the parent image for the differencing disk


7. Click Finish to create the VHD file in your computer.




                                                            Page | 66
   Figure 76
   Confirming the creation of the differencing virtual hard disk


   Once you create the differencing disk, you now configure the virtual machine to use it.
8. In the Hyper-V console, ensure the virtual machine that you set up at the start of the lab is
   turned off and then right-click its node to select Settings.
9. In the Hardware section on the left pane, select the Hard Drive node under IDE Controller 0.
   Next, click Browse to select the differencing disk that you just created and then OK to apply the
   changes.




                                                                                             Page | 67
   Figure 77
   Replacing the VHD disk file in the virtual machine with the differencing disk


10. Start the guest operating system. To do this, right-click the virtual machine in the Hyper-V
    Manager and select Connect to open a Virtual Machine Connection. Then, click the Start
    button in the window’s toolbar.
11. Wait for the virtual machine to boot and then log in using the credentials that you assigned
    previously, when you initialized the base image and installed the tools.




                                                                                            Page | 68
   Figure 78
   Logging in to the virtual machine image


12. Now, in the console window for the VM, from Start | All Programs | Accessories, open Paint as
    an administrator.
13. In Paint, open the image file shown as part of the welcome page for the default Internet
    Information Server (IIS) installation, which you will find at C:\inetpub\wwwroot\Welcome.png.
14. Use the Text tool to overlay a caption on this image file. Use any sample phrase, for example,
    draw the text:”Windows Azure VM Role”.




                                                                                           Page | 69
   Figure 79
   Using the text tool to modify the default welcome page in IIS




   Figure 80
   Overlaying a caption on the image


15. Save the file.
16. Once again, you need to prepare the differencing disk for deployment. To do this, inside the
    VM, open the Start menu, type %windir%\system32\sysprep\sysprep.exe and then press Enter
    to launch the System Preparation Tool. Set the System Cleanup Action to “Enter System Out-of-
    Box Experience (OOBE)”, check Generalize, set the Shutdown Options to Shutdown, and then
    press OK.
                                                                                       Page | 70
17. Wait for the system to completely shutdown. Your differencing image is now ready for
    deployment to Windows Azure. To deploy this image, you will follow a similar procedure to the
    one that you used earlier, when you uploaded the base image.
18. Open a Windows Azure SDK Command Prompt as an administrator from Start | All Programs |
    Windows Azure SDK v1.x.
19. At the command prompt, execute the following command line, where:

    <YOUR-SUBSCRIPTION-ID>                 ID of your Windows Azure subscription that you obtain from
                                           the Management Portal

    <YOUR- CERTIFICATE-THUMBPRINT>         Thumbprint of the management certificate that you can
                                           generate in Visual Studio and upload to the Management
                                           Portal (see Appendix A: Configuring your Windows Azure
                                           Management Portal Credentials in Visual Studio)

    <PATH-TO-VHD-FILE>                     Path to the differencing disk image file, diffimage.vhd, that you
                                           built in Hyper-V

    <HOSTED-SERVICE-LOCATION>              Windows Azure data center location where the hosted service
                                           will be deployed (choose from “East Asia”, “North Central US”,
                                           “North Europe”, “South Central US”, “Southeast Asia”, “West
                                           Europe”)
                                           Choose the same region used for the base image



   Windows Azure Command Prompt
   csupload Add-VMImage -Connection "SubscriptionId=<YOUR-SUBSCRIPTION-ID>;
   CertificateThumbprint=<YOUR-CERTIFICATE-THUMBPRINT>" -Description
   "Differencing image with updated logo" -LiteralPath "<PATH-TO-VHD-FILE>" -Name
   diffimage.vhd -Location <HOSTED-SERVICE-LOCATION>



20. Press Enter to start execution.




                                                                                                 Page | 71
   Figure 81
   Uploading the differencing disk image


21. In the Windows Azure VHD Verification Tool dialog, click OK to allow the VHD to be mounted. If
    the AutoPlay dialog appears, close it.
22. Wait until the uploading process completes. Because the differencing disk is considerably
    smaller, this should be significantly faster than uploading the base image.
23. Now, at the command prompt, enter the following command to associate the differencing disk
    with its base image.

    <YOUR-SUBSCRIPTION-ID>                  ID of your Windows Azure subscription that you obtain from
                                            the Management Portal

    <YOUR- CERTIFICATE-THUMBPRINT>          Thumbprint of the management certificate that you can
                                            generate in Visual Studio and upload to the Management
                                            Portal (see Appendix A: Configuring your Windows Azure
                                            Management Portal Credentials in Visual Studio)



   Windows Azure Command Prompt
   csupload Set-Parent -Connection "SubscriptionId=<YOUR-SUBSCRIPTION-ID>;
   CertificateThumbprint=<YOUR-CERTIFICATE-THUMBPRINT>" -Child diffimage.vhd -
   Parent baseimage.vhd



24. Now, go back to the Management Portal, select the Hosted Services, Storage Accounts, & CDN
    tab, and then VM Images. Notice how the portal now shows the differencing disk as a child of
    the base image.
                                                                                        Page | 72
        Figure 82
        Base image and its differencing disk



Task 2 – Updating a Virtual Machine Role OS Image
In this task, you update the service model to use the differencing disk and deploy it to Windows Azure to
allow the Virtual Machine role to boot from the replacement disk image. Changing the image that a role
boots from is easily achieved by updating the OsImage element in the configuration file. You can do this
at the Management Portal, without stopping the service.
    1. Browse the Windows Azure Management Portal at https://windows.azure.com/ and, if
       necessary, sign in with your Live ID.
    2. At the Management Portal, select the Hosted Services, Storage Accounts & CDN tab and then
       Hosted Services.
    3. Locate the hosted service that you created earlier and select the deployment that contains the
       base image VHD. Then, click Configure in the Deployments group of the ribbon.




                                                                                               Page | 73
   Figure 83
   Updating the configuration of your service deployment


4. In the Configure Deployment dialog, select the option labeled Edit current configuration.
   Notice that the contents of the Settings text box contain the settings that you defined when you
   created the service model and built the package in Visual Studio.
5. In the Settings text box, locate the OsImage element and change the value of its href attribute
   from baseimage.vhd to diffimage.vhd.




                                                                                          Page | 74
   Figure 84
   Updating the image used by the virtual machine role


6. Click OK to save the changes and update the role configuration. Notice that the Management
   Portal changes the status of the deployment to Updating while the changes are applied.




   Figure 85
   Waiting for the changes to the OS image to take effect



                                                                                      Page | 75
7. Wait until the host starts again and changes its status back to Ready.

     Note: This process may take several minutes. Remember that the role now starts from an
     updated image that was generalized with the System Preparation Tool (Sysprep.exe) and that
     it needs to boot and prepare the OS for its first time use.



8. Now, navigate to the URL of the service to open the Welcome page in the IIS instance running in
   the VM role. Notice that it now shows the updated image, which now shows an additional
   caption, confirming that the role has booted from the differencing disk.




   Figure 86
   Welcome page in Internet Information Server (IIS) showing the updated image




                                                                                        Page | 76
Summary
In this hands-on lab, you explored the basic features of Windows Azure Virtual Machine roles and saw
how to create custom OS images and prepare them for deployment to the cloud.




Appendix A: Configuring your Windows
Azure Management Portal Credentials in
Visual Studio
Follow these steps to create the credentials that you can use to access your Windows Azure subscription
from Visual Studio.
    1. To add a new set of credentials, open an existing Windows Azure project or create a new one.
    2. Open a Windows Azure Project Management Authentication dialog. To do this, use one of the
       following two procedures:
           a. In Solution Explorer, right-click the Windows Azure project and select Publish.
           b. In the Publish Windows Azure Application dialog, expand the Subscription drop down
              list and select Manage.




                                                                                                Page | 77
   Figure 87
   Configuring Windows Azure account credentials - Option A


c. It will prompt a dialog to manage your Windows Azure authentication settings. Click
   New to define you authentication settings.




   Figure 88
   Adding Authentication Settings
                                                                                 Page | 78
   Alternatively,
       d. Add a Virtual Machine Role to the Windows Azure project. To do this, right-click the
          Roles folder inside the project, point to Add, and then select New Virtual Machine Role.
       e. In Solution Explorer, double-click the VM Role to open its properties window.
       f.   In the Virtual Hard Disk tab, expand the drop down list labeled Select or create your
            Windows Azure account credentials, and then choose Add.




            Figure 89
            Configuring Windows Azure account credentials - Option B


3. In the Windows Azure Project Management Authentication dialog, expand the drop down list
   below the label Create or select an existing certificate for authentication and choose Create.
4. In the Create Certificate dialog, set the name to AzureMgmt and click OK.
5. Choose the newly created certificate from the drop down list.




                                                                                           Page | 79
   Figure 90
   Choosing a certificate for authentication


6. Now, click the link labeled Copy the full path to store the path to the certificate file in the
   clipboard.




   Figure 91
                                                                                               Page | 80
   Copying the path of the generated certificate public key file to the clipboard



     Note: Visual Studio stores the public key file for the certificate it generates in a temporary
     folder inside your local data directory.



7. Click OK to dismiss the confirmation message box and then save the path in the clipboard to a
   safe location. You will need this value shortly, when you upload the certificate to the portal.




   Figure 92
   Confirmation that the file path was copied to the clipboard successfully


8. Now, in the Windows Azure Project Management Authentication dialog, click the link labeled
   Windows Azure Portal to open a browser window and navigate to the Management Portal.




                                                                                              Page | 81
9. At the Management Portal, if you have not already done so, sign in using your Windows Live ID.
10. Select the Hosted Services, Storage Accounts & CDN option, click Management Certificates,
    and then click Add Certificate on the ribbon.




   Figure 93
   Adding a new management certificate to your subscription


11. In the Add New Management Certificate dialog, click Browse, change the file name to the path
    for the public key (.cer) file generated by Visual Studio that you copied earlier to your clipboard,
    and then click Open. Click Ok to upload the certificate to the Management Portal.




   Figure 94
   Uploading a management certificate




                                                                                              Page | 82
12. In the Certificates List, click the subscription where you created the certificate and make a
    record of the subscription ID, located in the Properties pane. You will need it in the next step.




   Figure 95
   Retrieving your subscription ID from the Management Portal


13. Go back to the Windows Azure Project Management Authentication dialog in Visual Studio and
    paste the value retrieved from the Management Portal into the subscription ID textbox.




   Figure 96
   Entering your Windows Azure subscription ID


                                                                                             Page | 83
    14. Provide a name to identify your credentials, for example, MyWindowsAzureAccount, and then
        click OK.




Appendix B: Installing Windows Server
2008 R2
The following procedure briefly describes the steps required to install Windows Server 2008 R2 using
default settings.
    1. Start the virtual machine to launch the Windows Server 2008 R2 installation procedure.

         Note: If the installation does not start automatically, you may have specified an incorrect
         location of the setup media for Windows Server 2008 R2 in the Installation Options page of
         the New Virtual Machine wizard.




       Figure 97
                                                                                              Page | 84
   Installation loading files from the setup media


2. Choose the language to install, the time and currency format, and the default keyboard layout
   and then choose Next.




   Figure 98
   Configuring the language and regional settings


3. Click Install now to begin the installation.




                                                                                        Page | 85
   Figure 99
   Starting the installation process


4. Choose the Windows Server 2008 R2 Enterprise server edition and then click Next.




                                                                                      Page | 86
   Figure 100
   Choosing the server edition to install


5. Read and accept the license terms. Then, click Next to proceed.




                                                                     Page | 87
   Figure 101
   Accepting the licensing agreement


6. Choose the Custom (advanced) installation type.




                                                     Page | 88
   Figure 102
   Choosing an installation type


7. When prompted to choose an installation location, press Shift+F10 to open a command prompt.




                                                                                     Page | 89
   Figure 103
   You can open a command prompt by pressing Shift + F10 now


8. At the command prompt, type diskpart and press Enter.




   Figure 104

                                                               Page | 90
   Launching the diskpart tool


9. Now, type list disk and press Enter to enumerate available disks—there should be a single disk
   only.




   Figure 105
   Enumerating available disks


10. Next, type select disk 0 and press Enter.




   Figure 106
   Selecting the current disk


                                                                                         Page | 91
11. Type create partition primary and then press Enter to create a partition that spans the entire
    disk.




   Figure 107
   Creating a primary partition


12. Finally, type exit and then press Enter.




   Figure 108
   Exiting the diskpart tool


13. Close the command prompt window.


                                                                                           Page | 92
14. Back in the GUI, click Refresh to update the list of available partitions, choose the newly created
    partition and then click Next.




   Figure 109
   Choosing a partition to install the operating system


15. Wait for the installation to complete.




                                                                                             Page | 93
   Figure 110
   Windows installation showing the current progress


16. Once the installation completes and the system boots successfully, in the virtual machine, click
    OK to set up the administrator’s password and log in for the first time.




                                                                                            Page | 94
   Figure 111
   Changing the administrator’s password


17. Enter a password for the administrator, confirm it, and then press Enter or click the blue button.




                                                                                            Page | 95
Figure 112
Logging in for the first time




                                Page | 96

								
To top