Click here to Skip to main content
15,892,161 members
Articles / Productivity Apps and Services / Sharepoint
Technical Blog

HOWTO Setup a Datacenter in a Box

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
8 Dec 2016Ms-PL18 min read 5.8K   3  
Today’s high end desktops and laptops are good enough to host quite a few virtual machines in them, more than sufficient to host a full fledged datacenter in them. In this article, we go through creating a multi machine data center on a single system, and hence the title — datacenter in

Today’s high end desktops and laptops are good enough to host quite a few virtual machines in them, more than sufficient to host a full fledged datacenter in them. In this article, we go through creating a multi machine data center on a single system, and hence the title — datacenter in a box. Of course, before implementing the ideas in this walkthrough, do ensure that you are compliant license wise, that you have sufficient licensing for both the host and the virtual machines.

IMPORTANT:
Licensing considerations

I am not a lawyer, so I will not profess to give you advice on this. You can head over to http://www.microsoft.com/en-us/legal/intellectualproperty/UseTerms/default.aspx to find out more for the specific software that you have. Please ensure that you are always compliant with software licensing. If you are still unsure of how to proceed, either contact an Authorized Software Licensing Consultant for your area.

Today’s high end desktops and laptops are good enough to host quite a few virtual machines in them, more than sufficient to host a full fledged datacenter in them. In this article, we go through creating a multi machine data center on a single system, and hence the title — datacenter in a box. Of course, before implementing the ideas in this walkthrough, do ensure that you are compliant license wise, that you have sufficient licensing for both the host and the virtual machines.

Determine if you have hardware support

If you are performing the steps in this section on the same system that you are reading this article on, please write down the steps on a sheet of paper before
starting to perform them.

If you have a brand new machine, then chances are very high that it has the required support. Otherwise, reboot the machine in question and hold down the DEL key on your keyboard to enter the machine’s BIOS. In the BIOS, look for an “Advanced” or “Onboard Devices” settings screen. In the screen(s) look the below options and enable/disable them as indicated in the below table:

BIOS OptionEnable or Disable
(Intel) Execute Disable (XD)(AMD) No Execute (NX)Enable
(Intel) Virtualization Technology (VT)(AMD) AMD-VEnable
Trusted ExecutionDisable

After enabling and disabling features as above, save your settings (do not exit) and switch off your computer using the power switch or by pulling out its power supply cable. Wait for the system fans to stop and then power it on again. Enter your BIOS again and ensure the changes are in place — if they are not in place, did you save the changes earlier before powering off? Now you may reboot out of the BIOS in the normal way (save and reboot).

Ensure you have a Hyper V Generation 2 system

Hyper V’s latest version is called “Generation 2” and is supported on Windows 8 (64-bit), Windows 8.1 (64-bit), Windows Server 2012 and Windows Server 2012 R2. The Hyper V Generation 2 offers some new functionality within virtual machines: Secure Boot, boot from SCSI virtual hard disks and DVDs, PXE booting from a standard network adapter (previously you needed to have a Legacy network adapter attached to the VM to enable it to boot from PXE) and UEFI firmware support. You can read more on these enhancements on this TechNet page: http://technet.microsoft.com/en-us/library/dn282285.aspx.

Good Practices – but not mandatory

It is a good idea to have at least two physical network cards on a machine you want to install Hyper V on. If you have three, even better. Here is how you would use them:

  • NIC #1 – Primary NIC, you would use this to administer the host system. Applications on the Host would also use this NIC.
  • NIC #2 – Hyper V Internet Facing NIC, used by your Hyper V virtual machines to communicate with your network and the Internet
  • NIC #3 – Hyper V Internal NIC, used by your Hyper V virtual machines to communicate with other Hyper V VMs or physical systems within your network, but not the Internet. Kind of your an “intranet” network.

For our walkthrough, I am using a host machine with two physical network cards. We will use these similar to NIC#1 and NIC #2 above. Before proceeding, open the Network and Sharing Center > Change Adapter Settings and rename the connection to be used for NIC#1 as “Host Administration” and for the NIC #2 as “Internet”.

Note: When selecting NICs in the Hyper V Virtual Switch Manager, it will only show you the actual device name of the NIC as it appears in the Device Manager. To find out which NIC is attached to which network connection, open the Properties of the network connection (from Change adapter settings) and look at the name under “Connect using”.

If you only have one physical NIC on your host machine, don’t worry, I provide instructions for both scenarios below.

Disk Space

Ensure you have a hard disk or hard disk partition (has to be physical) that is large enough to hold all of your virtual machine hard disks. Considering a typical system today easily occupies up to 80 GB when fully installed and configured, including expansion space for future patches and service packs, you need at least 1 TB of free space for a large scale operation. For the purpose of this walkthrough you will need an NTFS formatted drive with at least 520 GB of free space. If not, you will need to adjust the disk sizes in the below (Create your VHDs) section accordingly.

Install and Enable Hyper V

Earlier, to install Hyper V, you needed a server operating system. Otherwise, you had to be content with the “lesser” Virtual PC option on a client operating system. However, starting with Windows 8, Hyper V is now available on the client OS as well. To get started, on Windows 8 and 8.1, go to Control Panel > Add/Remove Programs and click the “Turn Windows Features on or off”. On the server OS, go to your Role manager. Under either screen, check on the Hyper V option, select the combination of sub features you may need and finish the installation. If you are adding through the Roles and Features (Server OS), then you need to add the role “Hyper V” and under Features, you need to add “Hyper V GUI Management Tools” and “Hyper V module for Windows PowerShell” (these are under Remote Server Administration Tools > Role Administration Tools > Hyper V Management Tools.

Since Hyper V modifies critical base system features and drivers, you will need to reboot at the end of the change.

Administering and Using Hyper V

You can administer and use Hyper V from either PowerShell (new commandlets are installed when you install the Hyper V role and features), or from the “Hyper V” console from Administrative tools. If you are a newbie, get started using the GUI console and progress your way to PowerShell. The first time you use the GUI, it will connect automatically to your local Hyper V instance. You can use this console to manage multiple Hyper V systems, but that requires making several system settings including opening of firewall ports and such and we will take a look at all that in a future article.

Our Datacenter Plan

In our virtualized datacenter, we will have 3 VMs: one will be a SQL Server database server, the third will be for IIS and Internet applications with our fourth VM dedicated for DNS and Active Directory. First we will create each VM with an edition of Windows Server 2012 Datacenter edition (selecting this because apparently it has unlimited host and virtualization rights) — you can get your 180 day trial copy here: http://technet.microsoft.com/en-us/evalcenter/hh670538.aspx. We will then provision our ADS VM and install Active Directory with integrated-mode DNS. Next, we will bring up our Internet server. Finally we will bring up our SQL Server system in domain-joined mode.

First up, create your Virtual Network Switches

Hyper V offers three kinds of networking. It is important to understand the pros and cons of each one and create only the ones that are necessary for your environment. The three types are:

  • Private – any VM on this switch will be able to communicate with only other VMs on that host. It can neither access the host machine nor any other machine on your network (outside that particular host) or the Internet. This switch does not make use of any physical NIC.
  • Internal – a VM on this switch can interact with other VMs on that host and with the host itself. But it cannot interact with anything outside the host. This switch does not make use of any physical NIC.
  • External – VMs on this host can access anything that the network adapter it is bound to can access (this includes other hosts, other VMs on other hosts, your internal network resources and may be even the Internet). This switch needs a physical NIC on the host machine to bind to.

Regardless of the switch you choose, you can always connect to the machine from the Hyper V console using the Hyper V VM Console. But you will be able to remote desktop to the machine only if you use the Internal + Host (remote desktop only from the host machine) or External (remote desktop from any machine on your network). And your VMs can themselves have one or more virtual NICs, each of which can bind to one of the virtual network switches on the host.

For our walkthrough, since we have two NICs, we will create two Virtual Network Switches. Ensure you have the Hyper V Manager console open and click on the “Virtual Switch Manager”. We will create one Private switch and one External switch. So go ahead and click on “Private” and then “Create Virtual Switch”. Provide the following details:

  • Name: Private Virtual Switch
  • Description: Datacenter Internal Network
  • Ensure “Connection Type” is set to “Private” and click Apply

Now click on the “New virtual network switch” (first item) on the list of switches on the left-hand pane of this dialog. This time, click “External” and then “Create Virtual Switch”. For this switch make your selections as follows:

  • Name: Internet Network Virtual Switch
  • Description: Datacenter Internet Network
  • Under “Connection Type”, “External network” will already be selected. There will be a drop down with your list of physical NICs. Click the drop down and select the NIC attached to your Internet network.
  • IF YOU HAVE TWO PHYSICAL NICS: Since we have another NIC on this host that we will use for managing the host system, uncheck the “Allow management operating system to share this network adapter” — this will mark the NIC exclusively for your VM network.

Note that this time when you click Apply, network connectivity will be lost for a few seconds — your system will be up and running, but since behind the scenes, Hyper V will change the way your physical NICs and network connections work, connectivity will be disrupted. If you are doing all this using a remote desktop, then it will disconnect — simply wait for about 5-10 seconds and reconnect.

PowerShell way

If you want to do the same as above using PowerShell, here’s the code. If you have only 1 NIC, set the “-AlowManagementOS” parameter to “$true” below.

PS:\> $InternetLANAdapter = Get-NetAdapter -Name "Internet"
PS:\> New-VMSwitch -Name "Private Virtual Switch" -Notes "Datacenter Internal Network" -SwitchType Private
PS:\> New-VMSwitch -Name "Internet Network Virtual Switch" -Notes "Datacenter Internet Network" -NetAdapterName $InternetLANAdapter.Name -AllowManagementOS $false

Differencing versus Cloned versus Fresh systems

There are two ways in which you can create your VMs. If you want a “Fresh” system every time, you start off with a blank virtual hard disk (VHD) and install everything from scratch. There is no particular advantage to doing this unless you need to worry about licensing (some editions of software may offer you unlimited virtualization), or they are different (or different editions or versions) of operating systems or you simply have a lot of time. Some operating systems may not play nice with the “differencing” method I explain below. The next method is to first install a fresh system and store it as an offline VHD (i.e., no running VMs using this VHD file). Whenever you want a new VM, you create a copy of this offline VHD and run your new system off this image. While this is better than the fresh VM method, what it also means is that it gains you no big advantage over the fresh method — you still need to make all the settings each time. The differencing method is similar to the cloned one, but instead of creating a copy of your offline VHD, you create a Differencing Disk with the offline VHD as the parent. Any changes you make to the offline VHD will also appear in the differenced systems.

Patching considerations

When you have the need to periodically keep your systems up to date for software patches and updates, the fresh or cloned system is the best. The differencing method offers really no advantage here, since patches will be installed per system on the particular differenced disk — the parent VHD is never actually touched except in read-only mode to load the operating system and whatever else you installed directly on the parent VHD.

We will use the Fresh method for our walkthrough.

Hyper V Storage Folders

Before we continue, let us set up some folder configurations for later convenience. On my host, I have a 1 TB NTFS partition that I use to store virtual machine definitions and VHD files and everything else related to virtualization. I have this as my “H” (H for Hyper V) drive. On your Hyper V Manager, from the right side menu, click “Hyper V Settings” and set up:

  • Virtual Hard Disks: H:\Disks
  • Virtual Machines: H:\VMs

(Ensure you create these folders first) and then click OK. Nothing to restart.

Create your VHDs

I find it a good idea to first create blank VHDs. And then provision my VMs to use the pre-created VHDs. This method will come in handy for you when you want to use PowerShell to do your Hyper V. We need 10 VHDs of these sizes: 3 VHDs of 80 GB each that we will use as the system drives of our three VMs, 3 VHDs of 40 GB each that we will use as data drives for our three VMs. The remaining 4 VHDs (of 40 GB each) are for use with our SQL Server as its Data, Log, Temp and Backup drives. There are three ways to create VHDs: from Disk Management Console (diskmgmt.msc), from Hyper V Manager’s New > Hard Disk, and from PowerShell. We will create one from each GUI and the other 8 we will create using PowerShell. You can do them by any of these means as you find convenient — just be sure to adjust the file names accordingly.

Disk Management GUI

Fire up diskmgmt.msc from WIN+R. Select any NTFS drive and from the menu Action > Create VHD. Set the Location by using Browse and selecting “H:\Disks” (what you set up for Virtual Hard Disks in Hyper V Manager) Enter the file name as “VM01_SystemDisk.vhd”. Set the size to 80 GB, the format to “VHDX” and set the disk type to “Fixed size” (if you don’t have the 520 GB space recommended for this walkthrough, set up “Dynamically expanding). Click OK.

You will need to wait for about 15 minutes (depending on the speed of your computer and the hard disk) for the system to provision a file of 80 GB size on your hard disk drive. If you selected dynamic disk, then the operation will finish much faster as the file actually provisioned will be smaller.

Hyper V Manager GUI

The process is fairly similar to the DiskMgmt method above. From Hyper V Manager, click New and then Hard Disk. Skip the first page, select “VHDX” format, “Fixed size” (again, if you don’t have the 520 GB space, set to Dynamically Expanding). Set the name as “VM02_SystemDisk.vhd”, note that the folder is preselected for you. Select “Create a new blank virtual hard disk” and specify the size as 80 GB and click Finish.

Again it will take about 10-15 minutes for the operation to complete. If you selected dynamic disk, then the operation will finish much faster as the file actually provisioned will be smaller.

PowerShell

We are going to write quite a bit of code here since we dont want to type a command, wait for 15 minutes and then repeat it. Most of this should be self explanatory, if not, look to the explanation that’s under the code. Before we do this, you need to fire up Windows PowerShell ISE (right click on the PowerShell icon and select “Windows PowerShell ISE” (or search for “powershell” in the Metro UI and select this program). It will open a part text-editor (with the file name as “Untitled1.ps1” and a PowerShell command prompt below.

For the rest of the drives, we will keep the remaining VM03’s system drive as a fixed drive (80GB), but for the seven 40 GB disks, we will use dynamically expanding disks. Paste the following code into the text-editor section of your PowerShell ISE window:

$VHDNamesArray = "VM01_DATA", "VM02_DATA", "VM03_DATA", "SQL_DATA", "SQL_LOG", "SQL_TEMP", "SQL_BACKUP"

# First create the remaining 80GB fixed disk
Write-Host "Creating 80GB fixed disk for VM03 SYSTEM"
New-VHD -Path "H:\Disks\VM03_SYSTEM.vhdx" -Fixed -SizeBytes 80GB

# Now create our 40 GB dynamic disks
foreach($vhdName in $VHDNamesArray) 
{ 
	$VHDPath = "H:\Disks\" + $vhdName + ".vhdx" 
	Write-Host "Creating 40GB dyanmic disk "$VHDPath
	New-VHD -Path $VHDPath -Dynamic -SizeBytes 40GB 
} 

Write-Host "Done." 

The lines starting with a “#” are comments meant for your understanding. The Write-Host statements will print output. PowerShell commandlets do not play nice with in-place string manipulation. So the New-VHD that is within the loop will not work correctly if we do the path and name concatenation in the same line, so we need to do this separately, store the result in a variable and use that variable in the New-VHD command.

To run the script, save it to the Hyper V system’s desktop as “CreateVHDs.ps1”. For this time, you can simply hit “F5” on your keyboard or press the play button on the toolbar. The next time you want to run this script, from the PowerShell prompt, change directory to the Desktop folder (or wherever you saved it) run “.\CreateVHDs.ps1”

The first New-VHD creates the static 80GB file, this will take the 10-15 minutes time. The New-VHD in the loop will take a few seconds each.

Create your VMs

There are two ways to create your VMs. One with the Hyper V Manager (GUI) and the second using PowerShell. Again, we will create the first VM using the GUI and the other 2 with PowerShell.

Hyper V Manager GUI

This time, from the New menu, select “Virtual Machine”. It will open a wizard. Skip the first page and enter the name of the VM, lets call it “VM01-ActiveDirectory-DomainController” (note that this is just a name in Hyper V and not the computer name!). Select the Generation as “Generation 2”, Set startup memory to 4096 MB (4GB… or as high as you can since machines and programs always consume more memory when they startup) and select the “Use dynamic memory for this virtual machine”. Connect the network to the “Private Virtual Switch” — the wizard will add only one network card, you will need to add the second one after creation. For the virtual hard disk, select “Use an existing virtual hard disk” and browse to “H:\Disks” and select the VM01_SYSTEM.vhdx file. Finish the wizard. This will not take time and will quickly return with the VM listed in the Hyper V Manager.

Now we need to open up the newly created Properties and add the second network card and the second (data) hard disk. Right click the VM and select “Settings”. Add Hardware will be selected by default – select Network Adapter, click Add and connect it to the “Internet Network Virtual Switch”. Click Apply. Click where it says “SCSI Controller” on the left-hand pane. Select Hard Drive on the right side and click Add. Browse and attach VM01_DATA.vhdx file. Again click Apply. Add another SCSI controller, this time select DVD Drive, leave the image selection as none and click Apply.

Our first VM is now ready. We will now go ahead and create the other 2 VMs before we install software on them.

PowerShell

Again in Windows PowerShell ISE, paste the following commands and run the script as you did for the VHD creation.

Write-Host "Adding and configuring SQL Server VM"

New-VM -Generation 2 -Name "VM02-SQLServer-DatabaseServer" -MemoryStartupBytes 4096MB -VHDPath "H:\Disks\VM02_SYSTEM.vhdx" -BootDevice VHD -SwitchName "Private Virtual Switch"

Add-VMHardDiskDrive -VMName "VM02-SQLServer-DatabaseServer" -Path "H:\Disks\VM02_DATA.vhdx"
Add-VMHardDiskDrive -VMName "VM02-SQLServer-DatabaseServer" -Path "H:\Disks\SQL_DATA.vhdx"
Add-VMHardDiskDrive -VMName "VM02-SQLServer-DatabaseServer" -Path "H:\Disks\SQL_LOG.vhdx"
Add-VMHardDiskDrive -VMName "VM02-SQLServer-DatabaseServer" -Path "H:\Disks\SQL_TEMP.vhdx"
Add-VMHardDiskDrive -VMName "VM02-SQLServer-DatabaseServer" -Path "H:\Disks\SQL_BACKUP.vhdx"
Add-VMDvdDrive -VMName "VM02-SQLServer-DatabaseServer"
Add-VMNetworkAdapter -VMName "VM02-SQLServer-DatabaseServer" -Name "Internet" -SwitchName "Internet Network Virtual Switch"

Write-Host "Adding and configuring IIS Internet Server VM"

New-VM -Generation 2 -Name "VM03-IIS-InternetServer" -MemoryStartupBytes 4096MB -VHDPath "H:\Disks\VM03_SYSTEM.vhdx" -BootDevice VHD -SwitchName "Private Virtual Switch"

Add-VMHardDiskDrive -VMName "VM03-IIS-InternetServer" -Path "H:\Disks\VM03_DATA.vhdx"
Add-VMDvdDrive -VMName "VM03-IIS-InternetServer"
Add-VMNetworkAdapter -VMName "VM03-IIS-InternetServer" -Name "Internet" -SwitchName "Internet Network Virtual Switch"

Write-Host "Done."

Now we have our three VMs ready. Next to install our software.

Installing software

To start installing software, the easiest way is if you have an RIS (Remote Installation Server) that can supply the boot and installation images to our VMs and we can PXE boot off that. We will look at this scenario in a future article. For now, we have no RIS, so we will make do with ISO files. Note that if you try to install using physical DVD media, installation will be very slow since all three VMs will be trying to install off one DVD. The easier way is to either use the ISO image (downloaded) or convert your DVD into an ISO using any CD/DVD burning software. Once you have the ISO for your copy of Windows Server 2012 Datacenter edition, continue below.

Attach the OS ISO file to all our VMs, if you wish to use only GUI, open a Hyper V Console Connection from Hyper V by right clicking on each VM and selecting Connect. From the menu, select Media > DVD Drive > Insert Disk. Browse to and select the ISO. Then start the VM by clicking the play button on the toolbar. To start from PowerShell doing the same thing, perform these commands for each VM (assuming you have the ISO saved as “H:\ISOs\Win2012R2DataCenter.iso”):

PS:\> Set-VMDvdDrive -VMName "VM01-ActiveDirectory-DomainController" -Path "H:\ISOs\Win2012R2DataCenter.iso"
PS:\> Set-VMDvdDrive -VMName "VM02-SQLServer-DatabaseServer" -Path "H:\ISOs\Win2012R2DataCenter.iso"
PS:\> Set-VMDvdDrive -VMName "VM03-IIS-InternetServer" -Path "H:\ISOs\Win2012R2DataCenter.iso"

PS:\> Start-VM -VMName "VM01-ActiveDirectory-DomainController"
PS:\> Start-VM -VMName "VM02-SQLServer-DatabaseServer"
PS:\> Start-VM -VMName "VM03-IIS-InternetServer"

Now go ahead and install Windows as normal. Once the OS has been installed in each, name the VMs. Name our Active Directory VM as “VM01ADSDC”, the database VM as “VM02SQLDB” and the IIS VM as “VM03WEB”. Also, ensure you have set up your time zone (and system date and time) correctly and then ensure the system is up to date with Windows Update.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --