Advertisement
Guest User

Untitled

a guest
Nov 15th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.40 KB | None | 0 0
  1. ###########################################################
  2. # #
  3. # VMware Virtual SAN -- Making Storage Great Again #
  4. # #
  5. ###########################################################
  6. ###########################################################
  7. # #
  8. # The All-in-One Virtual SAN Deployment Script #
  9. # #
  10. # by Alan Renouf and Rawlinson #
  11. # #
  12. ###########################################################
  13.  
  14. # -- Infrastructure Configuration Settings Section --
  15.  
  16. $VCNode = "vcenter.vsan.com"
  17. $VCUserName = "administrator@vsphere.local"
  18. $VCPassword = "password"
  19. $ESXiUserName = "root"
  20. $ESXiPassword = 'password'
  21. $DCName = "vsan-4-life"
  22. $CluName = "vsan-all-flash"
  23. $VDSName = "10G Switch"
  24. $PortGroupRange = 3006 #3001..3007
  25. $DNS = "10.4.90.21", "10.4.90.22"
  26. $NTP = "10.4.90.12", "10.4.90.28"
  27. $VMotionIP = "192.168.21."
  28. $VSANIP = "192.168."
  29. $iSCSIIP = "192.168.22."
  30. $NFSIP = "192.168.23."
  31. $targets = "192.168.22.213"
  32. $cachingSSD = "S630DC-960"
  33. $CapacitySSD = "MICRON_M510DC_MT"
  34.  
  35. ####################################################################################################
  36.  
  37. # -- Import PowerCLI Modules --
  38.  
  39. get-module -ListAvailable VMware* | Import-Module | Out-Null
  40.  
  41.  
  42. # -- Connect to vCenter --
  43.  
  44. Connect-viserver $VCNode -user $VCUserName -pass $VCPassword -WarningAction SilentlyContinue
  45.  
  46. # -- Datacenter/Cluster Configuration --
  47.  
  48. # -- Create Datacenter --
  49.  
  50. Write-Host "Creating Datacenter: $DCName" -ForegroundColor Green
  51. $DC = New-Datacenter -Name $DCName -Location (Get-Folder Datacenters)
  52.  
  53. # -- Create Cluster --
  54.  
  55. Write-Host "Creating Cluster: $CluName" -ForegroundColor Green
  56. $CLU = New-Cluster -Name $CluName -Location ($DC) -DrsEnabled
  57.  
  58. # -- Add Hosts to cluster --
  59.  
  60. 09..16 | Foreach {
  61. $num = $_ ;
  62. $newnum = "{0:D2}" -f $num
  63. Write-Host "Adding host w3-octo-sm-$newnum.eng.vmware.com" -ForegroundColor Green
  64. Add-VMHost -Name "w3-octo-sm-$newnum.eng.vmware.com" -Location $CluName -User $ESXiUserName -Password $ESXiPassword -Force -RunAsync | FT | Out-Null
  65. }
  66.  
  67. # -- Host Configuration --
  68.  
  69. Sleep 20
  70. $VMHosts = Get-VMHost | Sort Name
  71.  
  72. # -- Add DNS/NTP and Enable iScsi Settings for the hosts --
  73.  
  74. Foreach ($vmhost in $vmhosts) {
  75. Write-Host "Configuring DNS and Domain Name on $vmhost" -ForegroundColor Green
  76. Get-VMHostNetwork -VMHost $vmhost | Set-VMHostNetwork -DNSAddress $DNS -Confirm:$false | FT | Out-Null
  77.  
  78. Write-Host "Configuring NTP Servers on $VMHost" -ForegroundColor Green
  79. Add-VMHostNTPServer -NtpServer $NTP -VMHost $VMHost -Confirm:$false -ErrorAction SilentlyContinue | FT | Out-Null
  80.  
  81. Write-Host "Configuring NTP Client Policy on $VMHost" -ForegroundColor Green
  82. Get-VMHostService -VMHost $VMHost | where {$_.Key -eq "ntpd"} | Set-VMHostService -policy "on" -Confirm:$false | FT | Out-Null
  83.  
  84. Write-Host "Restarting NTP Client on $VMHost" -ForegroundColor Green
  85. Get-VMHostService -VMHost $VMHost | where {$_.Key -eq "ntpd"} | Restart-VMHostService -Confirm:$false | FT | Out-Null
  86.  
  87. Write-Host "Enabling iSCSI on $VMhost" -ForegroundColor Green
  88. Get-VMHostStorage -VMHost $VMHost | Set-VMHostStorage -SoftwareIScsiEnabled $True | FT | Out-Null
  89.  
  90. }
  91.  
  92. # -- DVSwitch Configuration --
  93.  
  94. # -- Create DVSwitch --
  95.  
  96. Write-Host "Creating VDSwitch: $VDSName" -ForegroundColor Green
  97. $VDS = New-VDSwitch -Name $VDSName -NumUplinkPorts 2 -Location $DC -Mtu 9000 -Version "6.0.0"
  98.  
  99. # -- Create Portgroups --
  100.  
  101. $PortGroupRange | Foreach {
  102. Write-Host "Creating PortGroup: VSAN Network $($_)" -ForegroundColor Green
  103. New-VDPortgroup -Name "VSAN Network $($_)" -Vds $vds -VlanId $_ | FT | Out-Null
  104. }
  105.  
  106. Write-Host "Creating vMotion Network 3021" -ForegroundColor Green
  107. New-VDPortgroup -Name "vMotion Network 3021" -VDSwitch $vds -VlanId 3021 | FT | Out-Null
  108.  
  109. Write-Host "Creating ISCSI Network 3022" -ForegroundColor Green
  110. New-VDPortgroup -Name "ISCSI Network 3022" -VDSwitch $vds -VlanId 3022 | FT | Out-Null
  111.  
  112. Write-Host "Creating NFS Network 3023" -ForegroundColor Green
  113. New-VDPortgroup -Name "NFS Network 3023" -VDSwitch $vds -VlanId 3023 | FT | Out-Null
  114.  
  115. # -- Add Hosts to VDSWitch and Migrate pNIC to VDS (vmnic2/vmnic3) --
  116.  
  117. Foreach ($vmhost in $VMHosts) {
  118. Write-Host "Adding $VMHost to $VDSName" -ForegroundColor Green
  119. $vds | Add-VDSwitchVMHost -VMHost $vmhost | FT
  120. $vmhostNetworkAdapter = Get-VMHost $vmhost | Get-VMHostNetworkAdapter -Physical -Name vmnic2
  121. Write-Host "Adding $VMHostNetworkAdapter to $VDSName" -ForegroundColor Green
  122. $vds | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostNetworkAdapter -Confirm:$false | FT | Out-Null
  123. $vmhostNetworkAdapter = Get-VMHost $vmhost | Get-VMHostNetworkAdapter -Physical -Name vmnic3
  124. Write-Host "Adding $VMHostNetworkAdapter to $VDSName" -ForegroundColor Green
  125. $vds | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostNetworkAdapter -Confirm:$false | FT | Out-Null
  126. }
  127.  
  128. # -- Set DVUplink2 to standby --
  129.  
  130. $TeamingPolicys = $vds | Get-VDPortgroup VSAN* | Get-VDUplinkTeamingPolicy
  131. Foreach ($Policy in $TeamingPolicys) {
  132. Write-Host "Setting Standby Uplink for $Policy.VDPortGroup" -ForegroundColor Green
  133. $Policy | Set-VDUplinkTeamingPolicy -StandbyUplinkPort "dvUplink2" | FT | Out-Null
  134. }
  135.  
  136. # -- Create vMotion, iSCSI and VSAN VMKernel Ports --
  137.  
  138. foreach ($vmhost in $vmhosts) {
  139. $HostIP = ($vmhost | Get-VMHostNetworkAdapter -Name vmk0).ip
  140. $LastO = $HostIP.Split(".")[3]
  141. $CurrentvMotionIP = $vMotionIP + $LastO
  142. $CurrentiSCSIIP = $iSCSIIP + $LastO
  143. $CurrentNFSIP = $NFSIP + $LastO
  144. Write-Host "Adding vMotion Network Adapter to $VMHost with IP of $CurrentvMotionIP" -ForegroundColor Green
  145. New-vmhostnetworkadapter -VMHost $vmhost -PortGroup "vMotion Network 3021" -VirtualSwitch $vds -VMotionEnabled $true -IP $CurrentvMotionIP -SubnetMask "255.255.255.0" | FT | Out-Null
  146. Write-Host "Adding iSCSI Network Adapter to $VMHost with IP of $CurrentISCSIIP" -ForegroundColor Green
  147. New-vmhostnetworkadapter -VMHost $vmhost -PortGroup "ISCSI Network 3022" -VirtualSwitch $vds -IP $CurrentiSCSIIP -SubnetMask "255.255.255.0" | FT | Out-Null
  148. Write-Host "Adding NFS Network Adapter to $VMHost with IP of $CurrentNFSIP" -ForegroundColor Green
  149. New-vmhostnetworkadapter -VMHost $vmhost -PortGroup "NFS Network 3023" -VirtualSwitch $vds -IP $CurrentNFSIP -SubnetMask "255.255.255.0" | FT | Out-Null
  150.  
  151. Foreach ($VSANNet in (Get-VDPortGroup VSAN*)){
  152. $3rdO = ($VSANNet.Name).Substring(16)
  153. $CurrentVSANIP = $VSANIP + $3rdO + "." + $LastO
  154. Write-Host "Adding $CurrentVSANIP to $($VSANNet.Name) and enabling VSAN traffic" -ForegroundColor Green
  155. $VSANVMK = New-vmhostnetworkadapter -VMHost $vmhost -PortGroup $VSANNet.Name -VirtualSwitch $vds -VsanTrafficEnabled $true -IP $CurrentVSANIP -SubnetMask "255.255.255.0"
  156. }
  157. }
  158.  
  159. # -- iSCSI Configuration --
  160.  
  161. # -- Configure iSCSI Targets --
  162.  
  163. Sleep 20
  164. foreach ($VMHost in $VMHosts) {
  165. Write-host "Configuring $vmhost for iScsi" -ForegroundColor Green
  166. $hba = $VMHost | Get-VMHostHba -Type iScsi | Where {$_.Model -eq "iSCSI Software Adapter"}
  167. If ($hba) {
  168. foreach ($target in $targets) {
  169. Write-Host "Adding $target to $hba" -ForegroundColor Green
  170. New-IScsiHbaTarget -IScsiHba $hba -Address $target | FT | Out-Null
  171. }
  172. } Else {
  173. Write-Host "No iSCSI hba found on $VMHost" -ForegroundColor Green
  174. }
  175. }
  176.  
  177. Write-Host "Enabling VSAN in manual mode for Cluster: $CLU" -ForegroundColor Green
  178. $CLU = $CLU | Set-Cluster -VsanEnabled:$true -VsanDiskClaimMode Manual -Confirm:$false -ErrorAction SilentlyContinue
  179.  
  180. Foreach ($vmh in $vmhosts) {
  181. Write-Host "Finding disks for $($vmh)"
  182. $esxcli = Get-ESXCLI -VMhost $vmh
  183. 0..1 | Foreach {
  184. $DiskgroupNum = $_ +1
  185. $Caching = ($esxcli.storage.core.device.list() | Where {$_.model -eq $cachingSSD})[$_]
  186. $Capacity = ($esxcli.storage.core.device.list() | Where {$_.model -eq $capacitySSD})[$_]
  187. Write-Host "Using $($caching.Vendor) - $($caching.Model) for Caching in Disk Group $Diskgroupnum" -foregroundColor Green
  188. Write-Host "Using $($Capacity.Vendor) - $($Capacity.Model) for Capacity in Disk Group $Diskgroupnum" -foregroundColor Green
  189. Write-Host "Tagging $($Capacity.Model) as Capacity"
  190. $capacitytag = $esxcli.vsan.storage.tag.add(($capacity.Device), "capacityFlash")
  191. Write-Host "Adding Storage devices to $($vmhost)"
  192. $adddisks = $esxcli.vsan.storage.add(($capacity.device), ($Caching.device))
  193. if ($adddisks -eq "true") {
  194. Write-Host "Disks added" -ForegroundColor Green
  195. } Else {
  196. Write-Host "Error adding disks: $adddisks" -ForegroundColor Red
  197. }
  198. }
  199. Write-Host "Enable space efficiency sparse swap on $($vmh)" -ForegroundColor Green
  200. Get-AdvancedSetting -Entity $vmh -Name "VSAN.SwapThickProvisionDisabled" | Set-AdvancedSetting -Value 1 -Confirm:$false | out-null
  201.  
  202. }
  203.  
  204. If ($CLU.VSANEnabled){
  205. Write-Host "VSAN cluster $($CLU.Name) created in $($CLU.VSANDiskClaimMode) configuration" -ForegroundColor Yellow
  206. Write-Host "The following Hosts and Disk Groups now exist:"
  207. Get-VsanDiskGroup | Select VMHost, Name | FT -AutoSize | Out-Null
  208. Write-Host "The following VSAN Datastore now exists:"
  209. Get-Datastore | Where {$_.Type -eq "vsan"} | Select Name, Type, FreeSpaceGB, CapacityGB
  210. } Else {
  211. Write-Host "Something went wrong, Virtual SAN not enabled"
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement