I've just decided to create some step by step guide how to create VMware cluster via PowerCLI
Please keep in mind that this guide will not show you how to configure all parameters but should give you an idea how to start.
Prerequisite for this guide:
- vCentre server has to be installed and static IP configured
- All ESX hosts should have hypervisor installed and static management IP configured
- There has to be network connectivity between vCentre and ESX hosts
Connect to your vCentre server
Connect-VIServer vcentre.localdomain.local
Get default folder list, we will use it to create datacentre
Get-Folder
PowerCLI C:\> Get-Folder Name Type ---- ---- Datacenters Datacenter vm VM network Network host HostAndCluster datastore Datastore Discovered virtual machine VM
Create new datacentre "Datacentre_01"
New-Datacenter -Location Datacenters -Name Datacentre_01
Create new cluster in datacentre "Datacentre_01"
New-Cluster -Name Cluster_01 -Location "Datacentre_01"
On "Cluster_01" enable HA, virtual machines in the cluster should not start if they violate availability constraints, cluster should tolerate 1 host failure, VM swap file should be stored wit VM files, VM restart priority in case of host failure should be "Low", in case of host isolation all running VMs should remain online
Get-Cluster -Name Cluster_01 | Set-Cluster -Name Cluster_01 -HAEnabled:$true -HAAdmissionControlEnabled:$true -HAFailover 1 -VMSwapfilePolicy "WithVM" -HARestartPriority "Low" -HAIsolationResponse "DoNothing" -Confirm:$false
On "Cluster_01" enable DRS and set to be fully automated
Set-Cluster -Cluster Cluster_01 -DRSEnabled:$true -DRSAutomationLevel "FullyAutomated" -Confirm:$false
On "Cluster_01" enable EVC for intel-nehalem
Set-Cluster -Cluster Cluster_01 -EVCMode "intel-nehalem" -Confirm:$false
If you want to disable EVC run:
Set-Cluster -Cluster Cluster_01 -EVCMode $null -Confirm:$false
Add host esx-01 to "Cluster_01"
Add-VMHost -Name esx-01.localdomain.local -Location Cluster_01 -User root -Password password
If you want to remove host from cluster run:
Set-VMHost -VMHost esx-01.localdomain.local -State Disconnected Remove-VMHost esx-01.localdomain.local -Confirm:$false
Put your host in maintenance mode
Set-VMHost -VMHost esx-01.localdomain.local -State Maintenance
Get esx host physical nic list
Get-VMHost -Name esx-01.localdomain.local | Get-VMHostNetworkAdapter | where {$_.DeviceName -like "*nic*"} | select Name
PowerCLI C:\>Get-VMHost -Name esx-01.localdomain.local | Get-VMHostNetworkAdapter | where {$_.DeviceName -like "*nic*"} | select Name Name ---- vmnic0 vmnic1 vmnic2 vmnic3
Confirm that there is only one nic attached to default vSwitch0
Get-VMHost -Name esx-01.localdomain.local | Get-VirtualSwitch -Name vSwitch0 | select Nic
PowerCLI C:\>Get-VMHost -Name esx-01.localdomain.local | Get-VirtualSwitch -Name vSwitch0 | select Nic Nic --- {vmnic0}
Add 2nd physical nic "vmnic1" to vSwitch0
$nic = Get-VMHost -Name esx-01.localdomain.local | Get-VMHostNetworkAdapter -Physical -Name vmnic1 Get-VMHost -Name esx-01.localdomain.local | Get-VirtualSwitch -Name vSwitch0 | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $nic -Confirm:$false
Create new VM port group on vSwitch0
Get-VMHost -Name esx-01.localdomain.local | Get-VirtualSwitch -Name vSwitch0 | New-VirtualPortGroup -Name vPortgroup
Add vlan id 120 to port group "vPortgroup"
Get-VMHost -Name esx-01.localdomain.local | Get-VirtualSwitch -Name vSwitch0 | Get-VirtualPortGroup -Name vPortgroup | Set-VirtualPortGroup -name test -VLanId 120
Create new VM port group on vSwitch0 with vlan id 120
Get-VMHost -Name esx-01.localdomain.local | Get-VirtualSwitch -Name vSwitch0 | New-VirtualPortGroup -Name vPortgroup -VLanId 120
Create new vdSwitch with 2 uplinks
$Datacentre = Get-Datacenter -Name Datacentre_01 New-VDSwitch -Name vdSwitch0 -Location $Datacentre -NumUplinkPorts 2 -LinkDiscoveryProtocol "LLDP" -LinkDiscoveryProtocolOperation "Listen" -MaxPorts 256 -Version "6.0.0"
Set uplink teaming policy for vdSwitch0: dvUplink1 as active and dvUplink2 as standby
Get-VDSwitch -Name vdSwitch0 | Get-VDPortgroup | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -ActiveUplinkPort dvUplink1 -StandbyUplinkPort dvUplink2
Create new port group Production on vdSwitch0 with 16 ports, vlan id 200 and port binding Ephemeral
Get-VDSwitch -Name vdSwitch0 | New-VDPortgroup -Name Production -NumPorts 16 -VLanId 200 -PortBinding Ephemeral
Create new port group vMotion on vdSwitch0 with 16 ports, vlan id 110 and port binding Ephemeral
Get-VDSwitch -Name vdSwitch0 | New-VDPortgroup -Name vMotion -NumPorts 16 -VLanId 110 -PortBinding Ephemeral
Overwrite uplink teaming policy for vMotion port group: dvUplink2 as active and dvUplink1 as standby
Get-VDSwitch -Name vdSwitch0 | Get-VDPortgroup -Name vMotion | Get-VDPortgroupOverridePolicy | Set-VDPortgroupOverridePolicy -UplinkTeamingOverrideAllowed $true Get-VDSwitch -Name vdSwitch0 | Get-VDPortgroup -Name vMotion | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -ActiveUplinkPort dvUplink2 -StandbyUplinkPort dvUplink1
Add esx-01 host to vdSwitch0
Get-VDSwitch -Name vdSwitch0 | Add-VDSwitchVMHost -VMHost esx-01.localdomain.local
Add vmnic2 and vmnic3 of esx-01 host to vdSwitch0 uplinks
$nic2 = Get-VMHost -Name esx-01.localdomain.local | Get-VMHostNetworkAdapter -Physical -Name vmnic2 $nic3 = Get-VMHost -Name esx-01.localdomain.local | Get-VMHostNetworkAdapter -Physical -Name vmnic3 Get-VDSwitch -Name vdSwitch0 | Add-VDSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $nic2 -Confirm:$false Get-VDSwitch -Name vdSwitch0 | Add-VDSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $nic3 -Confirm:$false
Add vmkernel port to vdSwitch0 to vMotion port group and configure it for vMotion traffic with static IP address
New-VMHostNetworkAdapter -VMHost esx-01.localdomain.local -VirtualSwitch vdSwitch0 -PortGroup vMotion -IP 192.168.0.1 -SubnetMask 255.255.255.0 -VMotionEnabled:$true
Remove your host from maintenance mode
Set-VMHost -VMHost esx-01.localdomain.local -State Connected
And finally I have put all commands together to make easy script to configure a cluster
$VIUser="administrator" $VIPassword="password" $HostUser="root" $HostPassword="hostpassword" $DatacentreName="Datacentre_01" $ClusterName="Cluster_01" $vSwitchName="vSwitch0" $vdSwitchName="vdSwitch0" $vMotionNet="192.168.0." $VMotionStartIP=1 $VMotionNetMask="255.255.255.0"$HostNames=@("esx-01.localdomain.local","esx-02.localdomain.local") Connect-VIServer vcentre.appv4u.com -User $VIUser -Password $VIPassword New-Datacenter -Location Datacenters -Name $DatacentreName New-Cluster -Name $ClusterName -Location $DatacentreName Get-Cluster -Name $ClusterName | Set-Cluster -Name $ClusterName -HAEnabled:$true -HAAdmissionControlEnabled:$true -HAFailover 1 -VMSwapfilePolicy "WithVM" -HARestartPriority "Low" -HAIsolationResponse "DoNothing" -Confirm:$false Set-Cluster -Cluster $ClusterName -DRSEnabled:$true -DRSAutomationLevel "FullyAutomated" -Confirm:$false Set-Cluster -Cluster $ClusterName -EVCMode "intel-nehalem" -Confirm:$false $Datacentre = Get-Datacenter -Name $DatacentreName New-VDSwitch -Name $vdSwitchName -Location $Datacentre -NumUplinkPorts 2 -LinkDiscoveryProtocol "LLDP" -LinkDiscoveryProtocolOperation "Listen" -MaxPorts 256 -Version "6.0.0" Get-VDSwitch -Name $vdSwitchName | Get-VDPortgroup | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -ActiveUplinkPort dvUplink1 -StandbyUplinkPort dvUplink2 Get-VDSwitch -Name $vdSwitchName | New-VDPortgroup -Name Production -NumPorts 16 -VLanId 200 -PortBinding Ephemeral Get-VDSwitch -Name $vdSwitchName | New-VDPortgroup -Name vMotion -NumPorts 16 -VLanId 110 -PortBinding Ephemeral Get-VDSwitch -Name $vdSwitchName | Get-VDPortgroup -Name vMotion | Get-VDPortgroupOverridePolicy | Set-VDPortgroupOverridePolicy -UplinkTeamingOverrideAllowed $true Get-VDSwitch -Name $vdSwitchName | Get-VDPortgroup -Name vMotion | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -ActiveUplinkPort dvUplink2 -StandbyUplinkPort dvUplink1 foreach ($HostName in $HostNames){ $VMotionIP=$vMotionNet+$VMotionStartIP Add-VMHost -Name $HostName -Location $ClusterName -User $HostUser -Password $HostPassword | Out-Null Set-VMHost -VMHost $HostName -State Maintenance | Out-Null $nic1 = Get-VMHost -Name $HostName | Get-VMHostNetworkAdapter -Physical -Name vmnic1 Get-VMHost -Name $HostName | Get-VirtualSwitch -Name vSwitch0 | Add-VirtualSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $nic1 -Confirm:$false Get-VDSwitch -Name $vdSwitchName | Add-VDSwitchVMHost -VMHost $HostName $nic2 = Get-VMHost -Name $HostName | Get-VMHostNetworkAdapter -Physical -Name vmnic2 $nic3 = Get-VMHost -Name $HostName | Get-VMHostNetworkAdapter -Physical -Name vmnic3 Get-VDSwitch -Name $vdSwitchName | Add-VDSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $nic2 -Confirm:$false Get-VDSwitch -Name $vdSwitchName | Add-VDSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $nic3 -Confirm:$false New-VMHostNetworkAdapter -VMHost $HostName -VirtualSwitch $vdSwitchName -PortGroup vMotion -IP $VMotionIP -SubnetMask $VMotionNetMask -VMotionEnabled:$true Set-VMHost -VMHost $HostName -State Connected $VMotionStartIP++ $VMotionIP="" } Disconnect-VIServer -Confirm:$false
No comments:
Post a Comment