[8] Window PowerShell DSC 学习系列----MOF文件和DSC Module的部署
2017-01-29 00:50
549 查看
在前面的第7节,笔者分享了如何安装Pull服务器,如何生成MOF文件。那么生成了MOF文件之后,如何在Pull服务器上部署?另外如果MOF文件中又引用了其他的DSC Module或者DSC Resource,那么应该如何把这些额外的DSC module或者Resouce部署呢?因为DSC 4.x和5.x 部署方式不一样,因此,笔者就以DSC 5.x的部署方式为例子。
Window PowerShell DSC 学习系列----如何被管理的设置节点注册到Pull Server?文章中第4步提到的,客户端目标节点的ConfigurationID拷贝出来,6ed1afc8-d03c-4c35-b2a8-b3d712899a02,然后把生成的其中6ed1afc8-d03c-4c35-b2a8-b3d712899a02对应的目标机器名的MOF文件改名成6ed1afc8-d03c-4c35-b2a8-b3d712899a02.mof.
[DSCLocalConfigurationManager()]
configuration PullClientConfigNames
{
Node localhost
{
Settings
{
RefreshMode = 'Pull'
RefreshFrequencyMins = 30
RebootNodeIfNeeded = $true
ConfigurationID='6ed1afc8-d03c-4c35-b2a8-b3d712899a02'
}
ConfigurationRepositoryWeb pserver51w2k12.example.com
{
ServerURL = 'https://pserver51w2k12.example.com:8080/PSDSCPullServer.svc'
RegistrationKey = '589303f2-482e-478e-97cb-b1a278f07458'
}
ReportServerWeb pserver51w2k12.example.com
{
ServerURL = 'https://pserver51w2k12.example.com:8080/PSDSCPullServer.svc'
RegistrationKey = '589303f2-482e-478e-97cb-b1a278f07458'
}
}
}
PullClientConfigNames
然后把改名的6ed1afc8-d03c-4c35-b2a8-b3d712899a02.mof文件考本到C:\Program Files\WindowsPowerShell\DscService\Configuration目录下,并执行下面的命令
New-DscChecksum -ConfigurationPath "C:\Program Files\WindowsPowerShell\DscService\Configuration"
生成6ed1afc8-d03c-4c35-b2a8-b3d712899a02.mof的checksum文件:6ed1afc8-d03c-4c35-b2a8-b3d712899a02.mof.checksum
那么这个mof.checksum的文件有两个作用,第一个防止6ed1afc8-d03c-4c35-b2a8-b3d712899a02.mof在被传输到目标节点的过程中被修改;第二个作用是如果mof文件发生变化,则相应的mof.checksum的文件也要发生变化;这个时候,客户端轮询的时候,能改发现Pull服务器上的MOF文件发生变化,从而重新申下载并执行新的MOF文件。至此,MOF文件在Pull服务器上的部署就完成了。
从上面这个配置文件,我们知道,其引用了xChrome这个扩展的,非内置的DSC Module;而xChrome本身有引用PowerShell DSC xPSDesiredStateConfiguration这个额外的,非内置的PowerShell DSC Module;那么这个时候,我们应该如何部署这个Module呢?咱们还是以最新的DSC 5.x为例子;因为 DSC 5.x中,被引用的Module已经能够区分版本了;具体方式如下:
xPSDesiredStateConfiguration的处理类似。
比如:xChrome_1.1.0.0.zip和xChrome_1.1.0.0.zip
执行完成后,其画面如下:
恭喜你!!! MOF文件和DSC Module在Pull服务器上已经部署成功!!!
#1 如何在Pull服务器上部署MOF文件
咱们在[5] Window PowerShell 学习系列----如何生成一个DSC MOF文件?这篇文章中,提到了如何把一个安装Chrome浏览器的DSC配置文件,生成一个MOF文件。生成MOF文件后,下一步就是把[7]Window PowerShell DSC 学习系列----如何被管理的设置节点注册到Pull Server?文章中第4步提到的,客户端目标节点的ConfigurationID拷贝出来,6ed1afc8-d03c-4c35-b2a8-b3d712899a02,然后把生成的其中6ed1afc8-d03c-4c35-b2a8-b3d712899a02对应的目标机器名的MOF文件改名成6ed1afc8-d03c-4c35-b2a8-b3d712899a02.mof.
[DSCLocalConfigurationManager()]
configuration PullClientConfigNames
{
Node localhost
{
Settings
{
RefreshMode = 'Pull'
RefreshFrequencyMins = 30
RebootNodeIfNeeded = $true
ConfigurationID='6ed1afc8-d03c-4c35-b2a8-b3d712899a02'
}
ConfigurationRepositoryWeb pserver51w2k12.example.com
{
ServerURL = 'https://pserver51w2k12.example.com:8080/PSDSCPullServer.svc'
RegistrationKey = '589303f2-482e-478e-97cb-b1a278f07458'
}
ReportServerWeb pserver51w2k12.example.com
{
ServerURL = 'https://pserver51w2k12.example.com:8080/PSDSCPullServer.svc'
RegistrationKey = '589303f2-482e-478e-97cb-b1a278f07458'
}
}
}
PullClientConfigNames
然后把改名的6ed1afc8-d03c-4c35-b2a8-b3d712899a02.mof文件考本到C:\Program Files\WindowsPowerShell\DscService\Configuration目录下,并执行下面的命令
New-DscChecksum -ConfigurationPath "C:\Program Files\WindowsPowerShell\DscService\Configuration"
生成6ed1afc8-d03c-4c35-b2a8-b3d712899a02.mof的checksum文件:6ed1afc8-d03c-4c35-b2a8-b3d712899a02.mof.checksum
那么这个mof.checksum的文件有两个作用,第一个防止6ed1afc8-d03c-4c35-b2a8-b3d712899a02.mof在被传输到目标节点的过程中被修改;第二个作用是如果mof文件发生变化,则相应的mof.checksum的文件也要发生变化;这个时候,客户端轮询的时候,能改发现Pull服务器上的MOF文件发生变化,从而重新申下载并执行新的MOF文件。至此,MOF文件在Pull服务器上的部署就完成了。
#2 如何在Pull服务器上部署DSC Module
在[5] Window PowerShell 学习系列----如何生成一个DSC MOF文件?这篇文章中,在客户端安装Chrome软件的DSC的配置文件如下Configuration InstallGoogleChrome { param ( [string[]]$MachineName = "localhost", [Parameter(Mandatory)]$Language, [Parameter(Mandatory)]$LocalPath ) Import-DscResource -Module xChrome Node $MachineName { MSFT_xChrome chrome { Language = $Language LocalPath = $LocalPath } } } InstallGoogleChrome -MachineName (Get-Content -Path "c:\dsc\servers.txt") -Language "en" –LocalPath "C:\Windows\Temp\GoogleChromeStandaloneEnterprise.msi"
从上面这个配置文件,我们知道,其引用了xChrome这个扩展的,非内置的DSC Module;而xChrome本身有引用PowerShell DSC xPSDesiredStateConfiguration这个额外的,非内置的PowerShell DSC Module;那么这个时候,我们应该如何部署这个Module呢?咱们还是以最新的DSC 5.x为例子;因为 DSC 5.x中,被引用的Module已经能够区分版本了;具体方式如下:
第1步
把C:\Program Files\WindowsPowerShell\Modules\xChrome和C:\Program Files\WindowsPowerShell\Modules\xPSDesiredStateConfiguration这两个目录拷贝到一个文件夹下,比如c:\dsc\module第2步
以C:\DSC\Module\xChrome\文件夹为例子,其包含一个自文件夹C:\DSC\Module\xChrome\1.1.0.0,把C:\DSC\Module\xChrome\1.1.0.0文件夹下所有的子文件已经子文件夹剪切到C:\DSC\Module\xChrome目录下,并删除C:\DSC\Module\xChrome\1.1.0.0文件夹;xPSDesiredStateConfiguration的处理类似。
第3步
进入到C:\DSC\Module\xChrome文件夹,并用zip工具压缩成一个包含<module_name>_<module_version>.zip的文件;比如:xChrome_1.1.0.0.zip和xChrome_1.1.0.0.zip
第4步
把xChrome_1.1.0.0.zip和xChrome_1.1.0.0.zip两个zip文件拷贝到C:\Program Files\WindowsPowerShell\DscService\Modules目录第5步
执行下面的命令,对每一个的module的zip文件生成新的checksum的文件New-DscChecksum -ConfigurationPath "C:\Program Files\WindowsPowerShell\DscService\Modules"
执行完成后,其画面如下:
恭喜你!!! MOF文件和DSC Module在Pull服务器上已经部署成功!!!
相关文章推荐
- [5] Window PowerShell DSC 学习系列----如何生成一个DSC MOF文件?
- [3] Window PowerShell DSC 学习系列----如何在PowerShell DSC 5.x 安装最新的DSC Module?
- [4] Window PowerShell DSC 学习系列----PowerShell DSC 5.x 提供了哪些有用好用的工具命令?
- [9] Window PowerShell DSC 学习系列----错误诊断和分析
- [32] Window PowerShell DSC 学习系列----使用DSC Package安装时,如何获取Product ID?
- [27] Window PowerShell DSC 学习系列----DSC 5.x 查询节点注册和执行报告(Report)查询
- [29] Window PowerShell DSC 学习系列----如何备份数据库和解决一个MS Server 2008上的大坑?
- [7] Window PowerShell DSC 学习系列----如何被管理的设置节点注册到Pull Server?
- [24]Window PowerShell DSC学习系列---- 如何保护MOF文件里面存储的密码?
- [2] Window PowerShell DSC 学习系列----DSC的资源(Resource)以及配置和格式(Configuration && Sytax )
- [10] Window PowerShell DSC 学习系列----目标节点和Pull 服务器底层通信原理剖析
- [22]Window PowerShell DSC学习系列---- 如何用PowerShell脚本查看DSC服务器的执行报表(Report)
- [23]Window PowerShell DSC学习系列---- MOF文件能存储用户的密码吗?
- [30] Window PowerShell DSC 学习系列----如何解决跨节点(across computers)依赖?
- [28] Window PowerShell DSC 学习系列----如何用Java调用PowerShell DSC 5.x的oData服务
- [31] Window PowerShell DSC 学习系列----PowerShell DSC 专栏竟然在CSDN推荐的优秀专栏里面
- [6] Window PowerShell DSC 学习系列----如何安装最新的PowerShell DSC 5.1 Pull Server?
- [1] Window PowerShell DSC 学习系列----DSC的定义和2种架构模式
- [21]Window PowerShell DSC学习系列---- 在Window 2012 R2 安装DSC 5.0 Pull服务器报错的解决方案
- [14]Windows PowerShell DSC学习系列---如何Debug PowerShell DSC?