gpt4 book ai didi

sql-server-2012 - 由 chef-client 运行时,DISM/SQL2012 无法访问 Windows 更新

转载 作者:行者123 更新时间:2023-12-04 20:03:00 26 4
gpt4 key购买 nike

我的问题是:通过 WinRM 运行 Chef 时是否存在某种不允许程序访问互联网的权限问题?

我正在尝试在 Server 2012 Std 上使用 Chef 11.4.4 来部署 SQL 2012 Std。我遇到了两个问题,我相信它们是相关的:

windows_feature "NetFx3" do
action :install
end

这失败了,因为 DISM 应该转到 Microsoft 更新并下载 .Net 3.5.1 文件。如果我通过 RDP 手动运行 DISM/online/enable-feature/featurename:NetFx3/norestart 它工作正常 - 这基本上是 windows_feature 运行的。

如果我通过 Recipe (包含 DVD)运行 DISM/online/enable-feature/featurename:NetFx3/norestart/LimitAccess/Source:d:\sources\sxs,它会起作用。实际上,这绕过了上网下载文件的需要。

第二个问题是 SQL Server 2012 安装程序在安装期间尝试联机查找更新。如果我将/UpdateEnabled=false 开关添加到安装命令,它会继续。我正在使用

windows_package "Microsoft SQL Server 2012 (64-bit)" do
source "\\\\10.200.1.240\\admin\\Installs\\SQL\\SQL2012Std\\setup.exe"
timeout 3600 # 60min to just install sql will be fine. Default of 10min can be a bit short
action :install
installer_type :custom
options "/ConfigurationFile=\"#{node['mssql']['installIni']}\" /SAPWD=\"#{node['mssql']['sapw']}\""
end

在 installIni 文件中,我设置了 UpdateSource=MU

我正在通过 knife winrm 192.168.170.145 'chef-client -c c:/chef/client.rb' -m -x nfox 运行 chef,如果这有区别的话。当我从 administrator:cmd 窗口运行 chef-client 时,我没有遇到这个问题。

最佳答案

是的,与您在本地执行命令相比(即使是作为本地管理员特权用户或本地管理员执行此操作),winrm( Chef 的通信协议(protocol))没有完整的用户“上下文”。

如前所述,解决方案是使用在机器上异步触发的计划任务。这样做的好处是拥有完整的上下文,但缺点是您需要知道计划任务何时完成才能删除它并继续。至于使用计划任务,您应该使用具有 lwrp 的 Windows Recipe 。

所以 ...NetFx3 功能安装的解决方案(Microsoft SQL Server 2012(64 位)安装的解决方案可以使用相同的计划任务方法完成):

  • 捕获错误(这只会在第一次运行时发生 Recipe ;在安装功能后运行不会抛出错误)和在计划任务中处理; Chef 的错误处理很长主题,但简而言之,您只能在 Chef 运行的“编译”阶段,这就是 end.run_action(:install ) 正在做)
  • 创建并运行计划任务
  • 轮询直到该功能被安装或您超过超时
  • 无论安装功能成功与否,始终删除任务
  • 根据成功/失败的功能安装继续

创建包含

的COOKBOOK/files/default/install_dotnetfx3.bat.erb
dism.exe /online /enable-feature /featurename:NetFx3 /norestart

然后把它作为你 Recipe 的一部分

begin
windows_feature "NetFx3ServerFeatures" do
action :nothing
end.run_action( :install )

windows_feature "NetFx3" do
action :nothing
end.run_action( :install )

rescue Mixlib::ShellOut::ShellCommandFailed => ex

Chef::Log.error( "ShellCommandFailed was thrown during windows_feature NetFx3 install. Kicking off install via windows_task." )

install_dotnet3_task = 'install_dotnetfx3'
install_dotnet3_script = 'C:\Chef\install_dotnetfx3.bat'

# :create cookbook_file in "compile" phase
cookbook_file install_dotnet3_script do
source 'install_dotnetfx3.bat.erb'
action :nothing
end.run_action( :create )

# :create windows_task in "compile" phase
windows_task install_dotnet3_task do
user Administrator
password XXXXXXX
command install_dotnet3_script
run_level :highest
action :nothing
frequency :minute
frequency_modifier 10
end.run_action( :create )

# :run windows_task in "compile" phase
windows_task install_dotnet3_task do
action :nothing
end.run_action( :run )

featureInstalled = false
iteration = 0
# number of sleeps each sleep_period seconds (total_sleep_period = max_dotnet3_install_via_task_loop_counter * sleep_period)
max_dotnet3_install_via_task_loop_counter = 10
sleep_period = 20 # in sec
loop do

# Check if feature is installed
featureInstalled = shell_out( "dism /online /get-featureinfo /FeatureName:NetFx3 | find \"State : Enabled\"" ).exitstatus == 0
break if featureInstalled || ( iteration += 1 ) > max_dotnet3_install_via_task_loop_counter

# sleep for sleep_period seconds
sleep sleep_period

log "Inside of polling loop for installation (taking #{(iteration * sleep_period)} seconds) of feature via windows_task." do
level :info
action :nothing
end.run_action( :write )
end

# Always :delete windows_task (so that it won't fire again with frequency above) in "compile" phase regardless of whether
# installation via task succeeded or failed.
windows_task install_dotnet3_task do
action :nothing
end.run_action( :delete )

if featureInstalled
log "Installation of the feature via windows_task succeeded." do
level :info
action :nothing
end.run_action( :write )
else
# Raise exception if installation via windows_task failed
raise "Installation of the feature via windows_task timed out within #{(max_dotnet3_install_via_task_loop_counter * sleep_period)} seconds. Try increasing install_via_task_max_poll_counter attribute and re-try."
end
end

关于sql-server-2012 - 由 chef-client 运行时,DISM/SQL2012 无法访问 Windows 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16570875/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com