我们知道,PowerShell DSC的默认数据库为ESENT文件数据库;或者oleDB形式的Access数据库(数据库文件后缀名为:mdb).
默认安装方式下,如果用xDscWebService DSC资源安装Pull服务器的话,其默认方式是ESENT文件数据库的方式;那么如何把Pull服务器的存储数据库改成Access数据库呢?答案其实很简单,只需要修改MSFT_xDSCWebService.psm1文件。
具体步骤方法如下:
@首先,在Pull服务器的安装目录下找到,MSFT_xDSCWebService.psm1这个文件,比如,笔者当前的环境是PowerShell DSC 5.1; 其xPSDesiredStateConfiguration DSC模块的的文件目录在C:\Program Files\WindowsPowerShell\Modules\xPSDesiredStateConfiguration\5.1.0.0\DSCResources\MSFT_xDSCWebService
找到MSFT_xDSCWebService.psm1文件,然后用PowerShell ISE打开。
@ 然后,在function Set-TargetResource方法中,找到为变量$isDownlevelOfBlue,$IsBlue赋值的地方,然后插入下面的代码。
@ 安装Pull服务的脚本还是不变,具体如下:
#New-SelfSignedCertificate -certstorelocation cert:\localmachine\my -dnsname sql-pull-server.example.com
configuration InstallxDsc5PullServer
{
param
(
[string[]]$NodeName = 'localhost',
[ValidateNotNullOrEmpty()]
[string] $certificateThumbPrint,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $RegistrationKey
)
Import-DSCResource -ModuleName xPSDesiredStateConfiguration
Import-DSCResource –ModuleName PSDesiredStateConfiguration
Node $NodeName
{
WindowsFeature DSCServiceFeature
{
Ensure = 'Present'
Name = 'DSC-Service'
}
xDscWebService PSDSCPullServer
{
Ensure = 'Present'
EndpointName = 'PSDSCPullServer'
Port = 8080
PhysicalPath = "$env:SystemDrive\inetpub\PSDSCPullServer"
CertificateThumbPrint = $certificateThumbPrint
ModulePath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Modules"
ConfigurationPath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration"
State = 'Started'
DependsOn = '[WindowsFeature]DSCServiceFeature'
UseSecurityBestPractices = $false
}
File RegistrationKeyFile
{
Ensure = 'Present'
Type = 'File'
DestinationPath = "$env:ProgramFiles\WindowsPowerShell\DscService\RegistrationKeys.txt"
Contents = $RegistrationKey
}
}
}
InstallxDsc5PullServer -certificateThumbprint 'DEBD244CA738E89177E00685B53BD1C02BB9EB72' -RegistrationKey '589303f2-482e-478e-97cb-b1a278f07458' -OutputPath c:\DSC\PullServer
Start-DscConfiguration -Force -Path c:\DSC\PullServer -Wait -Verbose
上面的脚本执行完成之后,我们到Access数据库的安装目录下C:\Program Files\WindowsPowerShell\DscService 发现,其Pull服务器的数据已经换成了Access数据库。
打开数据,我们可以看到总共有三张表:Devices,Registration和StatusReport表,看来Pull服务器的实现还是蛮简单的啊。
在这个章节我之所以分享如何替换Pull服务器的数据库为Access是为后一章节服务器的;因为不管是ESEIN文件数据库也好;还是Acces数据也好;其性能,可管理性已经其数据库的容量都是非常有限的。但是DSC的官方对MS SQL Server默认是不支持的,那么有没有什么的好的办法让其也支持MS SQL Server?敬请期待下篇文章。