来自命令行的rubygems.org超时问题-SSL问题?

时间:2018-07-15 22:36:07

标签: ubuntu ssl rubygems bundler

多年以来,我不需要使用Linux,但是现在我正在创建linux计算机,以便可以在Ruby on Rails上运行。我正在使用Ubuntu 18.04。我以为我已经加载了所有东西,并试图创建我的第一个Rails项目,但是在执行过程中出现错误:

run bundle install --local
Traceback (most recent call last):
    19: from /usr/bin/rails:9:in `<main>'
    18: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    17: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    16: from /usr/lib/ruby/vendor_ruby/rails/cli.rb:14:in `<top (required)>'
    15: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    14: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    13: from /usr/lib/ruby/vendor_ruby/rails/commands/application.rb:17:in `<top (required)>'
    12: from /usr/lib/ruby/vendor_ruby/thor/base.rb:444:in `start'
    11: from /usr/lib/ruby/vendor_ruby/thor/group.rb:232:in `dispatch'
    10: from /usr/lib/ruby/vendor_ruby/thor/invocation.rb:133:in `invoke_all'
     9: from /usr/lib/ruby/vendor_ruby/thor/invocation.rb:133:in `map'
     8: from /usr/lib/ruby/vendor_ruby/thor/invocation.rb:133:in `each'
     7: from /usr/lib/ruby/vendor_ruby/thor/invocation.rb:133:in `block in invoke_all'
     6: from /usr/lib/ruby/vendor_ruby/thor/invocation.rb:126:in `invoke_command'
     5: from /usr/lib/ruby/vendor_ruby/thor/command.rb:27:in `run'
     4: from (eval):1:in `run_bundle'
     3: from /usr/lib/ruby/vendor_ruby/rails/generators/app_base.rb:351:in `run_bundle'
     2: from /usr/lib/ruby/vendor_ruby/rails/generators/app_base.rb:335:in `bundle_command'
     1: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- bundler (LoadError)
chris@linuxbox:~/Sites$

深入研究问题之后,我发现我在与gem交流时遇到问题。我无法从命令行与rubygems.org通信!我尝试的所有操作似乎都超时,但是从浏览器访问rubygems.org没问题。

我尝试使用安装捆绑包,但是(经过漫长的等待)得到了这个包:

chris@linuxbox:~/Sites$ gem install bundler
ERROR:  Could not find a valid gem 'bundler' (>= 0), here is why:
          Unable to download data from https://rubygems.org/ - timed out (https://api.rubygems.org/specs.4.8.gz)
chris@linuxbox:~/Sites$

我做了一些进一步的挖掘,想知道我是否遇到了OpenSSL问题。这是一个eval语句的输出:

chris@linuxbox:~/Sites$ ruby -ropen-uri -e 'eval open("https://git.io/vQhWq").read'
Here's your Ruby and OpenSSL environment:

Ruby:           2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
RubyGems:       2.7.7
Bundler:        1.16.2
Compiled with:  OpenSSL 1.1.0g  2 Nov 2017
Loaded version: OpenSSL 1.1.0g  2 Nov 2017
SSL_CERT_FILE:  /usr/lib/ssl/cert.pem
SSL_CERT_DIR:   /usr/lib/ssl/certs

With that out of the way, let's see if you can connect to rubygems.org...

Bundler connection to rubygems.org:       failed  ❌  (execution expired)
RubyGems connection to rubygems.org:      failed  ❌  (timed out (https://rubygems.org))
Ruby net/http connection to rubygems.org: failed  ❌

Unfortunately, this Ruby can't connect to rubygems.org. 
Even worse, we're not sure why. 

Here's the full error information:
Net::OpenTimeout: execution expired
  /home/chris/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/http.rb:937:in `initialize'
  /home/chris/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/http.rb:937:in `open'
  /home/chris/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/http.rb:937:in `block in connect'
  /home/chris/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/timeout.rb:103:in `timeout'
  /home/chris/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/http.rb:935:in `connect'
  /home/chris/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/http.rb:920:in `do_start'
  /home/chris/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/net/http.rb:915:in `start'
  (eval):90:in `<main>'
  -e:1:in `eval'
  -e:1:in `<main>'

You might have more luck using Mislav's SSL doctor.rb script. You can get it here:
https://github.com/mislav/ssl-tools/blob/8b3dec4/doctor.rb
Read more about the script and how to use it in this blog post:
https://mislav.net/2013/07/ruby-openssl/

我在该输出的末尾下载并运行了doctor.rb脚本,这就是它的意思:

chris@linuxbox:~/Sites$ ruby doctor.rb 
/home/chris/.rvm/rubies/ruby-2.5.1/bin/ruby (2.5.1-p57)
OpenSSL 1.1.0g  2 Nov 2017: /usr/lib/ssl
SSL_CERT_DIR=""
SSL_CERT_FILE=""

HEAD https://status.github.com:443
#<Net::HTTPGatewayTimeOut 504 GATEWAY_TIMEOUT readbody=true>
chris@linuxbox:~/Sites$ 

所以我有SSL问题,对吗?我该如何解决?

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,几乎是您提到的确切输出和命令。

是在系统更新之后。我认为问题是将openssl更新到1.1.1b,但是我不确定其他软件是否也已更新。

我尝试过类似的事情

openssl s_client -connect www.rubygems.com:443

wget https://rubygems.org/rubygems/rubygems-2.7.7.tgz

我注意到它大约2分钟后就连接了。

我随便看了看wget的输出,并赞赏它在切换到ipv4地址时可以正常工作。

因此,我搜索了在Linux上如何更喜欢ipv4而不是ipv6,并且看来在基于glibc的系统上替换行可能成为可能:

precedence ::ffff:0:0/96 10

作者

precedence ::ffff:0:0/96 100

(10到100)

/etc/gai.conf

之后,我可以正常使用红宝石。

希望它会对您有所帮助。