如何使用DSC软件包资源安装MongoDB?

时间:2019-03-23 18:10:38

标签: windows powershell dsc

我尝试了似乎简单的方法,并在我的节点配置中为MongoDB MSI添加了Package资源。我收到以下错误:“无法获取文件的https流”。

这是我尝试过的软件包配置:

    package MongoDB {
        Name = "MongoDB 3.6.11 2008R2Plus SSL (64 bit)"
        Path = "https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.6.11-signed.msi"
        ProductId = "88F7AA23-BDD2-4EBE-9985-EBB5D2E23E83"
        Arguments = "ADDLOCAL=`"all`" SHOULD_INSTALL_COMPASS=`"0`" INSTALLLOCATION=`"C:\MongoDB\Server\3.6`""
    }

(我那里有$ConfigurationData个引用,但是为简单起见,用文字代替了

我收到以下错误: Could not get the https stream for file

可能的TLS版本问题?我发现Invoke-WebRequest需要以下内容才能与同一mongo下载URL一起使用。有办法用包资源做到这一点吗? [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"

1 个答案:

答案 0 :(得分:0)

使用nmap询问nodejs.org和fastdl.mongodb.org(实际上位于云前沿),TLS支持确实是不同的。 Node仍然支持TLS版本1.0,因此可以在PowerShell中使用。但是MongoDB的站点仅支持TLS版本1.1或1.2。

正如我在问题中提到的那样,我怀疑设置.Net安全协议确实有效。无法将任意脚本添加到DSC package 资源中,因此我需要制作一个脚本块以运行此代码,并使软件包资源依赖于此。

这就是我要工作的:

Node $AllNodes.Where{$_.Role -contains 'MongoDBServer'}.NodeName {

Script SetTLS {
    GetScript = { @{ Result = $true } }
    SetScript = { [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" }
    TestScript = { $false } #Always run
}

package MongoDB {
    Ensure = 'Present'
    Name = 'MongoDB 3.6.11 2008R2Plus SSL (64 bit)'
    Path = 'https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.6.11-signed.msi'
    ProductId = ''
    Arguments = 'ADDLOCAL="all" SHOULD_INSTALL_COMPASS="0" INSTALLLOCATION="C:\MongoDB\Server\3.6"'
    DependsOn = '[Script]SetTLS'
}
...