4

在我们的 RHEL 6.3 系统上安装任何版本的 Ruby 时,OpenSSL 似乎没有正确编译。我一直试图让用户安装 RVM 并通过 ruby​​-install 和 chruby 用 root 安装替换它们。OpenSSL 在我们的 RVM 用户安装(使用规定的 RVM 修复)以及 Ruby 1.8.7 的内置系统安装中运行良好/usr/bin

在我使用 ruby​​-install、ruby-build 甚至 RVM 尝试使用他们最新建议的修复程序时,OpenSSL 在每个 Ruby 版本中都被破坏。1.9.3-p392(我们的 prod 版本)、最新的 1.9 和当前的 2.1.0。我已经尝试了所有可以找到的 openssl 修复/解决方法,例如--with-openssl-dir=/some/dir指向各种 openssl 文件夹的配置,但对我来说没有任何效果。

以下是我多次尝试中的一些相关信息:

[root@dbatcit ~]# ruby-install ruby
>>> Installing ruby 2.1.0 into /opt/rubies/ruby-2.1.0 ...
>>> Installing dependencies for ruby 2.1.0 ...
Loaded plugins: product-id, rhnplugin, security, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
Setting up Install Process
Package gcc-4.4.7-4.el6.x86_64 already installed and latest version
Package automake-1.11.1-4.el6.noarch already installed and latest version
Package zlib-devel-1.2.3-29.el6.x86_64 already installed and latest version
Package libyaml-devel-0.1.3-1.el6.x86_64 already installed and latest version
Package openssl-devel-1.0.1e-16.el6_5.4.x86_64 already installed and latest version
Package gdbm-devel-1.8.0-36.el6.x86_64 already installed and latest version
Package readline-devel-6.0-4.el6.x86_64 already installed and latest version
Package ncurses-devel-5.7-3.20090208.el6.x86_64 already installed and latest version
Package libffi-devel-3.0.5-3.2.el6.x86_64 already installed and latest version
Nothing to do
.
.
make[2]: Entering directory `/usr/local/src/ruby-2.1.0/ext/openssl'
compiling ossl_pkey.c
compiling ossl_ssl.c
ossl_ssl.c:121: error: âTLSv1_2_methodâ undeclared here (not in a function)
ossl_ssl.c:122: error: âTLSv1_2_server_methodâ undeclared here (not in a function)
ossl_ssl.c:123: error: âTLSv1_2_client_methodâ undeclared here (not in a function)
ossl_ssl.c:127: error: âTLSv1_1_methodâ undeclared here (not in a function)
ossl_ssl.c:128: error: âTLSv1_1_server_methodâ undeclared here (not in a function)
ossl_ssl.c:129: error: âTLSv1_1_client_methodâ undeclared here (not in a function)
make[2]: *** [ossl_ssl.o] Error 1
make[2]: Leaving directory `/usr/local/src/ruby-2.1.0/ext/openssl'
make[1]: *** [ext/openssl/all] Error 2
make[1]: Leaving directory `/usr/local/src/ruby-2.1.0'
make: *** [build-ext] Error 2
!!! Compiling ruby 2.1.0 failed!



[root@dbatcit ~]# ruby-install ruby 1.9
>>> Installing ruby 1.9.3-p484 into /opt/rubies/ruby-1.9.3-p484 ...
>>> Installing dependencies for ruby 1.9.3-p484 ...
Loaded plugins: product-id, rhnplugin, security, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
Setting up Install Process
Package gcc-4.4.7-4.el6.x86_64 already installed and latest version
Package automake-1.11.1-4.el6.noarch already installed and latest version
Package zlib-devel-1.2.3-29.el6.x86_64 already installed and latest version
Package libyaml-devel-0.1.3-1.el6.x86_64 already installed and latest version
Package openssl-devel-1.0.1e-16.el6_5.4.x86_64 already installed and latest version
Package gdbm-devel-1.8.0-36.el6.x86_64 already installed and latest version
Package readline-devel-6.0-4.el6.x86_64 already installed and latest version
Package ncurses-devel-5.7-3.20090208.el6.x86_64 already installed and latest version
Package libffi-devel-3.0.5-3.2.el6.x86_64 already installed and latest version
Nothing to do
.
.
make[2]: Entering directory `/usr/local/src/ruby-1.9.3-p484/ext/openssl'
compiling ossl_pkey.c
compiling ossl_ssl.c
compiling ossl_pkcs12.c
compiling ossl_bn.c
compiling ossl_hmac.c
ossl_hmac.c: In function âossl_hmac_copyâ:
ossl_hmac.c:90: warning: implicit declaration of function âHMAC_CTX_copyâ
compiling ossl_asn1.c
compiling ossl.c
compiling ossl_bio.c
compiling ossl_pkey_rsa.c
compiling ossl_ocsp.c
ossl_ocsp.c: In function âossl_ocspreq_add_certidâ:
ossl_ocsp.c:180: warning: function called through a non-compatible type
ossl_ocsp.c:180: note: if this code is reached, the program will abort
ossl_ocsp.c: In function âossl_ocspreq_get_certidâ:
ossl_ocsp.c:200: warning: function called through a non-compatible type
ossl_ocsp.c:200: note: if this code is reached, the program will abort
ossl_ocsp.c: In function âossl_ocspbres_get_statusâ:
ossl_ocsp.c:541: warning: function called through a non-compatible type
ossl_ocsp.c:541: note: if this code is reached, the program will abort
compiling ossl_pkey_dh.c
ossl_pkey_dh.c: In function âossl_dh_initializeâ:
ossl_pkey_dh.c:184: warning: function called through a non-compatible type
ossl_pkey_dh.c:184: note: if this code is reached, the program will abort
ossl_pkey_dh.c: In function âossl_dh_to_public_keyâ:
ossl_pkey_dh.c:372: warning: function called through a non-compatible type
ossl_pkey_dh.c:372: note: if this code is reached, the program will abort
compiling ossl_ns_spki.c
compiling ossl_x509attr.c
compiling ossl_x509name.c
ossl_x509name.c: In function âossl_x509name_hash_oldâ:
ossl_x509name.c:342: warning: implicit declaration of function âX509_NAME_hash_oldâ
compiling ossl_pkcs7.c
compiling ossl_pkey_ec.c
ossl_pkey_ec.c: In function âossl_ec_group_initializeâ:
ossl_pkey_ec.c:784: warning: function called through a non-compatible type
ossl_pkey_ec.c:784: note: if this code is reached, the program will abort
ossl_pkey_ec.c: In function âossl_ec_group_to_stringâ:
ossl_pkey_ec.c:1154: warning: function called through a non-compatible type
ossl_pkey_ec.c:1154: note: if this code is reached, the program will abort
compiling ossl_ssl_session.c
ossl_ssl_session.c: In function âossl_ssl_session_initializeâ:
ossl_ssl_session.c:53: warning: function called through a non-compatible type
ossl_ssl_session.c:53: note: if this code is reached, the program will abort
ossl_ssl_session.c:57: warning: function called through a non-compatible type
ossl_ssl_session.c:57: note: if this code is reached, the program will abort
ossl_ssl_session.c: In function âossl_ssl_session_to_pemâ:
ossl_ssl_session.c:251: warning: function called through a non-compatible type
ossl_ssl_session.c:251: note: if this code is reached, the program will abort
compiling openssl_missing.c
compiling ossl_x509.c
compiling ossl_x509cert.c
compiling ossl_digest.c
compiling ossl_pkcs5.c
ossl_pkcs5.c: In function âossl_pkcs5_pbkdf2_hmacâ:
ossl_pkcs5.c:39: warning: implicit declaration of function âPKCS5_PBKDF2_HMACâ
compiling ossl_rand.c
compiling ossl_engine.c
compiling ossl_x509crl.c
compiling ossl_cipher.c
ossl_cipher.c: In function âossl_cipher_copyâ:
ossl_cipher.c:143: warning: implicit declaration of function âEVP_CIPHER_CTX_copyâ
compiling ossl_x509ext.c
compiling ossl_config.c
compiling ossl_x509store.c
compiling ossl_x509revoked.c
compiling ossl_pkey_dsa.c
compiling ossl_x509req.c
linking shared-object openssl.so
installing default openssl libraries
make[2]: Leaving directory `/usr/local/src/ruby-1.9.3-p484/ext/openssl'
.
.
>>> Successfully installed ruby 1.9.3-p484 into /opt/rubies/ruby-1.9.3-p484

请注意上面的所有 ossl 警告。

重新启动会话。测试系统 Ruby 1.8.7 openssl:有效。测试 ruby​​-install Ruby 1.9.3 openssl:失败。

[root@dbatcit ~]# chruby
   ruby-1.9.3-p484
[root@dbatcit ~]# which ruby
/usr/bin/ruby
[root@dbatcit ~]# ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
[root@dbatcit ~]# ruby -ropenssl -e "puts OpenSSL::VERSION"
1.0.0
[root@dbatcit ~]# chruby 1.9
[root@dbatcit ~]# chruby
 * ruby-1.9.3-p484
[root@dbatcit ~]# which ruby
/opt/rubies/ruby-1.9.3-p484/bin/ruby
[root@dbatcit ~]# ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
[root@dbatcit ~]# ruby -ropenssl -e "puts OpenSSL::VERSION"
/opt/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': /opt/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/x86_64-linux/openssl.so: undefined symbol: EC_GROUP_new_curve_GF2m - /opt/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/x86_64-linux/openssl.so (LoadError)
        from /opt/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /opt/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/openssl.rb:17:in `<top (required)>'
        from /opt/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /opt/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
[root@dbatcit ~]#


[root@dbatcit ~]# which -a openssl
/usr/bin/openssl
/usr/local/bin/openssl
[root@dbatcit ~]# openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013
[root@dbatcit ~]# /usr/local/bin/openssl version
OpenSSL 0.9.8d 28 Sep 2006

在用户主页中测试 RVM Ruby 1.9.3 openssl:有效。

[userbob@dbatcit ~]$ ruby -v
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux]
[userbob@dbatcit ~]$ ruby -ropenssl -e "puts OpenSSL::VERSION"
1.1.0
[userbob@dbatcit ~]$ which openssl
/usr/local/bin/openssl
[userbob@dbatcit ~]$ openssl version
OpenSSL 0.9.8d 28 Sep 2006
[userbob@dbatcit ~]$ .rvm/usr/bin/openssl version
OpenSSL 1.0.1c 10 May 2012
4

3 回答 3

8

经过太多小时的研究,并且对 Linux 的了解远远超出了我的关心,我已将问题缩小到 RHEL 和 OpenSSL 的基本特性以及 Ruby (extconf.rb) 在安装过程中做出的错误假设。以下网站为我提供了一些关于看什么的好线索,但我没有发现任何东西可以像我需要的那样把它们放在一起。

... 并不太感谢一大堆涉及 Ruby 补丁和 EC2M 的红鲱鱼。此外,RVM 需要纠正他们的乐观态度,即他们已经使用 autolibs 解决了这个问题,并且应该恢复他们之前的 openssl 页面。

基本解法规则

规则1

由 yum in 创建和维护的 OpenSSL (1.0.1e) 的安装/usr/bin不能用于正确编译 Ruby 的 OpenSSL 扩展——至少,目前在我的机器上没有最新版本的 Ruby (1.9.3-p484, 2.0 .0, 2.1.0)。RHEL 6.3。我只能推测这是由于 RedHat 编译 OpenSSL 的特殊性,正如 OpenSSL FAQ 中所暗示的那样。

规则 2

/usr/local我在(in bin+openssl和)中发现了 OpenSSL 的两个旧版本 (0.9.8) ssl/bin,更新/替换它们让我更接近解决方案。无论出于何种原因,OpenSSL 1.0.1f 的每次手动安装/usr/local(无论 bin、openssl、ssl 目录安排如何)都坚持将库放入/usr/local/lib64而不是/usr/local/lib(当然,除非我破解了Makefile. 然而, Ruby 的expconf.rb脚本假定 OpenSSL 库总是在一个lib目录中。追查这个单一的烦恼(并与 OpenSSL 发生冲突)是这一切中最难的部分。 因此,要在/usr/local工作中使用 OpenSSL 安装,您必须做两件事:(1)使用--with-openssl-dir开关,以及 (2) 重新编译 Ruby 的 OpenSSL 扩展,同时修改Makefileto 指向lib64而不是lib. 因此,以 root 身份运行类似于以下命令字符串的内容:

ruby-install ruby 1.9.3-p545 -- --with-openssl-dir=/usr/local
cd /usr/local/src/ruby-1.9.3-p545/ext/openssl
ruby extconf.rb

编辑 openssl 的 Makefile 以替换如下内容:

  libpath = . $(libdir) /usr/local/lib
  LIBPATH =  -L. -L$(libdir) -Wl,-R$(libdir) -L/usr/local/lib -Wl,-R/usr/local/lib

像这样:

  libpath = . $(libdir) /usr/local/lib64
  LIBPATH =  -L. -L$(libdir) -Wl,-R$(libdir) -L/usr/local/lib64 -Wl,-R/usr/local/lib64

保存,然后返回命令行:

make
make install

新的 Ruby 安装现在应该可以正常使用 OpenSSL。作为快速检查,我重新启动我的 sudo 会话,然后(假设使用 chruby):

chruby 1.9
ruby -ropenssl -e "puts OpenSSL::VERSION"

规则 3

在任何地方安装 OpenSSL,除了/usr将库放在预期的lib而不是lib64. (不要问我为什么……不知道。)这可能是更易于维护的解决方案,因为它可以让您避免破坏Makefile. 这也是 RVM 在运行时使用的解决方案rvm pkg install openssl。因此,要同时安装 OpenSSL 和 Ruby(在 中/opt),您可以运行类似这样的命令(我运行为 sudo bash):

安装 OpenSSL:

cd /opt/local
wget http://www.openssl.org/source/openssl-1.0.1f.tar.gz
tar -xzf openssl-1.0.1f.tar.gz
cd openssl-1.0.1f
./config --prefix=/opt/local shared no-asm zlib > openssl_config.log
make > openssl_make.log
make install > openssl_install.log

(该shared开关是 Ruby 安装时所必需的,该no-asm开关有助于消除 Make 警告但似乎不是必需的,zlib并且其他开关是可选的。)

可选,更新 openssl 证书:

cd /opt/local/ssl
wget http://curl.haxx.se/ca/cacert.pem
mv cacert.pem cert.pem
cd /opt

回到红宝石:

ruby-install ruby 1.9.3-p545 -- --with-openssl-dir=/opt/local

新的 Ruby 安装现在应该可以正常使用 OpenSSL。作为快速检查,我重新启动我的 sudo 会话,然后(假设使用 chruby):

chruby 1.9
ruby -ropenssl -e "puts OpenSSL::VERSION"
于 2014-03-10T21:28:41.397 回答
2

问题:

这个答案适用于 RVM。具体问题是在 CentOS 6 上安装任何大于 2.2.1 的 ruby​​ 版本rvm install 2.2.2 。通过 rvm 构建的 2.2.2 构建的构建 openssl 包装器版本运行将失败。它将因多种原因而失败(未找到 lib,未找到符号等。)

解决方案:

让 rvm 构建 openssl 包并使用它。这可能适用于其他红宝石:

rvm pkg install openssl
rvm remove 2.2.2
rvm install 2.2.2 -C --with-openssl-dir=$HOME/.rvm/usr

补充说明:

如果您稍后由于 SSL 身份验证而遇到错误(通过 gem 安装任何东西),可能是由于.rvm/usr/ssl目录中的 CA 文件被错误地拉​​取。只需将您的系统安装核心证书文件链接到cert.pemruby​​ 即可完成身份验证。

于 2016-04-26T21:27:29.680 回答
0

我想我找到了一个更简单的解决方案。

显然,最近在 RedHat 和 Ruby 上对 OpenSSL 的更改存在一个已知问题:https ://bugs.ruby-lang.org/issues/8384

将此补丁向后移植到您尝试安装的 1.9.3 版本应该可以解决问题。我在ruby​​-build FAQ上找到了这个,这里有一些代码甚至可以应用补丁。

于 2015-03-23T17:36:38.170 回答