LoginSignup
0
2

More than 3 years have passed since last update.

Windowsサーバー(Hyper-Vホスト)にADDS(ドメコン)の仮想マシンを作ってドメイン参加

Last updated at Posted at 2019-05-14

仮想化ホストでライブマイグレーションをしたい(というか、まずはクラスターを組みたい)けど既存のドメインもないし、他にサーバーもない…そんな時に使う手順のまとめ。
最低限の2台構成でそれぞれ上にドメインコントローラーも2個作って、どっちか落ちてもいいように冗長化。
これができたらS2Dでもライブマイグレーションでも構築し放題。

ホストの設定(コンピュータ名とかIPアドレスとか)は終わらせてある前提です。

ホストの準備

#Cドライブの後ろにAD仮想マシン専用のパーティションを作成
#別の論理ディスクやドライブがある場合は不要
♯Cドライブのフォルダに作ってもOK(その場合は、Set-VMHostのパスを修正)
$DisksizeGB = 20 #お好みの容量で
$Cdrive = Get-Partition -DriveLetter "C"
$newCdrivesize =  $Cdrive.size - ($DisksizeGB * 1024 * 1024 * 1024)
Resize-Partition -DriveLetter C -Size $newCdrivesize
Get-Partition -DriveLetter C|Get-Disk|New-Partition -UseMaximumSize -DriveLetter D |Format-Volume -FileSystem NTFS -NewFileSystemLabel "AD1"

ホストのHyper-Vの設定

Set-VMHost -ComputerName (hostname) -VirtualHardDiskPath "D:\VHD" -VirtualMachinePath "D:\" -EnableEnhancedSessionMode $true
New-VMSwitch -Name MGMT -NetAdapterName MGMT -AllowManagementOS $true 

仮想マシンの作成と起動

$VMName = "AD1"
New-VM -Name $VMName -Generation 2 -MemoryStartupBytes 4096MB -SwitchName MGMT -NewVHDPath ($VMName + ".VHDX") -NewVHDSizeBytes 100GB
Set-VM -VMname $VMName -StaticMemory -ProcessorCount 2 -AutomaticStartAction Start -AutomaticStopAction ShutDown
Add-VMDvdDrive -VMName $VMName -Path C:\ISO\en_windows_server_2016_x64_dvd_9327751.iso
Set-VMFirmware -VMName $VMName -EnableSecureBoot Off -BootOrder (Get-VMDvdDrive -VMName $VMName), (Get-VMHardDiskDrive -VMName $VMName)
#AD仮想マシンの起動
Start-VM -VMName $VMName

GUI接続する頃にはDVDブートを通り過ぎているので一回リセットしてエンターキーを連打!

(GUIでポチポチしてる方が慣れてて早いので)インストールの自動化は後回し。いつか気が向いたら書きます。

起動してきたらサインインして、設定の続き。
ここから先はADのゲストOSの中。

ゲストOS(AD1)の設定

#ネットワーク設定
$NIC = Get-NetAdapter
New-NetIPAddress -IPAddress "10.10.107.1" -AddressFamily IPv4 -PrefixLength 22 -InterfaceAlias $NIC.name -DefaultGateway "10.10.104.1"
Set-DnsClientServerAddress -InterfaceAlias $NIC.name -ServerAddresses "8.8.8.8"
$NIC | Rename-NetAdapter -newname "MGMT"

#リモートデスクトップ有効化
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server" -Name "fDenyTSConnections" -Value "0"
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" -Name "UserAuthentication" -Value "0"

#ファイアウォール無効
Set-NetFirewallProfile -Enabled false

#コンピュータ名変更
Rename-Computer -NewName "AD1"
Restart-Computer -Force

♯ここで一回目の再起動。VMだからすぐあがってくる。

#役割のインストール
Install-WindowsFeature -Name AD-Domain-Services, DNS -IncludeManagementTools -IncludeAllSubFeature
♯ここは再起動不要

Install-ADDSForest -DomainName "hogehoge" -InstallDns -CreateDnsDelegation -Force

親パーティション(Hyper-Vホスト)1をドメインに参加させる。

DNSサーバーをさっき作ったADDSに向ける
Get-NetAdapter -Name "vEthernet (MGMT)"| Set-DnsClientServerAddress  -ServerAddresses "10.10.107.1", "10.10.107.2" #2はまだないけどこの次に作るので先に入れておく
#パスワードはスクリプトに埋め込みたくないので手打ち
Add-Computer -DomainName datacore.local -Credential (Get-Credential) -Restart

起動してきたらドメインユーザーでサインインしてみる。サインインできたら1台目完了。

冗長だけどほぼメモなので次は2台目。

ホストの準備とHyper-Vの設定

$DisksizeGB = 100
$Cdrive = Get-Partition -DriveLetter "C"
$newCdrivesize =  $Cdrive.size - ($DisksizeGB * 1024 * 1024 * 1024)
Resize-Partition -DriveLetter C -Size $newCdrivesize
Get-Partition -DriveLetter C|Get-Disk|New-Partition -UseMaximumSize -DriveLetter D |Format-Volume -FileSystem NTFS -NewFileSystemLabel "AD2"

Set-VMHost -ComputerName (hostname) -VirtualHardDiskPath "D:\VHD" -VirtualMachinePath "D:\" -EnableEnhancedSessionMode $true
New-VMSwitch -Name MGMT -NetAdapterName MGMT -AllowManagementOS $true 

仮想マシンの作成と起動

$VMName = "AD2"
New-VM -Name $VMName -Generation 2 -MemoryStartupBytes 4096MB -SwitchName MGMT -NewVHDPath ($VMName + ".VHDX") -NewVHDSizeBytes 100GB
Set-VM -VMname $VMName -StaticMemory -ProcessorCount 2 -AutomaticStartAction Start -AutomaticStopAction ShutDown
Add-VMDvdDrive -VMName $VMName -Path C:\ISO\en_windows_server_2016_x64_dvd_9327751.iso
Set-VMFirmware -VMName $VMName -EnableSecureBoot Off -BootOrder (Get-VMDvdDrive -VMName $VMName), (Get-VMHardDiskDrive -VMName $VMName)
#AD仮想マシンの起動
Start-VM -VMName $VMName

ゲストOS(AD2)の設定

#ネットワーク設定
$NIC = Get-NetAdapter
New-NetIPAddress -IPAddress "10.10.107.2" -AddressFamily IPv4 -PrefixLength 22 -InterfaceAlias $NIC.name -DefaultGateway "10.10.104.1"
Set-DnsClientServerAddress -InterfaceAlias $NIC.name -ServerAddresses "8.8.8.8"
$NIC | Rename-NetAdapter -newname "MGMT"

#リモートデスクトップ有効化
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server" -Name "fDenyTSConnections" -Value "0"
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" -Name "UserAuthentication" -Value "0"

#ファイアウォール無効
Set-NetFirewallProfile -Enabled false

#コンピュータ名変更
Rename-Computer -NewName "AD2"
Restart-Computer -Force

♯ここで一回目の再起動。VMだからすぐあがってくる。

#役割のインストール
Install-WindowsFeature -Name AD-Domain-Services, DNS -IncludeManagementTools -IncludeAllSubFeature
♯ここは再起動不要

#2台目はDNSを1台目に向ける
Get-NetAdapter | Set-DnsClientServerAddress  -ServerAddresses "10.10.107.1"

Install-AddsDomainController -DomainName hogehoge -Credential (Get-Credential) -Force
#勝手に再起動します。

親パーティション(Hyper-Vホスト)2をドメインに参加させる。

DNSサーバーをさっき作ったADDSに向ける
Get-NetAdapter -Name "vEthernet (MGMT)"| Set-DnsClientServerAddress  -ServerAddresses "10.10.107.1", "10.10.107.2"
#パスワードはスクリプトに埋め込みたくないので手打ち
Add-Computer -DomainName datacore.local -Credential (Get-Credential) -Restart

あとはWSFCを組むだけ。

以上

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2