Chef 引导错误-401 未经授权

Chef 引导错误-401 未经授权

我正在尝试使用 Vagrant 设置 Chef 节点,但 bootstrap 命令出现错误。我正在按照 learn.chef.io 上的教程操作

我的 Chef 服务器安装在 EC2 上,运行良好。我可以成功地将食谱从我的工作站上传到服务器本身。

但是,当我从工作站运行以下引导命令来设置节点时:

knife bootstrap localhost --ssh-port 2222 --ssh-user vagrant --sudo --identity-file /Users/Shivam/.vagrant/machines/default/virtualbox/private_key --node-name node1-ubuntu --run-list 'recipe[learn_chef_apache2]'

我收到以下错误。

Creating new client for node1-ubuntu
Creating new node for node1-ubuntu
Connecting to localhost
localhost -----> Existing Chef installation detected
localhost Starting the first Chef Client run...
localhost Starting Chef Client, version 13.2.20
localhost
localhost ================================================================================
localhost Chef encountered an error attempting to load the node data for "node1-ubuntu"
localhost ================================================================================
localhost
localhost Authentication Error:
localhost ---------------------
localhost Failed to authenticate to the chef server (http 401).
localhost The request failed because your clock has drifted by more than 15 minutes.
localhost Syncing your clock to an NTP Time source should resolve the issue.
localhost
localhost System Info:
localhost ------------
localhost chef_version=13.2.20
localhost ruby=ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
localhost program_name=chef-client worker: ppid=17409;start=22:48:40;
localhost executable=/opt/chefdk/bin/chef-client
localhost
localhost
localhost Running handlers:
localhost [2018-04-28T22:48:42+00:00] ERROR: Running exception handlers
localhost Running handlers complete
localhost [2018-04-28T22:48:42+00:00] ERROR: Exception handlers complete
localhost Chef Client failed. 0 resources updated in 01 seconds
localhost [2018-04-28T22:48:42+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
localhost [2018-04-28T22:48:42+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
localhost [2018-04-28T22:48:42+00:00] ERROR: 401 "Unauthorized"
localhost [2018-04-28T22:48:42+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

这是我的 Vagrant 虚拟机上的堆栈跟踪输出。

Generated at 2018-04-28 22:33:52 +0000
Net::HTTPServerException: 401 "Unauthorized"
/opt/chefdk/embedded/lib/ruby/2.4.0/net/http/response.rb:122:in `error!'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/http.rb:152:in `request'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/http.rb:131:in `post'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/api_client/registration.rb:96:in `create'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/api_client/registration.rb:87:in `create_or_update'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/api_client/registration.rb:58:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/client.rb:666:in `register'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/client.rb:267:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:291:in `block in fork_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:279:in `fork'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:279:in `fork_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:244:in `block in run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/local_mode.rb:44:in `with_server_connectivity'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:232:in `run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:469:in `sleep_then_run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:458:in `block in interval_run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:457:in `loop'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:457:in `interval_run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application/client.rb:441:in `run_application'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/lib/chef/application.rb:59:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/chef-13.2.20/bin/chef-client:26:in `<top (required)>'
/usr/bin/chef-client:263:in `load'
/usr/bin/chef-client:263:in `<main>'
~

这就是我的 knife.rb 在工作站上的样子。

current_dir = File.dirname(__FILE__)
log_level                 :info
log_location              STDOUT
node_name                 "chefadmin"
client_key                "#{current_dir}/chefadmin.pem"
chef_server_url           "https://ec2-11-90-25-181.compute-1.amazonaws.com/organizations/4thcoffee"
cookbook_path             ["#{current_dir}/../cookbooks"]

我已遵循这里的建议Chef bootstrap 给出 401 未经授权没有运气。

可能遗漏了一些简单的东西。提前致谢!

答案1

您的错误信息如下:

请求失败,因为您的时钟已偏移超过 15 分钟。将您的时钟与 NTP 时间源同步应该可以解决此问题。

您是否尝试过同步您的时钟?

相关内容