【发布时间】:2017-08-05 20:34:22
【问题描述】:
先决条件
- Chef Sever 正在与节点/工作站托管在同一隔离网络上的虚拟机上运行
- 网络确实需要代理才能与 Internet 上的服务进行通信
问题
在 Windows 上引导 特定 节点后尝试运行“厨师客户端”会导致:-
knife winrm <machine> chef-client -m -x <user> -P <password> --verbose
[2017-03-15T07:48:28+00:00] INFO: *** Chef 12.19.36 ***
[2017-03-15T07:48:28+00:00] INFO: Platform: x64-mingw32
[2017-03-15T07:48:28+00:00] INFO: Chef-client pid: 16184
[2017-03-15T07:48:50+00:00] INFO: Client key C:\chef\client.pem is not present - registering
[2017-03-15T07:48:50+00:00] ERROR: Running exception handlers
[2017-03-15T07:48:50+00:00] ERROR: Exception handlers complete
[2017-03-15T07:48:50+00:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out
[2017-03-15T07:48:50+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2017-03-15T07:48:50+00:00] FATAL: NoMethodError: undefined method `closed?' for nil:NilClass
Did you mean? clone
没错,它没有找到client.pem,并且是第一次使用验证器,但是在阅读堆栈跟踪后,我可以看到根本原因是机器无法从厨师服务器获取私钥.见下文:-
>>>> Caused by Net::HTTPServerException: 407 "Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied. )"
C:/opscode/chef/embedded/lib/ruby/2.3.0/net/http/response.rb:120:in `error!'
C:/opscode/chef/embedded/lib/ruby/2.3.0/net/http/response.rb:129:in `value'
C:/opscode/chef/embedded/lib/ruby/2.3.0/net/http.rb:920:in `connect'
C:/opscode/chef/embedded/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
C:/opscode/chef/embedded/lib/ruby/2.3.0/net/http.rb:852:in `start'
C:/opscode/chef/embedded/lib/ruby/2.3.0/net/http.rb:1398:in `request'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.19.36-universal-mingw32/lib/chef/http/basic_client.rb:70:in `request'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.19.36-universal-mingw32/lib/chef/http.rb:340:in `block in send_http_request'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.19.36-universal-mingw32/lib/chef/http.rb:372:in `block in retrying_http_errors'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.19.36-universal-mingw32/lib/chef/http.rb:370:in `loop'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.19.36-universal-mingw32/lib/chef/http.rb:370:in `retrying_http_errors'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.19.36-universal-mingw32/lib/chef/http.rb:333:in `send_http_request'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.19.36-universal-mingw32/lib/chef/http.rb:148:in `request'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.19.36-universal-mingw32/lib/chef/http.rb:131:in `post'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.19.36-universal-mingw32/lib/chef/api_client/registration.rb:96:in `create'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.19.36-universal-mingw32/lib/chef/api_client/registration.rb:87:in `create_or_update'
C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.19.36-universal-mingw32/lib/chef/api_client/registration.rb:58:in `run'
我尝试了什么?
从 Chef 服务器手动创建和下载私钥 - 稍后仍会获取 407。这让我相信实际上存在一些代理问题,但是我可以从节点与厨师服务器进行通信
我已使用域控制器的凭据运行 WinRM 命令,因此我确定不存在权限不足并已在节点上启用以下 WinRM 设置。
cmd.exe /c winrm quickconfig -q
cmd.exe /c winrm quickconfig -transport:http
cmd.exe /c winrm set winrm/config @{MaxTimeoutms="1800000"}
cmd.exe /c winrm set winrm/config/winrs @{MaxMemoryPerShellMB="3000"}
cmd.exe /c winrm set winrm/config/service @{AllowUnencrypted="true"}
cmd.exe /c winrm set winrm/config/service/auth @{Basic="true"}
cmd.exe /c winrm set winrm/config/client/auth @{Basic="true"}
cmd.exe /c winrm set winrm/config/listener?Address=*+Transport=HTTP @{Port="5985"}
cmd.exe /c netsh advfirewall firewall set rule name="Windows Remote Management (HTTP-In)" profile=public protocol=tcp localport=5985 remoteip=localsubnet new remoteip=any
cmd.exe /c net stop winrm
cmd.exe /c sc config winrm start= auto
cmd.exe /c net start winrm
更新在机器本地运行 chef-client,甚至不使用 WinRM 也会导致相同的错误。 将 WinRM 设置和命令留在帖子中以供历史参考
刀.rb
current_dir = File.dirname(__FILE__)
log_level :info
log_location STDOUT
node_name "admin"
client_key "#{current_dir}/admin_user.pem"
validation_client_name 'org-validator'
validation_key "#{current_dir}/org-validator.pem"
chef_server_url "https://chef.fqdn/organizations/org"
cookbook_path ["#{current_dir}/../cookbooks"]
引导过程创建的Client.rb
log_level :info
log_location STDOUT
chef_server_url "https://chef.fqdn/organizations/org"
validation_client_name "org-validator"
file_cache_path "c:/chef/cache"
file_backup_path "c:/chef/backup"
cache_options ({:path => "c:/chef/cache/checksums", :skip_expires => true})
# Using default node name (fqdn)
trusted_certs_dir "c:/chef/trusted_certs"
值得注意的是,我在网络上的任何其他机器上都没有这个问题。我正在努力从 chef-client 或 chef-server 找到更多调试信息。
回答
如已接受的答案中所述,机器在 Windows 环境变量中设置了 HTTP_PROXY,厨师识别并尝试使用该变量。解决方案是将 no_proxy 添加到 client.rb 或删除 HTTP_PROXY 环境变量。
no_proxy 'chef.fqdn'
【问题讨论】:
-
似乎您的代理不喜欢这台机器或使用的帐户...这听起来与厨师无关,但更多的是代理问题。如果没有您的网络架构图就很难提供帮助,您真的需要通过代理来联系您的主厨服务器吗?
-
@Tensibai,更新了帖子以包含有关代理的详细信息。简短的回答,不,代理只需要通过外部世界。厨师客户应该不需要尝试使用代理。我没有在 client.rb 或其他任何地方配置代理服务器。
-
您的系统在其配置中的某处有代理,请检查您的机器 client.rb,如果您的刀配置中有代理信息,它们会在引导时复制到机器。但奇怪的是你应该有一个 no_proxy 条目来联系你的厨师服务器......我会这样挖掘厨师为什么试图使用代理来联系厨师服务器,如果它不是厨师那么它是一些您机器上的防火墙,将请求重定向到代理。
-
我可以确认添加
no_proxy 'chef.fqdn'有效,但是我真的很想知道为什么厨师在client.rb中没有配置就选择了Windows http 代理。大多数工具都要求您指定代理信息。 -
哪种风格的窗户?如果有一个 HTTP_PROXY env 变量,厨师会尊重它......我真的不知道你的机器是如何制造的
标签: chef-infra http-proxy winrm