Separate VM in Hyper-V virtual machines using anti-affinity #winserv #hyperv #DRS   7 comments

For some Virtual machines you don’t want to run them on the same hyper-v server in a cluster. sys you have a two node cluster and running two DC’s you don’t want to run the VM’s on the same hyper-v box.

With anti-affinity you can prevent this that both VM’s are running on the same box. But this is not the same as preferred owner.

With the preferred owner you prevent that the VM will failover to a other Hyper-v host. If the hyper-v host is failing so are all the VM’s on this host there will be no failover to an other Hyper-v host.

image

With the anti-affinity you create a “rule” that says he these two VM’s or cluster roles may never be seen on the same hyper-v host. unless there is no other way.

Anti-Affinity – For a given VM (technically any cluster Group) there is a cluster group property called AntiAffinityClassNames that allows you to configure the preference to attempt to keep that VM off the same node as other similar VMs. Let’s say for example you have two domain controllers running in VMs. It would probably be best to keep those running on different nodes if possible. When determining failover, the cluster service will deprioritize any node which is hosting a similar VM. If there is no other option (in the goal of making VMs available) it will place them on the same host. More information:

http://msdn.microsoft.com/en-us/library/aa369651(VS.85).aspx.

but there is no GUI option for this. PowerShell only and this need settings on all your hyper-v nodes in the cluster.

So get some listing of the classes

Get-ClusterGroup | get-member -name AntiAffinityClassNames

these are the objects “System.Object AntiAffinityClassNames {get;set;}”

If you need more info check this link : http://msdn.microsoft.com/en-us/library/system.collections.specialized.stringcollection.aspx

image

 

With a quick check we can see the current affinity settings

Get-ClusterGroup | Select AntiAffinityClassNames

image

Currently there are no rules in place.

Because I need to run this on all servers I create a nice step by step and easy to change Powershell script

I create several groups names  SQL,VM,DC,APP now I know what machines I can place in the groups.

So I create a small amount of variables

 

$SQLAntiAffinity = New-Object System.Collections.Specialized.StringCollection

$SQLAntiAffinity.Add("SQL Server Instance")

$DCAntiAffinity = New-Object System.Collections.Specialized.StringCollection

$DCAntiAffinity.Add("Domain Controllers")

$WEBAntiAffinity = New-Object System.Collections.Specialized.StringCollection

$WEBAntiAffinity.Add("WEB Servers")

$APPAntiAffinity = New-Object System.Collections.Specialized.StringCollection

$APPAntiAffinity.Add("Application Servers")

image

 

The last part is assign the VM to the group.

(Get-ClusterGroup –Name VMSQL01).AntiAffinityClassNames = $SQLAntiAffinity

(Get-ClusterGroup –Name VMSQL02).AntiAffinityClassNames = $SQLAntiAffinity

(Get-ClusterGroup –Name VMDC01).AntiAffinityClassNames = $DCAntiAffinity

(Get-ClusterGroup –Name VMDC02).AntiAffinityClassNames = $DCAntiAffinity

(Get-ClusterGroup –Name VMWEB01).AntiAffinityClassNames = $WEBAntiAffinity

(Get-ClusterGroup –Name VMWEB02).AntiAffinityClassNames = $WEBAntiAffinity

(Get-ClusterGroup –Name VMAPP01).AntiAffinityClassNames = $APPAntiAffinity

(Get-ClusterGroup –Name VMAPP02).AntiAffinityClassNames = $APPAntiAffinity

 

and You did know you can use the + = to add a VM to the group or Clear the group

(Get-ClusterGroup –Name NEWVM01).AntiAffinityClassNames += $SQLAntiAffinity

or clear the VM from all Groups

(Get-ClusterGroup –Name NEWVM01).AntiAffinityClassNames = “”

 

the rules are in place lets see if we can find them back

Get-ClusterGroup |Select-Object -Property name,AntiAffinityClassNames

image

(Get-ClusterGroup demo01).AntiAffinityClassNames

Now that the roles are in place We can see how It works. I paused a hyper-v node and As soon as I resume the node the anti-affinity rule kicks the VM Winking smile

image

Advertisements

7 responses to “Separate VM in Hyper-V virtual machines using anti-affinity #winserv #hyperv #DRS

Subscribe to comments with RSS.

  1. I’ve created a script which can configure anti-affinity for a set of VMs (cluster groups)
    http://gallery.technet.microsoft.com/Configuring-Anti-Affinity-b61d0ae4

  2. Pingback: Microsoft Most Valuable Professional (MVP) – Best Posts of the Week around Windows Server, Exchange, SystemCenter and more – #68 - Flo's Datacenter Report

  3. Pingback: Microsoft Most Valuable Professional (MVP) – Best Posts of the Week around Windows Server, Exchange, SystemCenter and more – #68 - Dell TechCenter - TechCenter - Dell Community

  4. Pingback: Microsoft Most Valuable Professional (MVP) – Best Posts of the Week around Windows Server, Exchange, SystemCenter and more – #68 - Windows Management - TechCenter - Dell Community

  5. HI!

    Need restart all something else? I was set up anti anfinity but my guest sit in same host.

    thank you

  6. How did you get so smart? Your blog is always full of the best information.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

  • Twitter

  • %d bloggers like this: