10/02/2015 Leave a comment
Disaster Recovery (DR) is a very important component for every IT System. To build a good and acceptable DR infrastructure normally involves datacentres, servers, storage, network bandwidth and all other expensive solutions. All these factors can make a DR plan more complicated for small and medium size companies. The high cost and complexity would make it very difficult to be accomplished.
Hyper- V on Windows Server 2012 R2 comes with a great and improved feature to solve this problem called Hyper-V Replica. It allows virtual machines to be replicated to another server, such a remote disaster recovery site server, using a single network connection.
The Hyper-V Replica components consist of a Primary Server, which host all virtual machines running in production, and the Replica Server, hosting all replica virtual machines from the primary server. It allows administrators to automatically replicate virtual machines to be used in case of a planned failover, like moving VMs to the replication site, or even a failover in unplanned events where the primary server is offline. Windows Server 2012 R2 introduces another option to create an extended replication of your Hyper-V Replica scenario, where you can add a third replication server to your Replica Server and extend the replication to another location or even a cloud provider.
Hyper-V Replica replication engine has a module called Change Tracking that captures every writes within the virtual hard drive file of all running virtual machine and creates a log file. The replication happens in the Virtual Hard Disk (VHD) level, making it even easier and allowing any virtual machine to be replicated. The replication using these logs occurs periodically and asynchronously through a HTTP or HTTPS connection. Windows Server 2012 R2 also brought the option to change the replication frequency, which was 15 minutes previously, but now allows you to select between 30 seconds, 5 minutes and 15 minutes. All the data that must be replicated to the Replica Server uses the Network Module, which optimizes the workload to work in slow network connections like WANs. Basically you will need two physical servers running Hyper-V and a network connection between then. That’s all. It doesn’t need any third party hardware or software. It also has the option to create recovery points so that you can restore virtual machines to a point in time. You don’t have to worry about database corruption or virus replication for example using the Recovery Points, which creates up to 24 points that can be recovered in any point in time from the last 24 replications in the replica server.
Hyper-V Replica is designed to allow small and medium size companies to have a full disaster recovery infrastructure solution for virtualized environment with small costs and components.
Even allowing you to have replicas on the same network, the idea of Hyper-V Replica is to have a replica in a different network where you can run your VMs in case of a disaster, making it fully compliant with almost all disaster recovery policies in place today.
In this recipe you will see how to create a single Hyper-V Replica infrastructure with a primary and recovery server using HTTP based replication.
How to do it…
In the following tasks you will see how to prepare and configure two servers to work with Hyper-V Replica and how to enable replication to a virtual machine. The tasks will illustrate how to set up the Primary Server (HVHost01), the Replica Server (HVHost02) and the server that will be used to extend the replica (HVHost03). At the end of the tasks you will also see how to failover the virtual machine in the replica server in case of disaster.
1. Open the Hyper-V Manager on the server that will be used as Replica Server.
2. In the Hyper-V Manager, click on Hyper-V Settings in the right pane.
3. In the Hyper-V Settings window, select Replication Configuration.
4. Click on Enable this computer as a Replica server.
5. Under Authentication and ports, select Use Kerberos (HTTP) and specify the port to be used.
6. Under Authorization and storage, select Allow replication from any authenticated server and specify the default location to store replica files or Allow replication from the specified servers. If you select the last option, specify the Primary Server, Storage Location and Trust Group.
7. In the following screenshot the port 80 was used to replicate using HTTP. The Primary server *.contoso.com was added to allow replication from any server from the contoso.com domain and a trust group called HVServers was also created. Click OK when finished.
8. When clicking OK, you will see a window to create the Windows Firewall exemption to allow Hyper-V Replica. Click OK to confirm. To configure it manually, open PowerShell from the Taskbar and type the following command.
Enable-Netfirewallrule -displayname "Hyper-V Replica HTTP Listener (TCP-In)"
9. Repeat the steps 1 to 8 in the Primary Server and the server used to extend your replica too.
10. Now with the Replica Server up and running, right click on the virtual machine you want to replicate in the Primary server in the Hyper-V Manager and select Enable Replication.
11. In the Enable Replication Wizard, click Next.
12. In the Specify Replica Server, type the Hyper-V Replica server name in Replica Server and click Next.
13. In Specify Connections Parameters, verify that Use Kerberos authentication (HTTP) is selected. In case of slow network connections, verify that the checkbox Compress the data that is transmitted over the network is selected as shown in the following screenshot and click Next.
14. Under Choose Replication VHDs, select the virtual hard disks file that you want to replicate and click Next.
15. In Configure Replication Frequency, select the time you want to replicate your virtual machines to the replica server. The options are 30 seconds, 5 minutes and 15 minutes. After selecting the option, click Next.
16. In Configure Additional Recovery Points, leave the option Maintain only the latest recovery point to have only the last recovery point in the replica server, as shown in the next screenshot, or select Create additional hourly recovery points to allow the replica server to receive additional recovery points per hour. If you select Create additional hourly recovery points, specify the number of recovery points in Coverage provided by additional recovery points (in hours). To specify the recovery points frequency, select the checkbox Volume Shadow Copy Services (VSS) snapshots frequency (in hours): and use the slider to specify the frequency the snapshots are taken.
17. In the Choose Initial Replication Method window, under Initial Replication Method, select Send initial copy over the network, as shown in the next screenshot, to use the network connection to copy the VM files, Send initial copy using external media to export the VM data and import locally in the replica server or Use an existing virtual machine on the Replica server as the initial copy in case you have a restored copy of the virtual machine on the replica server.
18. Under Schedule Initial Replication, select Start replication immediately, as shown in the following screenshot, to send the virtual machine data straight away after the wizard or select Start replication on, the time and date for scheduled replication to schedule the initial replication and click Next.
19. In Completing the Enable Replication wizard, check the settings and click Finish. The virtual machine data will be transferred to the replica server in the scheduled time and date.
20. Although this is optional, if you want to extend the replication from the Replica Server to a third server, open the Replica Server, right click on the virtual machine you want to replicate, click on Replication and select Extend Replication.
21. In the Before you Begin page, click Next.
22. In Specify Replica Server, type the server name you want to use to extend the replication and click Next.
23. In Specify Connection Parameters, select User Kerberos authentication (HTTP) and click Next.
24. In the Configure Replication Frequency, select the frequency you want to replicate and click Next.
25. In Configure Additional Recovery Points, select the option you prefer and click Next.
26. In Choose Initial Replication Method, select between Send initial copy over the network , Send initial copy using external media or Use an existing virtual machine on the Replica server as the initial copy.
27. Under Schedule Initial Replication, select between Start replication immediately or Start replication on and click Next.
28. In the Completing the Extended Replication wizard, verify the options and click Finish.
29. Wait until the replication is finished. To check if the replication is health, right click on the virtual machine, select Replication and click View Replication Health.
30. After completing the steps above your Hyper-V Replica environment will be up and running, replicating the VM data across the DR server and then to the extended server. In case of a disaster and the primary server is offline, right click on the virtual machine in the replica server, select Replica and click on Failover.
31. In the Failover window, select the recovery point to use in the dropdown list and click Fail Over, as shown in the following screenshot.
How it works…
Hyper-V Replica needs two servers to replicate the virtual machine data and can also use a third server now in Windows Server 2012 R2 to extend the existing replica from the Replica Server. The principal server, which contains the running virtual machines, is known as Primary Server, the secondary server, called Replica Server, gets the replication from the primary server and the optional server used to extend the replica from the Replica Server.
It’s important to mention that you cannot extend the replica from the Primary Server to another server when using Hyper-V replica, but only from the Replica Server.
During the replica configuration, the first thing is to enable the Replica Server in Hyper-V Settings. The settings are divided in two classes: authentication and authorization. In authentication, there are two options to transfer the virtual machine files over the network: HTTP, which doesn’t encrypt the data and doesn’t require any additional configuration and HTTPS, which encrypts the content using digital certificates for authentication. You must request and install a certificate to use certificate based authentication in order to select HTTPS. This option requires a certificate to be installed in both servers prior the replica configuration.
The replica server also needs to be configured to receive data from other servers. That’s the role of the authorization part of the window. You can select the option to Allow replication from any authenticated server or specify a list of servers and the path to store the virtual machine files. In the server list you can also use wildcards like *.contoso.com to allow any server from the contoso.com domain to replicate data to the server. You can use Trusted Groups to separate different areas or customers, creating a sort of tagging. This is an interesting option in case you have different customers and want to make sure their data will be in different locations.
Although the primary server doesn’t need these replica server options, would be a best practice to also enable it in the primary servers so that you can use the Planned Failover feature and transfer the VM back to the primary server after an outage.
Then a firewall exception must be configured to allow Windows Firewall to receive the HTTP requests from the primary server. If you configured the primary server as a replica server you also must run the PowerShell command.
That’s basically all you need to setup the hosts computers with Hyper-V Replica. The next step is to enable the replication on the virtual machines you want. This is done by selecting the option Enable Replication on the VM.
The first thing during the wizard is to select the replica server. After that you can select the protocol to send the VM files. You can use either HTTP or HTTPS. On the same screen you can uncheck the option to compress the data over the network. Because the primary and replica servers are intended to run in different sites, this checkbox is enabled by default. The next option is to select the VHD that need to be replicated. In case the VM has more than one VHD you can select which one will be present in the replica server. Then you can choose in what frequency you want to replicate the virtual machine. In the Configure Additional Recovery Points window you can choose to have only the last recovery point of a VM or additional ones. You can select the number and the interval to create the additional recovery points, which can be up to 24. The last step is to select the initial replication method and schedule. The default method is to send the initial copy over the network. In case of large virtual machines over slow networks, you can export the VM data to an external media and import in the replica server. In case the VM you want to replicate already exist in the replica server, you can use it for the initial copy. Then you can start the replication immediately or schedule the initial replication. It is important to say that the schedule is only applicable during the initial replication. The log replication occurs every five minutes and cannot be changed.
When a virtual machine is enabled to replicate the Hyper-V Replica modules start to monitor the changes in the VHD and create a log to be replicated. This is done by the Change Tracking module in the Hyper-V Virtual Storage Stack. The replication starts using an asynchronous method, replaying the log files in reverse order.
When adding the extended replication to a third server, you will face almost the same options when configuring a normal replica. The only difference is that you will not be able to select which VHD files will be replicated. This is inherited from the Replica Server.
And then the unexpected: a disaster occurs. No need to panic. The failover process is manual. To do so you must select the virtual machine and fail it over. You can also select which recovery point to restore the VM. It comes very handy if you have a virus infection in one of your virtual machine, for example.
As a last tip, it is recommended to monitor the replica health using the default views and tools to make sure you will be able to restore a recent version of your virtual machines in case of failure.
You might be wondering what happen with a virtual machine with a static IP address that fails over on another datacenter with a different subnet and network configuration. For example, on datacenter A, where the primary server sits, you have a VM with IP address, default gateway, DNS settings, etc. On datacenter B, where the replica server is, there are different network configurations, causing problems on all VM that failover to access the network.
When the VM starts on the replica server it will lose the network settings. Even if you keep the same network configuration it will not work because the VM is running on a different network.
That’s why Hyper-V allows you to add failover network configuration settings, which can be used when you failover it to the replica server.
To configure these settings, open the virtual machine settings, expand the attached network adapter and click on Failover TCP/IP, as shown in next screenshot.
Select the checkbox Use the following IPv4 address scheme for the virtual machine and add the network configuration that you want your VM to use when it fails over the other network.
Using PowerShell to Configure and Enable Hyper-V Replica
PowerShell is also present as a secondary configuration option for Hyper-V Replica and sometimes it becomes very handy and easier, as shown in the next examples.
You can use the command Set-VMReplicationServer to configure your server as a replica server. The next example shows a server being enabled using Kerberos as authentication type, with the default storage location point to C:\Hyper-V and with the option to receive replication from any server enabled.
Set-VMReplicationServer -ReplicationEnabled $true -AllowedAuthenticationType Kerberos -DefaultStorageLocation C:\Hyper-V -ReplicationAllowedFromAnyServer $true
To enable replication to a VM you can use the command Enable-VMReplication. The next example shows how to enable replication to all virtual machine at the same time using port 80 on server HVHost02.
Enable-VMReplication -VMName * -ReplicaServerName HVHost02 -ReplicaServerPort 80 -AuthenticationType Kerberos
The Start-VMInitialReplication command starts the initial replication for your virtual machines. The next example shows how to start it on every virtual machine.
Start-VMInitialReplication –VMName *
To list all Hyper-V Replica commandlets on PowerShell, type the following command.
Get-Command -Module Hyper-V *Replica*