首页 > Web开发 > 详细

Powershell DSC 5.0 - Pull 模式 (HTTPS)

时间:2015-09-24 19:35:42      阅读:273      评论:0      收藏:0      [点我收藏+]

Powershell DSC 的Pull模式除了SMB以外,还可以使用HTTP或者HTTPS。这两个配置几乎一样,Https需要多配置一个证书。基本流程是配置pull server,配置节点的LCM,配置需要实现的状态,然后推送测试。


首先,我们需要一个web server的证书。我已经有PKI在域里了,因此从IIS生成一个证书非常容易。

具体步骤参考: http://beanxyz.blog.51cto.com/5570417/1331453


技术分享


生成证书,绑定IIS之后,我需要获取该证书的指纹以便写入配置文件

技术分享

和SMB一样,我需要下载导入模块

注意证书指纹的配置

configuration HTTPSPullServer
{
    # Modules must exist on target pull server
    Import-DSCResource -ModuleName xPSDesiredStateConfiguration
    Node sydit01
    {
        WindowsFeature DSCServiceFeature
        {
            Ensure = "Present"
            Name   = "DSC-Service"
        }
        WindowsFeature IISConsole {
            Ensure = "Present"
            Name   = "Web-Mgmt-Console"
        }
        xDscWebService PSDSCPullServer
        {
            Ensure                  = "Present"
            EndpointName            = "PSDSCPullServer"
            Port                    = 8080
            PhysicalPath            = "$env:SystemDrive\inetpub\wwwroot\PSDSCPullServer"
            CertificateThumbPrint   = ‘56B5DC192DE9AB004AE6FB3C96F7C00684537028‘
            ModulePath              = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Modules"
            ConfigurationPath       = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration"
            State                   = "Started"
            DependsOn               = "[WindowsFeature]DSCServiceFeature"
        }
        xDscWebService PSDSCComplianceServer
        {
            Ensure                  = "Present"
            EndpointName            = "PSDSCComplianceServer"
            Port                    = 9080
            PhysicalPath            = "$env:SystemDrive\inetpub\wwwroot\PSDSCComplianceServer"
            CertificateThumbPrint   = "AllowUnencryptedTraffic"
            State                   = "Started"
            IsComplianceServer      = $true
            DependsOn               = ("[WindowsFeature]DSCServiceFeature","[xDSCWebService]PSDSCPullServer")
        }
    }
}
# Generate MOF
HTTPSPullServer -OutputPath C:\DSC\HTTPS


生成Pull Server的配置文件

技术分享


推送到指定的HTTPS服务器上

技术分享


推送之后,需要测试一下是否成功

技术分享

可以看见已经成功配置了

技术分享


接下来需要配置节点的LCM文件

[DSCLocalConfigurationManager()]
Configuration LCM_HTTPSPULL 
{
    param
        (
            [Parameter(Mandatory=$true)]
            [string[]]$ComputerName,
            [Parameter(Mandatory=$true)]
            [string]$guid
        )      
Node $ComputerName {
Settings {
AllowModuleOverwrite = $True
            ConfigurationMode = ‘ApplyAndAutoCorrect‘
RefreshMode = ‘Pull‘
ConfigurationID = $guid
            }
            ConfigurationRepositoryWeb DSCHTTPS {
       
                ServerURL = ‘https://sydit01.omnicom.com.au:8080/PSDSCPullServer.svc‘
                CertificateID = ‘56B5DC192DE9AB004AE6FB3C96F7C00684537028‘
                AllowUnsecureConnection = $False
            }
}
}
# Computer list 
$ComputerName=‘sydittest‘
# Create Guid for the computers
$guid=[guid]::NewGuid()
# Create the Computer.Meta.Mof in folder
LCM_HTTPSPULL -ComputerName $ComputerName -Guid $guid -OutputPath c:\DSC\HTTPS

生成LCM的meta.mof文件

技术分享

推送给节点

技术分享


接下来,配置我们需要实现的状态,这里的例子是确保SMTP服务始终不会安装。

configuration SMTP {
    Node HTTPSComputers {
        WindowsFeature SMTP{
            Name = ‘SMTP-Server‘
            Ensure = ‘Absent‘
        }
    }
}
SMTP -OutputPath C:\DSC\HTTPS

生成mof文件

技术分享


和SMB一样,HTTPS Pull Server 也是使用GUID和checksum来校验的,因此需要改名字,生成配置文件的校验码

技术分享


最后来测试一下,首先看看客户端(节点)已经安装了SMTP

技术分享


更新一下状态,发现他开始自动卸载


技术分享


再查看一下,已经成功协助(提示需要重启)

技术分享


实验成功。

本文出自 “麻婆豆腐” 博客,请务必保留此出处http://beanxyz.blog.51cto.com/5570417/1697842

Powershell DSC 5.0 - Pull 模式 (HTTPS)

原文:http://beanxyz.blog.51cto.com/5570417/1697842

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!