2013-03-04 62 views
6

在過去的一週中,我一直試圖解決Chef COOK-1172,但沒有取得太大的成功。我試圖通過使用Chef-Solo配置器的Vagrant安裝SQL Server 2008 R2開發版(在我的情況下)。當通過廚師獨自流浪時,SQL Server安裝程序失敗,並顯示「Unable to generate a temporary class」

我已經能夠通過直接通過Ruby WinRM gem重新引發廚師以外的問題,然後使用自定義PowerShell腳本修復它,該腳本使用傳入的憑據在來賓Windows上啓動setup.exe進程流浪者箱子。換句話說,WinRM gem會調用一個遠程PS腳本,它可以在指定的憑據下啓動SQL Server setup.exe,並且這可以工作。

但是,運行相同的確切腳本 guest虛擬機上的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)。

回答

4

我可能會列出很多事情來做跟蹤,但最終我發現失敗並不是特定於通過Chef或Ruby運行安裝程序。從本質上講,如果我使用另一個進程來安裝SQL Server WinRM,甚至是在安裝程序日誌中會產生OutOfMemoryException的PowerShell,它都會出錯。

這最終導致我想知道通過WinRM執行安裝程序有什麼不同。然後我有了一個想法。如果我是微軟,我可能會在WinRM上有一些企業特性,這限制了服務器上的攻擊面。顯然,WinRM具有一個名爲Quota Management的功能。

總之,修改我的Windows訪客虛擬機的本地組策略解決了這個問題,我終於能夠通過WinRM和Chef(使用我的上面的PS腳本)成功安裝SQL Server。以下是我使用的設置:

控制檯根|本地計算機策略|計算機配置| 管理模板| Windows組件| Windows遠程外殼

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

我也有這個問題了DSC上服務器2016安裝SQL Server(也可能是舊版本)

您還可以設置通過PowerShell的直接此選項:

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

我只是用它來對服務器2012R2安裝SQL 2014年可以確認它成功地解決了誤差爲OS/SQL Server的組合也得到解決。 – 2015-06-15 15:46:42

0

在花了很多天,現在追這個,我發現根本原因,就我而言,當我在無人蔘與文件中包含任何類型的密碼時,通過WinRM進行安裝時失敗。

這可以通過使用CredSSP的