DataCore SANsymphonyとHyper-VでHCI構成を組む時のネットワークをパワーシェルで作る


2019/6/26全面的に書き換えました。

準備

  1. 1サーバーあたり4ポート準備しましょう
  2. 最初の2つはチーミングを組んで、管理(早い話がRDP用)、サービス(別名、VM用とか業務用とか)、ライブマイグレーション、ハートビート、CSV等に使います。
  3. 残り2つはiSCSIに使います。冗長化はMPIOを使うためチーミングは使いません。

#先に必要な機能をインストール
Install-WindowsFeature -Name "Hyper-V", "Failover-Clustering", "Data-Center-Bridging", "RSAT-Clustering-PowerShell", "Hyper-V-PowerShell", "FS-FileServer", "FS-Data-Deduplication"  -IncludeManagementTools -IncludeAllSubFeature
#ついでにファイルサーバーも兼ねるなら
Install-WindowsFeature -Name "FS-FileServer", "FS-Data-Deduplication"  -IncludeManagementTools -IncludeAllSubFeature
#OSの再起動が必要

#変数(適宜書き換える)
##本番ネットワーク用アダプター名
$prodNicName1 = ""
$prodNicName2 = ""
##iSCSIネットワーク用アダプター名
$iSCSINicName1 = ""
$iSCSINicName2 = ""

##本番ネットワーク用チーミング名
$productionTeamName = "Prod_Team"

##vSwitch名
$productionvSwitchName = "Prod_vSwitch"

$iSCSIvSwitchName1 = "iSCSI01_vSwitch"
$iSCSIvSwitchName2 = "iSCSI02_vSwitch"

##vLAN ID
$ManagementVlan=0
$CsvVlan=302
$HeartbeatVlan=303
$LiveMigrationVlan=304

$FE1Vlan=101
$BE1Vlan=101
$MR1Vlan=102

$FE2Vlan=201
$BE2Vlan=201
$MR2Vlan=202

##MinimumBandwidthWeight
$ManagementWeight=80
$CsvWeight=100
$HeartbeatWeight=90
$LiveMigrationWeight=20

$FEWeight=80
$MRWeight=100
$BEWeight=80

##IPアドレス設定
$ManagementIP = "0.0.0.0"
$ManagementPrefix = "24"
$ManagementGW = "0.0.0.0"
$ManagementDNS = "0.0.0.0"
$CsvIP = "0.0.0.0"
$CsvPfrefix = "24"
$HeartbeatIP = "0.0.0.0"
$HeartbeatPrefix = "24"
$LiveMigrationIP = "0.0.0.0"
$LiveMigrationPrefix = "24"

$FE1IP = "0.0.0.0"
$FE1Prefix = "24"
$MR1IP = "0.0.0.0"
$MR1Prefix = "24"
$BE1IP = "0.0.0.0"
$BE1Prefix = "24"

$FE2IP = "0.0.0.0"
$FE2Prefix = "24"
$MR2IP = "0.0.0.0"
$MR2Prefix = "24"
$BE2IP = "0.0.0.0"
$BE2Prefix = "24"

##本番用のチーミングを作ります
$TEAM = New-NetLbfoTeam -Name "$ProductionTeamName" -TeamMembers "$ProdNicName1","$ProdNicName2" -TeamingMode SwitchIndependent -LoadBalancingAlgorithm IPAddresses -confirm:$false
##本番用のvSwitchを作ります
$VS = New-VMSwitch -Name "$productionvSwitchName" -NetAdapterName $TEAM.name -AllowManagementOS $false -MinimumBandwidthMode weight
##本番用のvNICを作ります
###管理(RDPやインターネット接続)を別のオンボードNICにする時はManagementを削除
$Usage = "Management","Csv","Heartbeat","LiveMigration"
Foreach ($i in $Usage){
    $Vlan1 = Get-Variable -Name "${i}Vlan" -ValueOnly
    $IP1 = Get-Variable -Name "${i}IP" -ValueOnly
    $Prefix1 = Get-Variable -Name "${i}Prefix" -ValueOnly
    $Weight1 = Get-Variable -Name "${i}Weight" -ValueOnly
    Add-VMNetworkAdapter -Name $i -ManagementOS -SwitchName $VS.name | Set-VMNetworkAdapterVlan -vlanid $Vlan1 -access | Set-VMNetworkAdapter -ManagementOS -MinimumBandwidthWeight $Weight1
    $NA = Get-NetAdapter | Where-Object{$_.Name -match $i}
    If($i -eq "Management"){ 
        New-NetIPAddress -InterfaceAlias $NA.name -IPAddress $IP1 -AddressFamily IPv4 -PrefixLength $Prefix1 -DefaultGateway $ManagementGW
        Set-DnsClientServerAddress  -InterfaceAlias $NA.Name -ServerAddresses $managementDNS
    }else{
        New-NetIPAddress -InterfaceAlias $NA.Name -IPAddress $IP1 -AddressFamily IPv4 -PrefixLength $Prefix1
        }

}


##iSCSI vSwitchを作ります
For ($x = 1;$x -le 2;$x++){
    $VMSwitchName = Get-Variable -Name "iSCSIvSwitchName${x}" -ValueOnly
    $iSCSINicName = Get-Variable -Name "iSCSINicName${x}" -ValueOnly
    $VS = New-VMSwitch -Name $VMSwitchName -NetAdapterName $iSCSINicName -AllowManagementOS $false -MinimumBandwidthMode weight
    $Role = "FE","MR","BE"
    Foreach ($y in $Role){
        $Vlan2 = Get-Variable -Name "${y}${x}Vlan" -ValueOnly
        $Weight2 = Get-Variable -Name "${y}Weight" -ValueOnly
        $IP2 = Get-Variable -Name "${y}${x}IP" -ValueOnly
        $Prefix2 = Get-Variable -Name "${y}${x}Prefix" -ValueOnly
        ##iSCSI用のvNICを作ります
        Add-VMNetworkAdapter -Name "iSCSI-${y}0${x}" -ManagementOS -SwitchName $VMSwitchName | Set-VMNetworkAdapterVlan -ManagementOS -vlanid $Vlan2 -access | Set-VMNetworkAdapter -ManagementOS -MinimumBandwidthWeight $Weight2
        Get-NetAdapter | Where-Object{$_.Name -match "iSCSI-${y}0${x}"} | New-NetIPAddress -IPAddress $IP2 -AddressFamily IPv4 -PrefixLength $Prefix2
    }
}

完了するとこんな感じです。