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

How do I use the DSC package resource to install MongoDB?

我尝试了似乎最直接的方法,并在我的节点配置中为 MongoDB MSI 添加了一个包资源。我收到以下错误:"Could not get the https stream for file".

这是我试过的包配置:

    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.6`""
    }

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

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

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

使用 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.6"'
    DependsOn = '[Script]SetTLS'
}
...