【问题标题】:SQL Server setup fails with "Unable to generate a temporary class" when through chef-solo on vagrant通过 vagrant 上的 chef-solo 时,SQL Server 设置失败并显示“无法生成临时类”
【发布时间】:2013-03-04 16:43:48
【问题描述】:

在过去的一周里,我一直在尝试与 Chef COOK-1172 联系,但没有取得多大成功。我正在尝试使用 Chef-Solo 配置程序通过 Vagrant 安装 SQL Server 2008 R2 Developer Edition(在我的情况下)。

我已经能够通过直接通过 Ruby WinRM gem 在 Chef 之外重现该问题,然后使用自定义 PowerShell 脚本修复它,该脚本使用传递的凭据在来宾 Windows vagrant 上启动 setup.exe 进程盒子。换句话说,WinRM gem 调用一个远程 PS 脚本,该脚本在指定的凭据下启动 SQL Server setup.exe,这是有效的。

但是,通过 chef-solo 在客户机上运行完全相同的脚本失败并出现 InvalidOperationException:无法生成临时类。

我用于测试的 Ruby 脚本和嵌入式 PowerShell 脚本,从我的 OS X 主机调用:

require 'winrm'

endpoint = 'http://localhost:5985/wsman'
user = password = 'vagrant'
ps = <<EOH

function ps-runas ([String] $cmd, [String] $arguments)
{
  Write-Host "ps-runas cmd: $cmd"
  Write-Host "ps-runas args: $arguments"

  $secpasswd = ConvertTo-SecureString "vagrant" -AsPlainText -Force

  $process = New-Object System.Diagnostics.Process
  $setup = $process.StartInfo
  $setup.FileName = $cmd
  $setup.Arguments = $arguments
  $setup.UserName = "vagrant"
  $setup.Password = $secpasswd
  $setup.Verb = "runas"
  $setup.UseShellExecute = $false
  $setup.RedirectStandardError = $true
  $setup.RedirectStandardOutput = $true
  $setup.RedirectStandardInput = $false

  # Hook into the standard output and error stream events
  $errEvent = Register-ObjectEvent -InputObj $process `
    -Event "ErrorDataReceived" `
    -Action `
    {
        param
        (
            [System.Object] $sender,
            [System.Diagnostics.DataReceivedEventArgs] $e
        )
        Write-Host $e.Data
    }
  $outEvent = Register-ObjectEvent -InputObj $process `
    -Event "OutputDataReceived" `
    -Action `
    {
        param
        (
            [System.Object] $sender,
            [System.Diagnostics.DataReceivedEventArgs] $e
        )
        Write-Host $e.Data
    }

  Write-Host "ps-runas starting: $cmd"

  if (!$process.Start())
  {
    Write-Error "Failed to start $cmd"
  }

  $process.BeginOutputReadLine()
  $process.BeginErrorReadLine()

  # Wait until process exit
  $process.WaitForExit()

  $process.CancelOutputRead()
  $process.CancelErrorRead()
  $process.Close()
}

EOH

cmd = ps

# Fails - Running through chef-solo fails - cannot compile a serialization assembly
cmd << "ps-runas \"c:\\opscode\\chef\\bin\\chef-solo.bat\" \"-c c:\\tmp\\vagrant-chef-1\\solo.rb -j c:\\tmp\\vagrant-chef-1\\dna.json\""

# Succeeds - Running setup directly works
#cmd << "ps-runas \"c:\\vagrant\\sql2008r2\\setup.exe\" \"/Q /ConfigurationFile=c:\\vagrant\\ConfigurationFile.ini\""

winrm = WinRM::WinRMWebService.new(endpoint, :plaintext, :user => user, :pass => password, :basic_auth_only => true)
winrm.set_timeout(60*20)

winrm.powershell(cmd) do |stdout, stderr|
  STDOUT.print stdout
  STDERR.print stderr
end

puts 'Done!'

来自 sql 安装日志:

013-03-03 22:44:50 Slp: Exception type: Microsoft.SqlServer.Chainer.Infrastructure.ChainerInfrastructureException
2013-03-03 22:44:50 Slp:     Message: 
2013-03-03 22:44:50 Slp:         Unable to generate a temporary class (result=1).
2013-03-03 22:44:50 Slp:         error CS0583: Internal Compiler Error (0xc0000017 at address 000007FEFD00AA7D): likely culprit is 'IMPORT'.
2013-03-03 22:44:50 Slp:         error CS0584: Internal Compiler Error: stage 'IMPORT' symbol 'System.Xml.Serialization.XmlSerializationReader'
2013-03-03 22:44:50 Slp:         error CS0584: Internal Compiler Error: stage 'IMPORT' symbol 'Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderClusterNodesStatusPublicConfigObject'
2013-03-03 22:44:50 Slp:         error CS0584: Internal Compiler Error: stage 'PREPARE' symbol 'Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderClusterNodesStatusPublicConfigObject'
2013-03-03 22:44:50 Slp:         error CS0584: Internal Compiler Error: stage 'PREPARE' symbol 'Microsoft.Xml.Serialization.GeneratedAssembly'
2013-03-03 22:44:50 Slp:         error CS0584: Internal Compiler Error: stage 'PREPARE' symbol 'Microsoft.Xml.Serialization'
2013-03-03 22:44:50 Slp:         error CS0584: Internal Compiler Error: stage 'PREPARE' symbol 'Microsoft.Xml'
2013-03-03 22:44:50 Slp:         error CS0584: Internal Compiler Error: stage 'PREPARE' symbol 'Microsoft'
2013-03-03 22:44:50 Slp:         error CS0584: Internal Compiler Error: stage 'PREPARE' symbol '<global namespace>'
2013-03-03 22:44:50 Slp:         error CS0586: Internal Compiler Error: stage 'PREPARE'
2013-03-03 22:44:50 Slp:         error CS0587: Internal Compiler Error: stage 'PREPARE'
2013-03-03 22:44:50 Slp:         error CS0587: Internal Compiler Error: stage 'BEGIN'
2013-03-03 22:44:50 Slp:         
2013-03-03 22:44:50 Slp:     Stack: 
2013-03-03 22:44:50 Slp:         at Microsoft.SqlServer.Chainer.Infrastructure.DataStoreService.DeserializeObject(String rootPath, Type type, String elementXPath)
2013-03-03 22:44:50 Slp:         at Microsoft.SqlServer.Chainer.Infrastructure.DataStoreService.DeserializeObject(String rootPath, Type type)
2013-03-03 22:44:50 Slp:         at Microsoft.SqlServer.Configuration.SetupExtension.FinalCalculateSettingsAction.ExecuteAction(String actionId)
2013-03-03 22:44:50 Slp:         at Microsoft.SqlServer.Chainer.Infrastructure.Action.Execute(String actionId, TextWriter errorStream)
2013-03-03 22:44:50 Slp:         at Microsoft.SqlServer.Setup.Chainer.Workflow.ActionInvocation.ExecuteActionHelper(TextWriter statusStream, ISequencedAction actionToRun)
2013-03-03 22:44:50 Slp:     Inner exception type: System.InvalidOperationException
2013-03-03 22:44:50 Slp:         Message: 
2013-03-03 22:44:50 Slp:                 Unable to generate a temporary class (result=1).
2013-03-03 22:44:50 Slp:                 error CS0583: Internal Compiler Error (0xc0000017 at address 000007FEFD00AA7D): likely culprit is 'IMPORT'.
2013-03-03 22:44:50 Slp:                 error CS0584: Internal Compiler Error: stage 'IMPORT' symbol 'System.Xml.Serialization.XmlSerializationReader'
2013-03-03 22:44:50 Slp:                 error CS0584: Internal Compiler Error: stage 'IMPORT' symbol 'Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderClusterNodesStatusPublicConfigObject'
2013-03-03 22:44:50 Slp:                 error CS0584: Internal Compiler Error: stage 'PREPARE' symbol 'Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderClusterNodesStatusPublicConfigObject'
2013-03-03 22:44:50 Slp:                 error CS0584: Internal Compiler Error: stage 'PREPARE' symbol 'Microsoft.Xml.Serialization.GeneratedAssembly'
2013-03-03 22:44:50 Slp:                 error CS0584: Internal Compiler Error: stage 'PREPARE' symbol 'Microsoft.Xml.Serialization'
2013-03-03 22:44:50 Slp:                 error CS0584: Internal Compiler Error: stage 'PREPARE' symbol 'Microsoft.Xml'
2013-03-03 22:44:50 Slp:                 error CS0584: Internal Compiler Error: stage 'PREPARE' symbol 'Microsoft'
2013-03-03 22:44:50 Slp:                 error CS0584: Internal Compiler Error: stage 'PREPARE' symbol '<global namespace>'
2013-03-03 22:44:50 Slp:                 error CS0586: Internal Compiler Error: stage 'PREPARE'
2013-03-03 22:44:50 Slp:                 error CS0587: Internal Compiler Error: stage 'PREPARE'
2013-03-03 22:44:50 Slp:                 error CS0587: Internal Compiler Error: stage 'BEGIN'
2013-03-03 22:44:50 Slp:                 
2013-03-03 22:44:50 Slp:         Stack: 
2013-03-03 22:44:50 Slp:                 at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
2013-03-03 22:44:50 Slp:                 at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
2013-03-03 22:44:50 Slp:                 at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
2013-03-03 22:44:50 Slp:                 at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace)
2013-03-03 22:44:50 Slp:                 at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
2013-03-03 22:44:50 Slp:                 at Microsoft.SqlServer.Chainer.Infrastructure.DataStoreService.DeserializeObject(String rootPath, Type type, String elementXPath)

我的第一个怀疑是我的临时目录遇到了某种权限问题,但我尝试运行 ProcMon 并且在运行设置时没有发现任何 ACCESS DENIED 结果。此外,由于 PowerShell 脚本和 UAC 已关闭,我明确地以本地管理员 (vagrant) 身份运行。

【问题讨论】:

    标签: sql-server powershell chef-infra vagrant winrm


    【解决方案1】:

    我可能会列出很多我为追踪此问题所做的事情,但最后我发现失败并非特定于通过 Chef 甚至 Ruby 运行安装程序。本质上,每当我使用另一个进程通过 WinRM 安装 SQL Server 时,它都会出错,即使是 PowerShell,也会在安装程序日志中产生 OutOfMemoryException。

    这最终让我想知道通过 WinRM 执行安装程序有什么不同。然后我有了一个想法。如果我是 Microsoft,我可能会围绕 WinRM 拥有一些企业特性,从而限制服务器上的攻击面。显然 WinRM 有一个名为Quota Management 的功能。

    简而言之,修改我的 Windows 来宾 VM 的本地组策略解决了这个问题,我终于能够通过 WinRM 和 Chef 成功安装 SQL Server(使用我上面的 PS 脚本)。以下是我使用的设置:

    控制台根目录 |本地计算机政策 |电脑配置 | 管理模板 | Windows 组件 | Windows 远程外壳​​

    • MaxConcurrentUsers:100
    • MaxMemoryPerShellMB: 0
    • MaxProcessesPerShell:0
    • MaxShellsPerUser:0

    【讨论】:

      【解决方案2】:

      我在服务器 2016(可能还有旧版本)上通过 DSC 安装 sql server 时也遇到了这个问题

      你也可以直接通过powershell设置这个选项:

      set-item WSMan:\localhost\Shell\MaxMemoryPerShellMB 2048
      

      【讨论】:

      • 我刚刚使用它在 Server 2012R2 上安装了 SQL 2014,并且可以确认它也成功解决了该 OS/SQL Server 组合的错误。
      【解决方案3】:

      来自 ticket Chef COOK-1172,Julian C. Dunn [Chef] 添加了评论

      我们相信微软现在在以下修补程序中修复了这个问题,这将恢复 WinRM 对 MaxMemoryPerShellMB 的尊重: http://support.microsoft.com/kb/2842230

      不幸的是,这对我不起作用。我仍然有同样的问题。

      【讨论】:

        【解决方案4】:

        现在已经花了很多天来追求这个,我发现就我而言,根本原因是当我在无人参与文件中包含任何类型的密码时,通过 WinRM 安装时失败。

        这可以通过使用 CredSSP 解决

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-09-16
          • 2012-04-30
          相关资源
          最近更新 更多