Virtual Machine Manager 2012 R2利用服务模板部署DC

本文介绍如何使用虚拟机管理器(VMM)服务模板自动化部署DC服务器。从创建配置脚本开始,逐步指导如何构建和应用服务模板,实现快速高效地创建活动目录服务器。

服务模板作为VMM非常重要的一个功能,无论是在日常的应用虚机创建,还是在私有云中的自助申请,我们都需要先创建好各种的服务模板,管理员或者根据工作流再通过这些服务模板来完成我们对各种应用的自动化部署,所以服务模板都是一个关键所在,利用好服务模板,也是私有云迈出的第一步。下面就以全自动创建一台DC服务器为例,继续对服务模板进行介绍。

1、首先将下面脚本保存为PS文件,这个脚本将会对DC执行相应的配置。

$ScriptName = $MyInvocation.MyCommand.Name

if (($args.Count -le 1) -or ($args.Count -ge 4))

{

$Instructions = @"

usage: $ScriptName <Local Admin Password> <Domain Name> [Data Drive]

This script creates an Active Directory server

Required Paramaters:

<Local Admin Password>:

This is the same password used in the template configuration for local administrator.

<Domain Name>:

The domain used to create Active Directory and DNS trees.

Optional Parameters:

[Data Drive]

Optionally, the data drive for storing database, SYSVOL and log files can be entered.

"@

$EventLog = New-Object System.Diagnostics.EventLog('Application')

$EventLog.MachineName = "."

$EventLog.Source = "$ScriptName"

$EventLog.WriteEntry("Script did not complete. $Instructions","Error", "1000")

exit

}

$pass = $args[0]

$domain = $args[1]

$driveLetter = $args[2]

$dataDrive = ""

$driveLetter = "C"

try{

# ToDo: Here we simply test if the drive letter entered as a param is actually a drive. This

# should be more agressive testing for writable and available free space using Get-PSDrive.

# Again for fast deploys we have control over we know attached drives and size but we

# are confirming here it exist and falling back if something went wrong attaching it.

if((New-Object System.IO.DriveInfo($driveLetter)).DriveType -ne 'NoRootDirectory')

{

$dataDrive = $driveLetter + ":\Windows\"

}

else

{

$dataDrive = "c:\Windows\"

}

$databasePath = $dataDrive + "NTDS"

$sysvolPath = $dataDrive + "SYSVOL"

Import-Module ADDSDeployment

$result = Install-ADDSForest `

-CreateDNSDelegation:$false `

-safemodeadministratorpassword (convertto-securestring $pass -asplaintext -force) `

-DatabasePath $databasePath `

-DomainMode "Win2012" `

-DomainName $domain `

-ForestMode "Win2012" `

-InstallDNS:$true `

-LogPath $databasePath `

-NoRebootOnCompletion:$false `

-SYSVOLPath $sysvolPath `

-force:$true

# Writing an event log entry

$EventLog = New-Object System.Diagnostics.EventLog('Application')

$EventLog.MachineName = "."

$EventLog.Source = "$ScriptName"

$EventLog.WriteEntry("$result","Information", "1000")

}catch [Exception]{

$EventLog = New-Object System.Diagnostics.EventLog('Application')

$EventLog.MachineName = "."

$EventLog.Source = "$ScriptName"

$EventLog.WriteEntry("Script failed. The error message: $_.Exception.Message","Error", "1000")

throw "$ScriptName failed to complete. $_.Exception.Message "

}

2、把脚本保存到库中

clip_image002

3、打开VMM控制台,选择库,配置文件选项中选择应用程序配置文件,然后右键创建应用程序配置文件。

clip_image004

4、在新建应用程序窗口中,填写名称。

clip_image006

5、切换到应用程序设置,添加一个脚本类型为安装前的脚本,如下图,在可执行程序栏填入Powershell的路径,参数填写如下:

-noprofile Set-ExecutionPolicy RemoteSigned

clip_image008

6、继续添加一个类型为安装前的脚本,脚本资源包选择刚才保存的PS脚本,并如下图进行配置,这里需要把超时修改为360秒,否则执行会失败。

clip_image010

7、接下来在服务模板选项,选择创建服务模板

clip_image012

8、创建一个单一计算机服务模板。

clip_image013

9、把一个VM模板拖入到画布中,如下图。

clip_image015

10、右键画布中的计算机层,属性,在OS配置中添加相应的DC服务和功能

clip_image017

11、打开应用程序配置选项,在应用配置文件下拉选择刚才配置好的应用程序配置文件。

clip_image019

12、完成后保存,并配置部署。

clip_image021

13、为新服务实例进行配置,如下图。

clip_image022

14、填入相关域信息,进行部署服务。

clip_image024

15、如果在APP Controller中进行服务部署的话,体验会更好点。

clip_image026

16、接下来就等待服务的运行完成了。这样,一台DC服务就完成创建了。

clip_image028

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值