首页 > 解决方案 > rubygems.org 命令行超时问题——SSL 问题?

问题描述

多年来我不需要使用 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 的通信问题。我无法从命令行与 ruby​​gems.org 通信!我尝试的一切似乎都超时了,但我从浏览器访问 ruby​​gems.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/

我在该输出的末尾下载并运行了医生.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 问题是对的吗?我该如何解决?

标签: ubuntusslrubygemsbundler

解决方案


我遇到了同样的问题,你提到的几乎完全相同的输出和命令。

那是在系统更新之后。我认为问题是将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

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

希望它会帮助你。


推荐阅读