02: Basic ESXi Setup

We now have our four ESXi hosts and we need to configure them with storage and for vMotion.  I’m going to use vSphere PowerCLI to do this as it’s easier to document than using the vSphere Client.  Furthermore, using the vSphere Client is tedious when it comes to repeating the same steps on multiple servers where PowerCLI automates this for you out of the box.  And besides VMware are trying to wean us off the vSphere Client!

Before installing PowerCLI you must set the execution policy to allow remote signed scripts.  From an elevated command prompt run

Set-ExecutionPolicy RemoteSigned -Force

Open the PowerCLI installer

image

Accept the EULA

image

Accept the defaults

image

And install

image

All finished

image

Open PowerCLI and connect to all your servers

Connect-VIServer -Server 10.0.1.1,10.0.1.2,10.0.1.3,10.0.1.4 -User root -Password XXX -Force

Delete the default VM Network port group

Get-VirtualPortGroup -Name "VM Network" | Remove-VirtualPortGroup

Create a software iSCSI adapter on the host

Get-VMHostStorage 10.0.1.1 | Set-VMHostStorage -SoftwareIscsiEnabled $true

Determine the name of the HBA created above – typically vmnic33

$hba = Get-VMHostHba -Type IScsi -Host 10.0.1.1

Create a new virtual switch called vSwitch1 on vmnic1

$vs = New-VirtualSwitch -VMHost 10.0.1.1 -Name "vSwitch1" -Mtu 9000 -Nic vmnic1

Using the virtual switch created above create a port group on it called iSCSI and set the IP address. This returns the name of the kernel device created

$vmk = New-VMHostNetworkAdapter -VMHost 10.0.1.1 -VirtualSwitch $vs -PortGroup "iSCSI" -IP 10.1.0.11 -SubnetMask 255.255.255.0 –Mtu 9000

Bind the iSCSI software HBA to the vmkernel port

$esxcli = Get-ESXCLI -VMHost 10.0.1.1
$esxcli.iscsi.networkportal.add($hba, $true, $vmk)

Set the iSCSI target IP address

New-IScsiHbaTarget -IscsiHba $hba -Address 10.1.0.10

Scan the iSCSI target for devices

Get-VMHostStorage -VMHost 10.0.1.$i -RescanAllHba

Create a virtual switch for vMotion and set the IP address

$vs = New-VirtualSwitch -VMHost 10.0.1.1 -Name "vSwitch2" -Mtu 9000 -Nic vmnic2
New-VMHostNetworkAdapter -VMHost 10.0.1.1 -VirtualSwitch $vs -PortGroup "vMotion" -IP 10.1.1.11 -SubnetMask 255.255.255.0 –Mtu 9000 -VMotionEnabled $true

Repeat the above commands for the remaining hosts

ForEach ($i in 2..4) {
	Get-VMHostStorage 10.0.1.$i | Set-VMHostStorage -SoftwareIscsiEnabled $true
	$hba = Get-VMHostHba -Type IScsi -Host 10.0.1.$i
	$vs = New-VirtualSwitch -VMHost 10.0.1.$i -Name "vSwitch1" -Mtu 9000 -Nic vmnic1
	$vmk = New-VMHostNetworkAdapter -VMHost 10.0.1.$i -VirtualSwitch $vs -PortGroup "iSCSI" -IP 10.1.0.1$i -SubnetMask 255.255.255.0 –Mtu 9000
	New-IScsiHbaTarget -IscsiHba $hba -Address 10.1.0.10
	$esxcli = Get-ESXCLI -VMHost 10.0.1.$i
	$esxcli.iscsi.networkportal.add($hba, $true, $vmk)
	Get-VMHostStorage -VMHost 10.0.1.$i -RescanAllHba
	$vs = New-VirtualSwitch -VMHost 10.0.1.$i -Name "vSwitch2" -Mtu 9000 -Nic vmnic2
	New-VMHostNetworkAdapter -VMHost 10.0.1.$i -VirtualSwitch $vs -PortGroup "vMotion" -IP 10.1.1.1$i -SubnetMask 255.255.255.0 –Mtu 9000 -VMotionEnabled $true
}

On the iSCSI target associate the connections from the server with the storage then rescan the HBAs again

Get-VMHostStorage  -RescanAllHba

Experience shows that rescanning the HBA may need to do done two or three times.

Create a network for VM traffic on all hosts

Get-VMHost | New-VirtualSwitch -Name vSwitch3 -Nic vmnic3 | New-VirtualPortGroup -Name "VM Network"

Create a network for DMZ traffic on all hosts

Get-VMHost | New-VirtualSwitch -Name vSwitch4 -Nic vmnic4 | New-VirtualPortGroup -Name "DMZ Network"

Create the iSCSI datastore on one host only and then rescan for the other to pick it up

$lun = Get-ScsiLun | where {$_.Vendor -eq "SCST_BIO"}
New-Datastore -Vmfs -VMHost 10.1.0.10 Path $lun.CanonicalName -Name VMFS01
Get-VMHostStorage -RescanAllHba