Powershell DSC 5.0 - Pull 模式 (HTTPS)

简介:

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


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

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


wKiom1YDl__Ql2PKAALSdY0MGS0241.jpg


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

wKioL1YDmAKhkismAADdnb8dkx4361.jpg

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

注意证书指纹的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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的配置文件

wKiom1YDmACDc9KIAAD5dyBW0vY293.jpg


推送到指定的HTTPS服务器上

wKioL1YDmAOiKWUmAANfMfVFGlA011.jpg


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

wKiom1YDmAHihqrQAABYzziYClw254.jpg

可以看见已经成功配置了

wKiom1YDmALyzvcQAALqKcaZMOs257.jpg


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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[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文件

wKioL1YDmAWgwblbAACkKo_tBn8476.jpg

推送给节点

wKiom1YDmAPRXtSzAALwKTJAypo785.jpg


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

1
2
3
4
5
6
7
8
9
configuration SMTP {
     Node HTTPSComputers {
         WindowsFeature SMTP{
             Name =  'SMTP-Server'
             Ensure =  'Absent'
         }
     }
}
SMTP -OutputPath C:\DSC\HTTPS

生成mof文件

wKioL1YDmAehbPpOAAEu7qm_cDY125.jpg


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

wKiom1YDmAWz3hPuAAF35kBr-G0481.jpg


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

wKioL1YDmAjwGOsaAAC-NdumuNI037.jpg


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


wKiom1YDmAfDw8a2AAZ6UCvLuRk374.jpg


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

wKioL1YDmAryu3olAACp3taPY2o094.jpg


实验成功。










本文转自 beanxyz 51CTO博客,原文链接:http://blog.51cto.com/beanxyz/1697842,如需转载请自行联系原作者

目录
相关文章
|
Linux Docker Windows
docker pull 报错解决:error pulling image configuration: Get https:..
docker pull 报错解决:error pulling image configuration: Get https:..
4005 0
|
6月前
|
监控 小程序 前端开发
基础入门-抓包技术&HTTPS协议&WEB&封包监听&网卡模式&APP&小程序
基础入门-抓包技术&HTTPS协议&WEB&封包监听&网卡模式&APP&小程序
193 0
|
网络协议 C++ Docker
Docker pull拉取镜像报错“Error response from daemon: Get "https://registry-1.docker.io/v2”解决办法
Docker pull拉取镜像报错“Error response from daemon: Get "https://registry-1.docker.io/v2”解决办法
29764 1
|
Linux API C语言
由浅入深C系列五:使用libcurl进行基于http get/post模式的C语言交互应用开发
由浅入深C系列五:使用libcurl进行基于http get/post模式的C语言交互应用开发
|
数据采集 大数据 测试技术
代理http服务商一般都有哪些收费模式?哪种划算?
IP代理服务商提供了一个方便的解决方案,允许用户轻松地在不同的地理位置上模拟互联网访问。
代理http服务商一般都有哪些收费模式?哪种划算?
|
JavaScript 算法 前端开发
vue本地开启https访问模式
vue本地开启https访问模式
8937 0
|
Docker 容器
docker pull 报错:Get https://registry:5000/v1/_ping: http: server gave HTTP response to HTTPS client
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34173549/article/details/80415283    ...
5079 0
|
Go
Go 自带的 http/server.go 的连接解析 与 如何结合 master-worker 并发模式,提高单机并发能力
作者:林冠宏 / 指尖下的幽灵 掘金:https://juejin.im/user/587f0dfe128fe100570ce2d8 博客:http://www.cnblogs.com/linguanh/ GitHub : https://github.com/af913337456/ 腾讯云专栏: https://cloud.tencent.com/developer/user/1148436/activities 关于 server.go 源码的解析可以去搜下,已经有很多且还不错的文章。
1644 0
|
监控 负载均衡 测试技术