Set up Hyper-V 2016 Failover Cluster

In our recent posts, we learned how to set up a nested Hyper-V 2016 lab on VMware Workstation which we later on configured for Shared-nothing setup and Hyper-V Replication. Now on this post, we’re taking things further by learning how to set up Hyper-V 2016 Failover Cluster, and like the previous posts, we’ll use PowerShell as much as we can to get things done. Without further ado, let’s begin.

1. Add Failover Clustering features on our Hyper-V hosts (hv01 and hv02).

1
Install-WindowsFeature -Name Failover-Clustering -ComputerName hv01 -IncludeManagementTools

2. Add RSAT Failover Clustering Tools on dc02 which I use for hosts management purposes. Again, this is not a recommended setup for production environment, but should be ok for a personal lab.

1
Install-WindowsFeature -Name RSAT-Clustering -IncludeAllSubFeature

3. Add 2 more network interfaces to each Hyper-V host using VMware Workstation. We will isolate storage traffic to these interfaces.

4. Add the following hardware to dc02:

• Add 1 more network interface to dc02. We will use dc02 to host the iSCSI Cluster Shared Volume (CSV) and we’ll use this new network interface for that connection.
• Add 1 disk to dc02 which will be used as Clustered Shared Volume (CSV). I added a 100GB disk.

5. Start iSCSI Service of hv01 and hv02 and take note of their IQN.

1
2
3
Start-Service msiscsi
Set-Service -Name msiscsi -StartupType Automatic
(Get-InitiatorPort).NodeAddress

6. Install Windows MPIO feature on the Hyper-V hosts, restart these servers, and then enable the newly installed feature.

1
2
Install-WindowsFeature -Name Multipath-IO -Restart
Enable-WindowsOptionalFeature -Online -FeatureName MultiPathIO

7. Set additional MPIO settings:

•  Enable automatic claiming of iSCSI devices for MPIO

1
Enable-MSDSMAutomaticClaim -BusType iSCSI

• Set load balancing policy

1
Set-MSDSMGlobalDefaultLoadBalancePolicy -Policy RR

We can choose from:

None
FOO – Failover Only
RR – Round Robin
LQD – Least Queue Depth
LB – Least Blocks

8. Now let’s configure dc02 as an iSCSI Target that will host the CSV of our Hyper-V hosts.

1
Install-WindowsFeature -Name FS-iSCSITarget-Server

Tip: If you want to install some Windows Server Roles or Features but don’t know what to put after the -Name parameter, use the cmdlet Get-WindowsFeature and refer to the second column to get what you need.

a. We need to create an iSCSI virtual disk that will serve as our iSCSI LUN, which will then be associated to dc02 because it’s the iSCSI target. This small disk will be the Quorum Witness for the Hyper-V Failover Cluster.

1
2
3
New-IscsiVirtualDisk -Path "C:\Shared Disks\Disk1.vhdx" -Size 1GB
New-IscsiServerTarget -TargetName Disk1 -InitiatorIds "IQN:iqn.1991-05.com.microsoft:hv01.lab.pri","IQN:iqn.1991-05.com.microsoft:hv02.lab.pri"
Add-IscsiVirtualDiskTargetMapping -TargetName Disk1 -Path "C:\Shared Disks\Disk1.vhdx"

b. Set a static IP address on the new network interface of dc02. I set it to 10.0.1.2 which is different from the first network segment that dc02 has.

1
New-NetIPAddress -IfIndex 2 -IPAddress 10.0.1.2 -AddressFamily IPv4 -PrefixLength 24

9. While we are in dc02, let’s prepare the new disk that we added to it, which will be used for  CSV.

1
2
3
4
Set-Disk 1 -IsOffline $false
Initialize-Disk 1 -PartitionStyle MBR
Get-Disk 1 | New-Partition -UseMaximumSize -DriveLetter D
Format-Volume -DriveLetter D -FileSystem NTFS

10. Let’s go back to our Hyper-V hosts and set static IP addresses on their two new network interfaces. I set mine in the 10.0.1.X/24 segment. For example, I used these commands on hv01:

1
2
New-NetIPAddress -IfIndex 4 -IPAddress 10.0.1.10 -AddressFamily IPv4 -PrefixLength 24
New-NetIPAddress -IfIndex 8 -IPAddress 10.0.1.11 -AddressFamily IPv4 -PrefixLength 24

11. Then, we’ll connect each of the Hyper-V hosts’ new network interfaces to the iSCSI Target IP and disks with MPIO enabled:

1
2
3
New-IscsiTargetPortal -TargetPortalAddress 10.0.1.2 -InitiatorPortalAddress 10.0.1.10
New-IscsiTargetPortal -TargetPortalAddress 10.0.1.2 -InitiatorPortalAddress 10.0.1.11
On the previous steps a and b, we'll see that they both didn't have any iSCSI Target and iSCSI Connections. But it's a different story after running the commands above.

1
2
Connect-IscsiTarget -TargetPortalAddress 10.0.1.2 -InitiatorPortalAddress 10.0.1.10 -IsMultipathEnabled $true -IsPersistent $true -NodeAddress iqn.1991-05.com.microsoft:dc02-disk1-target
Connect-IscsiTarget -TargetPortalAddress 10.0.1.2 -InitiatorPortalAddress 10.0.1.11 -IsMultipathEnabled $true -IsPersistent $true -NodeAddress iqn.1991-05.com.microsoft:dc02-disk1-target

After running these commands, we should get a new, offline, RAW disk on our Hyper-V hosts (use Get-Disk).

12. Now, we’ll get the new disk prepared using these commands on one of the Hyper-V hosts:

1
2
3
4
Set-Disk 1 -IsOffline $false
Initialize-Disk 1 -PartitionStyle MBR
Get-Disk 1 | New-Partition -UseMaximumSize -DriveLetter E
Format-Volume -DriveLetter E -FileSystem NTFS

Simply bring the disk online on the rest of the other Hyper-V hosts.

13. Before we actually create our Hyper-V Cluster, let’s run the validation test first using this command on dc02:

1
Test-Cluster -Node hv01,hv02

By default, the validation report will be saved in C:\Users\Administrator\AppData\Local\Temp (given you ran it using the Administrator user account).

14. If you’re following this guide to the T, you shouldn’t see any warning nor any error on the report. We’re good to go to create our cluster.

1
New-Cluster -Name hv-cluster1 -Node hv01,hv02 -StaticAddress 10.0.0.3 -IgnoreNetwork 10.0.0.0/24

15. Let’s add a new iSCSI disk target to our Hyper-V hosts using the 100GB disk that we added to dc02. We’ll basically have to repeat steps 8, 10, 11, and 12, while modifying some values appropriately.

1
2
3
4
5
6
7
8
9
New-IscsiVirtualDisk -Path "D:\Shared Disks\Disk2.vhdx" -Size 90GB
New-IscsiServerTarget -TargetName Disk2 -InitiatorIds "IQN:iqn.1991-05.com.microsoft:hv01.lab.pri","IQN:iqn.1991-05.com.microsoft:hv02.lab.pri"
Add-IscsiVirtualDiskTargetMapping -TargetName Disk2 -Path "D:\Shared Disks\Disk2.vhdx"
New-IscsiTargetPortal -TargetPortalAddress 10.0.1.2 -InitiatorPortalAddress 10.0.1.10
New-IscsiTargetPortal -TargetPortalAddress 10.0.1.2 -InitiatorPortalAddress 10.0.1.11
Connect-IscsiTarget -TargetPortalAddress 10.0.1.2 -InitiatorPortalAddress 10.0.1.10 -IsMultipathEnabled $true -IsPersistent $true -NodeAddress iqn.1991-05.com.microsoft:dc02-disk2-target
Connect-IscsiTarget -TargetPortalAddress 10.0.1.2 -InitiatorPortalAddress 10.0.1.11 -IsMultipathEnabled $true -IsPersistent $true -NodeAddress iqn.1991-05.com.microsoft:dc02-disk2-target
Set-Disk 2 -IsOffline $false
Initialize-Disk 2 -PartitionStyle MBR

16. Add this new disk made available to the members of the cluster to the Failover Cluster and then make it as a Cluster Shared Volume.

1
2
Get-ClusterAvailableDisk | Add-ClusterDisk
Add-ClusterSharedVolume "Cluster Disk 2"

All that we’ve done so far is put together the foundation that makes up our Failover Cluster. We need to do a few more stuffs to see it in action, like have a VM automatically get restarted on another Hyper-V host if the original Hyper-V host fails. Let’s continue.

17. Create a new VM using Failover Cluster Manager, but we’ll choose the CSV for storing the VM files.

Creating a new VM on a member of a cluster using Failover Cluster Manager will automatically enable high availability on the VM.

That’s about it for setting up a Hyper-V 2016 Failover Cluster using PowerShell. One thing to look forward to is getting all these things done automatically by combining all of the commands in a complete script. Perhaps we can do that on some future posts. Until here; hope this helps.

By |2018-10-07T12:54:48+00:00December 20th, 2017|Microsoft, Technology|2 Comments

About the Author:

2 Comments

  1. Abi April 6, 2018 at 6:56 am - Reply

    Thanks for good write up

    But Disk 2 must be formatted as NTFS before adding to CSV

    • elaguni April 11, 2018 at 3:55 pm - Reply

      @Abi
      Thank you for the input!

Leave A Comment