【问题标题】:berkshelf unable to connect on CentOSberkshelf 无法在 CentOS 上连接
【发布时间】:2014-09-24 01:05:28
【问题描述】:

我在 vagrant box 上安装了 ChecfDK。

Brekshelf 无法正常工作。无法连接无法连接

我检查了 Iptables 等,但在网络上找不到问题。 URL 可以通过 curl 访问,并且可以在 ubuntu 盒子上正常工作。

CentOS (https://github.com/takase1024/chefdk-centos)

[vagrant@vagrant-centos65 ~]$ cd /vagrant/berks
[vagrant@vagrant-centos65 berks]$ berks install
Resolving cookbook dependencies...
Fetching 'myapp' from source at .
Fetching cookbook index from http://api.berkshelf.com/...
Error retrieving universe from source: http://api.berkshelf.com/
  * [Berkshelf::APIClient::TimeoutError] Unable to connect to: http://api.berkshelf.com/
E, [2014-08-25T03:14:08.122005 #1776] ERROR -- : Actor crashed!
Berkshelf::MissingLockfileCookbookVersion: Cookbook 'apache2' (2.0.0) not found in any of the sources! This can happen if the remote cookbook has been deleted or if the sources inside the Berksfile have changed. Please run `berks update apache2` to resolve to a valid version.
        /opt/chefdk/embedded/apps/berkshelf/lib/berkshelf/installer.rb:95:in `install'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/calls.rb:26:in `public_send'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/calls.rb:26:in `dispatch'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/calls.rb:63:in `dispatch'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/cell.rb:60:in `block in invoke'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/cell.rb:71:in `block in task'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/actor.rb:369:in `block in task'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/tasks.rb:55:in `block in initialize'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/tasks/task_fiber.rb:15:in `block in create'
E, [2014-08-25T03:14:08.123992 #1776] ERROR -- : Actor crashed!
Berkshelf::MissingLockfileCookbookVersion: Cookbook 'iptables' (0.13.2) not found in any of the sources! This can happen if the remote cookbook has been deleted or if the sources inside the Berksfile have changed. Please run `berks update iptables` to resolve to a valid version.
        /opt/chefdk/embedded/apps/berkshelf/lib/berkshelf/installer.rb:95:in `install'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/calls.rb:26:in `public_send'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/calls.rb:26:in `dispatch'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/calls.rb:63:in `dispatch'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/cell.rb:60:in `block in invoke'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/cell.rb:71:in `block in task'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/actor.rb:369:in `block in task'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/tasks.rb:55:in `block in initialize'
        /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/celluloid-0.16.0.pre2/lib/celluloid/tasks/task_fiber.rb:15:in `block in create'
Cookbook 'apache2' (2.0.0) not found in any of the sources! This can happen if the remote cookbook has been deleted or if the sources inside the Berksfile have changed. Please run `berks update apache2` to resolve to a valid version.

(Following omitted)

[vagrant@vagrant-centos65 berks]$ curl http://api.berkshelf.com/
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
  <head>

(Following omitted)

【问题讨论】:

    标签: networking centos vagrant chefdk


    【解决方案1】:

    在尝试使用 Berkshelf 工作流程后,我发现它实际上不适用于在 Windows 主机上运行的 vagrant(或者我猜是 Virtual Box?)CentOS 来宾。这是因为上面指出的超时问题。我的hacky修复是这样的。我知道它可能会更好地推动允许您将其作为变量传递的增强功能。

    现在我假设您使用的是 ChefDK 的嵌入式 ruby​​ 和 berkshelf gem。如果不是,这些位置可能在其他地方。

    在此处阅读有关特定课程的更多信息:

    http://ruby-doc.org/gems/docs/b/berkshelf-api-client-1.2.0/Berkshelf/APIClient/Connection.html

    [vagrant@vagrant-centos65 apache-acquity]$ cd /opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/berkshelf-api-client-1.2.0/
    lib/berkshelf/api_client
    [vagrant@vagrant-centos65 api_client]$ vim connection.rb
    

    找到这个:

    def initialize(url, options = {})
      options         = options.reverse_merge(retries: 3, retry_interval: 0.5,
        open_timeout: 3, timeout: 30)
    

    改成这样:

    def initialize(url, options = {})
      options         = options.reverse_merge(retries: 3, retry_interval: 0.5,
        open_timeout: 30, timeout: 30)
    

    保存并关闭,然后重试。

    【讨论】:

      【解决方案2】:

      这看起来可能是 berkshelf-api-client 选项的问题。默认情况下,open_timeout 选项设置为 3 秒。通过增加此超时时间,我能够成功连接。

      1.9.3-p547 :010 > source = Berkshelf::Source.new("http://berkshelf.example.come")
       => #<Berkshelf::Source uri: "http://berkshelf.example.com">
      1.9.3-p547 :011 > api = source.send(:api_client)
       => #<Berkshelf::APIClient::Connection:0x00000001b613f8 @url="http://berkshelf.example.com", @retries=3, @retry_interval=0.5, @parallel_manager=nil, @headers={"User-Agent"=>"Faraday v0.9.0"}, @params={}, @options=#<Faraday::RequestOptions timeout=30, open_timeout=3>, @ssl=#<Faraday::SSLOptions (empty)>, @default_parallel_manager=nil, @builder=#<Faraday::RackBuilder:0x00000001b612b8 @handlers=[Ridley::Middleware::ParseJson, Ridley::Middleware::Gzip, Faraday::Request::Retry, Faraday::Adapter::NetHttp]>, @url_prefix=#<URI::HTTP:0x000000023938a0 URL:http://berkshelf.example.com/>, @proxy=nil>
      1.9.3-p547 :012 > api.universe
      

      错误:

      Berkshelf::APIClient::TimeoutError: Unable to connect to: http://berkshelf.example.com
      

      现在,如果我修改 APIClient 使用的选项如下:

      1.9.3-p547 :012 > opts = api.options
       => #<Faraday::RequestOptions timeout=30, open_timeout=3>
      1.9.3-p547 :013 > opts.open_timeout = 30
       => 30
      1.9.3-p547 :014 > api.instance_eval { @options = opts }
       => #<Faraday::RequestOptions timeout=30, open_timeout=30>
      

      成功:

      1.9.3-p547 :015 > api.universe
       => [#<Berkshelf::APIClient::RemoteCookbook:0x00000002a30320 @blah=blah @etc=true>]
      

      【讨论】:

      • 我对红宝石不熟悉。如果你运行命令,你想尝试你的方式吗?我忘记推送示例代码。只是推。
      • 这是显示 ruby​​ 交互式 shell 或“irb”。因此,只需从命令行运行“irb”,然后在 irb 打开时输入“require berkshelf”。然后你就可以完成上面的练习了。
      猜你喜欢
      • 2017-04-20
      • 2015-03-01
      • 2023-03-16
      • 1970-01-01
      • 2016-04-13
      • 2023-04-02
      • 2014-11-17
      • 2012-06-15
      • 2019-05-18
      相关资源
      最近更新 更多