In this 2 series post, we'll be creating a web farm of virtual machines running IIS on Windows Server 2012. In the first part, we will customize a Windows Server 2012 machine and set its roles to be running IIS, then capture it to be able to later create duplicates out of it with ease.
Create the Virtual Machine
We'll create a machine using the defaults by going to New --> Compute --> Virtual Machine --> Quick Create
Wait for the machine to be provisioned, should take about 10 minutes, then connect to it using Remote Desktop, logging in with the username and password you specified in the previous step.
Configuring the server
You will now be logged in onto the remote Windows Server 2012 machine we just created. The Server Manager should launch automatically, if not, launch it from the icon in the bottom left of the Task Bar.
Since we want to configure this as a Web server, we'll go ahead and configure the IIS role. Click on Add roles and features, then advance through the wizard till you reach the page where you select the roles, select Web Server (IIS).
Also go through the wizard to start and finish the installation.
Once the installation is over, we just need to open up port 80 in the firewall the Windows Azure load balancer. This is done on the Windows Azure portal's Endpoints tab.
Add the endpoint
Once the endpoint configuration is done, you'll be able to access the server from the web by opening its DNS name in the browser.
Congratulations, you've just configured an IIS8 server running on Windows Server 2012.
Preparing the virtual machine image to be reusable
Now suppose you create a lot of webservers, or suppose you configured this server with additional tools and frameworks such as a database, etc. Wouldn't your life be a lot easier if you can just create copies of this exact machine on demand?
This is exactly what we're going to do now, we are going to prepare this virtual machine to be a reusable image.
Go back to the Remote Desktop session, launch the Command Prompt as an Administrator
Change directory to
%windir%\system32\sysprep then run sysprep.exe
When the Sysprep tools comes up, choose "Enter System Out-Of-Box Experience (OOBE)" and make sure "Generalize" is checked, and select "Shutdown" from the Shutdown Options.
Sysprep will do some processing, then the Virtual Machine will shutdown which changes the status of the machine in the Management Portal to Stopped. The process of stopping the virtual machine may take up to 20 minutes. Once the virtual machine is stopped, you will be able to continue.
Capturing the Virtual Machine
Once the machine is stopped, you will be able to click on "Capture" in the Management Portal to create a reusable image out of that machine.
Enter a recognizable name for the image, say "Windows_Server_2012_with_IIS", select "I have run Sysprep on the virtual machine", then continue with capturing. Note that this process deletes the virtual machine.
After this is done, you will find this image in the Images tab, and you will be able to create new virtual machines based on it.
In our next post, we'll see how to use this image and easily create a load balanced web farm of servers.
Note: This post originally appeared on my MSDN blog at http://blogs.msdn.com/b/africaapps/archive/2013/05/28/how-to-customize-a-virtual-machine-on-windows-azure-then-capture-it-as-reusable-image.aspx