Configuring Hyper-V Replica in Windows Server 2012/R2
I’ve been thinking for a while to write this article, and eventually I did it. For those that don’t know what Hyper-V Replica is, I will try to summarize it. Is a host-based replication in the hypervisor, and we are talking about Hyper-V here, at no extra costs; its free. By implementing this feature, you can replicate running virtual machines to another site or other sites stating with Server 2012 R2 (extended replica). If you are thinking to mix this with a Hyper-V Server 2008/R2, thing again, because it won’t work. The only supported editions are the free Hyper-V Server 2012 and Hyper-V on Standard and Datacenter of Windows Server 2012/R2. Hyper-V Replica is using asynchronous replication (data is transmitted one way) and is design for site-to-site disaster recovery (DR), where the Hyper-V host on the DR site has a slightly older copy of the virtual machine(s). In server 2012 the replication was at every five minutes, now in server 2012 R2 you can choose between 30 seconds, 5 and 15 minutes. An important thing to mention here so it will not create any confusion, Hyper-V Replica is not an alternative to a cluster. The VM’s from the DR site will not be automatically powered on, you will have to manually start those machines if the Hyper-V host from the main site fails. If you need highly available virtual machines in a site, you need to deploy a Hyper-V cluster. For more information about Hyper-V Replica you can start reading this Microsoft Technet article, but right now let’s get to work and start configuring the replication.
For this lab I have a Hyper-V 2012 R2 cluster and two non-clustered Hyper-V servers also running server 2012 R2. The two non-clstered Hyper-V servers are in separate sites connected trough a VPN line. The VM’s will replicate from the cluster to one of the stand-alone Hyper-V servers in the first site, and from this one we will configure Extended Replication to the second non-clustered Hyper-V host from the second site. All this happens in a single forest/domain.
Before we actually start enabling replication one other thing needs to be done, enable the Hyper-V Replica Broker role. This is mandatory only for Hyper-V hosts part of a Failover Cluster. If you don’t configure the Hyper-V Replica Broker on the cluster you will get an error when you try to enable replication on VM’s running on that cluster.
A Hyper-V Replica Broker needs to be created on the failover cluster “cluster name“. Create the Hyper-V Replica Broker using Failover Cluster Manager and try again.
So let’s go and enable the Hyper-V Replica Broker. Open the Failover Cluster Manager console, right-click Roles and choose Configure Role.
On the High Availability Wizard page select the Hyper-V Replica Broker role and click Next.
Here you need to provide a name for this role and an IP address. In my case I’m using DHCP, so the address was automatically configured. In a production environment static IP addresses should be used. When you’re done click Next.
Since the wizard needs to create a new computer account in AD, make sure the account you are logged in with on this Hyper-V host/node has rights to create objects in AD, or it will fail. If needed prestage the computer account.
On the Confirmation page hit Next, then Finish to close the wizard.
When this is done, you can find that a new role was created in the cluster. Also, if you take a look in AD a computer object with the name you provided during the wizard was created.
One of the most important setting that must be configured on the Hyper-V Replica Broker role is to enable replication for the cluster. If you don’t configure this, when you try to do a Reverse Replication it will fail. I will talk more about Reverse Replication later in the guide, when we recover from an outage and synchronization needs to be done between VMs from the DR site and the main site. To configure this, right-click the Hyper-V Replica Broker role and choose Replication Settings.
Check the boxes Enable this cluster as a replica server and Use Kerberos (HTTP). Most of the times you are going to use Kerberos for authentication. The only time you will go for certificates based authentication (HTTPS) is when the replica server is not part of a Windows domain or you have a very tight security in your environment. On the Authorization and storage section, you can choose from what hosts to allow the replication and where to store the replica files. For this example I will go with the first option and allow replication from any authenticated server. This means that any Hyper-V host that is joined to the domain can replicate to this server. Click OK when you’re done.
Now we can start enabling replication for our VMs. Select the one you want to replicate to the DR site, right-click it and choose Replication > Enable Replication. If you have more than one, and I’m sure you do, you will need to repeat this operation for every VM.
Type the server name (Replica Server) where you want this VM to be replicated to, or click the Browse button and search for it.
Once you click Next, you should get an error message saying that the specified Replica server is not configured to receive replication from this server. We could avoid this error, but I wanted you to see it in case it happens to you. For now, click the Configure Server button to configure the replication on the destination server, and later I will show you how to do this directly from the Hyper-V host.
In order to do this, the account that is running the wizard needs to have Administrator rights on the specified replica server.
And you’ve seen this screen before when we configured the Hyper-V Replica Broker role, so I’m not going to discuss it again. Make sure you use Kerberos as the authentication mechanism or replication will fail. When done click OK, then hit Next on the Enable Replication wizard.
You should not store your replica virtual machines on the C: drive because you don’t want to accidentally fill the drive and break your management OS. Use a dedicated volume for storing your virtual machines.
One other thing to make sure is to configure the firewall to allow traffic on port 80 on the replica server.
The authentication type is predefined here based on how is the replica server configured. You also have the option to compress the data over the network. Leave the defaults and continue.
Select the virtual disks you want to replicate to the replica server.
One suggestion is to put the guest pagefile on a different VHD/VHDX and when you get to this screen of the wizard choose not to replicate the disk. This can be seen in the bellow picture where I have my Windows 8 VM pagefile on a different virtual disk where I disabled replication. Think about it, the page file is constantly modifying, meaning you will constantly have replication traffic over the WAN, even if it’s incremental is still traffic, resulting in wasted bandwidth. Not only that, but some VMs have large amounts of memory (12, 24 GB of RAM), resulting in large pagefile files that need to be replicated over the WAN.
Another suggestion is to replicate only data drives. Let’s say you have a virtual machine that is running SQL Server. The first VHD (C:) contains the operating system, the second VHD (D:) contains the SQL Server database files, and the third VHD (E:) contains the SQL Server log files. You could configure Hyper-V Replica to replicate just the D: and the E: virtual disks. After invocation, you would have to deploy template VHDs with the operating systems, attach them to the virtual machines, boot them up, reinstall the applications, do any other customizations/updating and reattach the databases.
Choose the replication frequency and continue the wizard. This depends on how much bandwidth you have and where is the replica server located. If is located on the same site, you can go with 30 seconds replication, because is not going over the WAN. Again…this is up to you, and how your infrastructure is set up.
Here we have the option to create additional recovery points or snapshots if you want to call them that. You can go as high as 24 recovery points per VM if you are using server 2012 R2. If you are not on R2 you can go to a maximum of 16 recovery points. To replicate incremental snapshots using the Volume Shadow Copy (VSS), select the check box Volume Shadow Copy Service (VSS) Snapshot frequency in hours, and increase or decrease the hours in the box to specify the frequency at which the snapshots are taken.
Choose how to send the initial replication and when. The initial replication is practically a full copy of the VM and only when the initial replication is done the incremental replication will take over.
On the Summary screen click Finish to enable and start the replication for this VM.
Depending on the size of the VM and the bandwidth you have between sites, this can take a while. If is big, run the initial replication during the night, or send it on a USB drive.
Once the replication is complete you will not get any message about it, but you can take a look on the replica server. The VM should be there, in a power off state.
One other option is to right-click the VM either from the Failover Cluster Manager or Hyper-V Manager, go to Replication and choose View Replication Health.
A window will pop-up with all kinds of information, the health of the replication, when it last occurred, etc.
I know you will be tempted to start the VM on the DR site, and you can even try it, but I guarantee that it will fail with the following error message:
“An error occurred while attempting to start the selected virtual machine(s). Hyper-V prevented starting virtual machine because replication is ongoing. Virtual machine can be started after performing a failover.”
This is because you can’t start a replica while the main VM is still sending replication updates. It can only be started if a planned or unplanned failover occurs. Right now I’m going to simulate an outage on my primary site where the Hyper-Cluster just crashed. To be able to start the VM(s) in the DR site so clients can still work until the failed environment is reinstalled/reconfigured, right-click the VM(s) and choose Replication > Failover.
If you enabled recovery points for the VM, or if you followed me trough this guide you should have a window presenting those recovery points. Click the Fail Over button to power on the VM.
And the VM is started, but as you just saw, you have to do the failover manually. Is not an automated process like it is in a Failover Cluster, but is still a great option to have.
After you restored the environment in the main site all that is left is do a reverse replication from the DR site, and all the VMs will be replicated back. Right-click the VM(s) from the DR site and choose Replication > Reverse Replication.
Do not shut down the VM for this operation since it servers clients. Reverse Replication is working with running VMs.
Specify the Replica server or the Hyper-V Replica Broker if it’s a cluster and click Next. Follow the wizard using the default settings and at the end click Finish to start the replication.
In the Status column of the Hyper-V hosts you can see information about the replication.
When is all done, shut down the VM(s) from the DR site, and on the primary site right-click the VM(s) and choose Replication > Failover. This is to be able to start the VM(s), since this is the site where you will want them to run.
To reverse replication and make the VM(s) from the primary site replicate to the DR site, which is the way it should be, right-click again the VM(s) and choose Replication > Reverse Replication. Follow the wizard as we did before. The Hyper-V hosts will start sending the initial replication to the Replica server.
You might think I’m done, but I’m not. There is one more thing I want to show you before I close; the Extended Replica feature. As I’ve said at the begging of the article in server 2012 R2 you can have two sites for DR. Until now we only worked with one. Before we start to configure Extended Replica, let’s configure the Hyper-V host from the second DR site. Open the Hyper-V Settings,
go to Replication Configuration, and as before check Enable this computer as a Replica server and Use Kerberos (HTTP).
You can also use PowerShell to enable this computer as a replica server:
Set-VMReplicationServer -ReplicationEnabled $True -AllowedAuthenticationType `Kerberos -ReplicationAllowedFromAnyServer $True -DefaultStorageLocation D:\
And set the firewall rules:
Enable-NetFirewallRule -DisplayName "Hyper-V Replica HTTP Listener (TCP-In)"
Now we can go ahead and enable Extended Replica. Right-click the VM(s) sitting on your first DR site and choose Replication > Extended Replication.
The wizard is the same as Enable Replication Wizard that we worked with until now. Specify the Replica server name or Hyper-V Replica Broker server and continue the wizard using the default options.
And they start replicating.
This replication solution is great and a lot of small business can benefit for it, but some limitations exists:
– You cannot replicate virtual machines from one host to another host in the same cluster. And it makes sense, considering that a cluster has “single shared storage,” even if that shared storage is replicated from one site to another.
– You can replicate a virtual machine to only a single destination (host or cluster).
To end this, all I have to say is thanks for bearing out with me on this one too.
Want content like this delivered right to your
2 thoughts on “Configuring Hyper-V Replica in Windows Server 2012/R2”
Could you go into a little more detail on Recovery Points… If I check the additional recovery points and leave 24 hours, am I correct that there will be one per hour? Where do they show, Checkpoints?
If I changed the hours to 4, then there would be 4 recovery points created over a 24 hour period. Correct??
The verbiage on the wizard window is a little confusing.
How can all of this be done through VMM 2012 R2 Console 🙂