• 9.PowerShell DSC之Pull


    前言

    一般生产环境都使用Pull模式
    image

    配置Pull Server

    配置Pull Server需要安装两个WindowsFeture:IIS、windows DSC,这两都可以通过UI界面化引导安装,也可以通过前面讲过的配置方式安装。

    安装好之后,需要在IIS上部署一个用于和各Node交互的服务,指定后续的配置存放位置、资源存放位置等信息,具体配置如下:

    configuration CreatePullServer
    {
    	param
    	(
    		[string[]]$ComputerName = 'localhost'
    	)
     
     
    Import-DSCResource -ModuleName xPSDesiredStateConfiguration
     
     
    Node $ComputerName
    {
    	WindowsFeature DSCServiceFeature
    	{
    		Ensure = "Present"
    		Name   = "DSC-Service"
    	}
     
    	xDscWebService PSDSCPullServer
    	{
    		Ensure = "Present"
    		EndpointName = "PSDSCPullServer" 
                	Port = 8080 
                	PhysicalPath = "$env:SystemDriveinetpubwwwrootPSDSCPullServer" 
                	CertificateThumbPrint = "AllowUnencryptedTraffic" 
                	ModulePath = "$env:PROGRAMFILESWindowsPowerShellDscServiceModules" 
                	ConfigurationPath = "$env:PROGRAMFILESWindowsPowerShellDscServiceConfiguration" 
                	State = "Started" 
                	DependsOn = "[WindowsFeature]DSCServiceFeature" 
            } 
        } 
    }
     
    CreatePullServer
    

    配置完之后,在IIS上会出现一个Site,可在浏览器访问,测试是否配置成功
    image

    配置各个Node

    各Node主要是LCM发挥作用,所以主要是配置LCM:

    [DSCLocalConfigurationManager()]
    configuration LCMConfig
    {
        Node localhost
        {
            Settings
            {
                RefreshMode = 'Pull'
                
                #方式1:通过ConfigurationID
                #注意:此方式RegistrationKey不是必须设置
                ConfigurationID = '1d545e3b-60c3-47a0-bf65-5afc05182fd0'
            }
        }
        
        #定义节点请求配置文件
        ConfigurationRepositoryWeb CONTOSO-PullSrv
        {
            ServerURL = 'https://CONTOSO-PullSrv:8080/PSDSCPullServer.svc'
            RegistrationKey = '140a952b-b9d6-406b-b416-e0f759c9c0e4'
            
             #方式2:通过ConfigurationNames
             #注意:此方式RegistrationKey必须要设置
            ConfigurationNames = @('ClientConfig')
        }
        
        #定义节点请求资源文件
        ConfigurationRepositoryWeb CONTOSO-PullSrv
        {
            ServerURL = 'https://CONTOSO-PullSrv:8080/PSDSCPullServer.svc'
            RegistrationKey = '140a952b-b9d6-406b-b416-e0f759c9c0e4'
        }
        
        #定义节点汇报执行情况给PullServer
        #PullServer默认会使用access数据库
        #数据库可以修改为SQLServer
        ReportServerWeb CONTOSO-PullSrv
        {
            ServerURL = 'https://CONTOSO-PullSrv:8080/PSDSCPullServer.svc'
            RegistrationKey = 'fbc6ef09-ad98-4aad-a062-92b0e0327562'
        }
    }
    

    生成mof文件(xxx.meta.mof)并应用即可

    Set-DSCLocalConfigurationManager –ComputerName localhost –Path 'mof floder' –Verbose.
    

    可以使用以下命令进行验证配置是否成功

    Get-DSCLocalConfigurationManager 
    

    发布配置到Pull Server

    以上服务器配置完成后,就需要进行交互工作了。我们根据业务写配置,编译,放到指定位置,等待Node到Pull Server上拉取,然后到Node中执行应用。

    指定的位置是哪里?
    上面我们配置Pull Server的时候,设置 ModulePath、ConfigurationPath,就分别是资源和配置要放置的地方。

    需要强调的是资源和配置,都需要为其生成checksum文件,这样Node每次来拉取如果发现文件的checksum无变化,则不拉取。

    所以配置文件夹下大概是这样的:

    a.mof
    a.mof.checksum
    b.mof
    b.mof.checksum
    ...
    

    资源文件夹下面大概是这样的:

    a_1.0.zip
    a_1.0.zip.checksum
    b_2.0.zip
    b_2.0.zip.checksum
    ...
    

    注意:资源文件命名必须要资源名称_版本号.zip

    参考

    Pull模式:https://www.red-gate.com/simple-talk/sysadmin/powershell/powershell-desired-state-configuration-pull-mode/

    Pull Server配置:https://docs.microsoft.com/en-us/powershell/dsc/pull-server/pullserver

    LCM配置:https://docs.microsoft.com/en-us/powershell/dsc/managing-nodes/metaconfig

    注册Node到PulServer:
    https://docs.microsoft.com/en-us/powershell/dsc/pull-server/pullclientconfignames

    https://docs.microsoft.com/en-us/powershell/dsc/pull-server/pullclientconfigid

  • 相关阅读:
    芯片测试
    【转】悬浮的对话框
    imagebutton 设置点击和按压效果
    imagebutton 设置了src属性的图片更换
    侧滑实现
    使用自定义的AlertDialog。
    [转]Dialog
    【转】webview的几个问题
    webview 播放H5视频问题 黑屏 只有声音没有画面
    【转】Android HTML5 Video视频标签自动播放与自动全屏问题解决
  • 原文地址:https://www.cnblogs.com/talentzemin/p/11587913.html
Copyright © 2020-2023  润新知