はじめに
- 検証でADサーバーを作成する必要があり、どうせならWindows Server 2016で実施してみようと思った。
- 何度か作り直す可能性があったため、2012R2と同様の手順でVagrantのBase Boxが作成できるか試してみた。
- Boxを作成するのに参考にしたサイト -> Windows Server 2012R2 の Vagrant Base Boxを作る
実施環境
- MacOS Sierra 10.12.2
- Vagrant 1.9.1
- VirtualBox 5.1.12 r112440
VagrantBoxの作り方を確認する
- Vagrantの公式ページにて、VirtualBoxのBoxeの作成方法を確認する
- Windowsを作成する際に以下の設定を実施する必要がある
- 「vagrant」ユーザを作成し、パスワードを「vagrant」に変更
- UACを無効
- 「複雑さの要件を満たす必要があるパスワード」を無効に変更
- シャットダウンイベントの追跡ツールを無効
- サーバーマネージャーがログオン時に表示されないように変更
- 「vagrant」ユーザを管理者グループに追加
- リモートデスクトップの有効化
- WinRMを有効化する
- VirtualBox Guest Additionのインストール
VirtualBoxでWindowsServer2016のBaseBoxを作成する
■ WindowsServer2016をダウンロードする
■ VirtualBoxマネージャーより仮想マシンを作成する
VirtualBoxを起動し、[新規]を選択し、名前を次のように入力する ※ タイプはWindows Server 2016がないので[Other Windows]を選択
構築時にコピペが利用できるように[一般]->[高度]より「クリップボードの共有」「ドラッグ&ドロップ」を双方向に変更する
■ WindowsServer2016のインスール
■ VirtualBox Guest Additionのインストール
- VirtualBoxのメニューから[Devices]->[Insert Guest Additions CD Image...] を選択し、インストーラがマウントされたことを確認する
■ 「複雑さの要件を満たす必要があるパスワード」を無効に変更
■ Administratorのパスワードを変更する
■ 「vagrant」ユーザを作成し、パスワードを「vagrant」に変更
■ UAC(User Account Control)を無効
■ シャットダウンイベントの追跡ツールを無効
[ローカルグループポリシーエディター]が表示されたら、[ローカルコンピュータポリシー]->[コンピュータの構成]->[管理用テンプレート]->[システム]をクリックし、「シャットダウンイベントの追跡ツールを表示する」を選択する
■ サーバーマネージャーがログオン時に表示されないように変更
- 上記と同様に「ローカルグループポリシーエディタ」を開き、[ローカルコンピュータポリシー]->[コンピュータの構成]->[管理用テンプレート]->[システム]->[サーバーマネージャー]をクリックし、「ログオン時にサーバーマネージャーを自動的に表示しない」を選択する
- 「ログオン時にサーバーマネージャーを自動的に表示しない」を[有効]に変更し、[OK]を選択する
■ WinRMを有効化する
- PowerShellを起動し、以下のコマンドを実行する
winrm quickconfig -q
winrm set winrm/config '@{MaxTimeoutms="1800000"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
sc.exe config WinRM start= auto
■ リモートデスクトップの有効化
すべての設定が完了したので、シャットダウンを実行する
VagratBoxを作成する
■ VagrantBox内に同梱するVagrantfileを作成する
- Vagrant Base Box 用のディレクトリを作成する
% mkdir Win2016; cd Win2016
% vim Vagrantfile
- vagrantfileを以下のように記述する
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.guest = :windows
config.vm.communicator = "winrm"
if Vagrant.has_plugin?("vagrant-vbguest")
config.vbguest.auto_update = false
end
config.vm.network :forwarded_port, guest: 3389, host: 13389
config.vm.network :forwarded_port, guest: 5985, host: 15985,id: "winrm", auto_correct: true
end
■ BaseBoxのパッケージング化
- 手動で作成したVMを以下のコマンドでパッケージングし、boxに追加する
% vagrant package --base "Windows Server 2016" --vagrantfile Vagrantfile
==> Windows Server 2016: Exporting VM...
==> Windows Server 2016: Compressing package to: /Users/daicho/work/Win2016/package.box
==> Windows Server 2016: Packaging additional file: Vagrantfile
% ls -g
total 10201320
-rw-r--r-- 1 staff 388 1 16 01:46 Vagrantfile
-rw-r--r-- 1 staff 5223071392 1 17 01:01 package.box
% mv package.box WindowsServer2016.box
% vagrant box add --name WindowsServer2016 WindowsServer2016.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'WindowsServer2016' (v0) for provider:
box: Unpacking necessary files from: file:///Users/daicho/work/Win2016/WindowsServer2016.box
==> box: Successfully added box 'WindowsServer2016' (v0) for 'virtualbox'!
% vagrant box list
WindowsServer2016 (virtualbox, 0)
■ 作成したVagrntBoxからサーバーを作成してみる
% mkdir /tmp/TestWin2016; cd /tmp/TestWin2016
% vagrant init WindowsServer2016
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
% vagrant up --provider virtualbox
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'WindowsServer2016'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: TestWin2016_default_1484583347099_36076
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 3389 (guest) => 13389 (host) (adapter 1)
default: 5985 (guest) => 15985 (host) (adapter 1)
default: 5986 (guest) => 55986 (host) (adapter 1)
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: WinRM address: 127.0.0.1:15985
default: WinRM username: vagrant
default: WinRM execution_time_limit: PT2H
default: WinRM transport: negotiate
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
default: /vagrant => /private/tmp/TestWin2016
% vagrant rdp
==> default: Detecting RDP info...
default: Address: 127.0.0.1:13389
default: Username: vagrant
==> default: Vagrant will now launch your RDP client with the connection parameters
==> default: above. If the connection fails, verify that the information above is
==> default: correct. Additionally, make sure the RDP server is configured and
==> default: running in the guest machine (it is disabled by default on Windows).
==> default: Also, verify that the firewall is open to allow RDP connections.
参考ページ
まとめ
- WindowsServer2012R2と同じ手順でWindowsServer2016のVagrantのBaseBoxが作成できることが確認できた
- これでWindowsServer2016の検証が容易にできるようになったが、手動で作成するのはかっこよくないので、そのうちPackerで作成する手順を記載する