1. 程式人生 > >解決方法:配置群集時# gem install redis 報錯:Unable to require openssl, install OpenSSL and rebuild ruby

解決方法:配置群集時# gem install redis 報錯:Unable to require openssl, install OpenSSL and rebuild ruby

ttr 沒有 就會 由於 mic mas 可能 sage not

問題
前面已經在/usr/local/src安裝了ruby-2.3.0.tar.gz、rubygems-2.4.2.tar.gz。
在配置 redis-3.1.1 群集中,使用gem install 安裝 ruby redis 接口時報:

[plain] view plain copy
  1. # [root@localhost src]# gem install redis --version 3.0.0
  2. # # 由於源的原因,可能下載失敗,就手動下載下來安裝
  3. [root@localhost src]# gem install /usr/local/src/redis-3.2.1.gem
  4. ERROR: While executing gem ... (Gem::Exception)
  5. Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources


原因
缺少openssl,需要安裝openssl包,我現在這裏來安裝一個openssl-1.0.1s.tar.gz(下載鏈接:http://www.openssl.org/source/)

解決方法步驟
1.解壓在/usr/local/src目錄下,進入/usr/local/src/openssl-1.0.1s目錄準備安裝:

[plain] view plain copy
  1. [root@localhost src]# tar -xzvf openssl-1.0.1s.tar.gz
  2. [root@localhost src]# cd openssl-1.0.1s
  3. [root@localhost openssl-1.0.1s]# ./config -fPIC --prefix=/usr/local/openssl enable-shared
  4. [root@localhost openssl-1.0.1s]# ./config -t
  5. [root@localhost openssl-1.0.1s]# make && make install


openssl的配置文件必須要配置-fPIC參數,如果沒有該參數下面的安裝中會出現問題!
安裝完成,可以檢測一下是否安裝成功:

[plain] view plain copy
  1. [root@localhost openssl-1.0.1s]# openssl version


2.進入ruby源碼[/usr/local/src/ruby-2.3.0]目錄下的ext/openssl 目錄:

[plain] view plain copy
  1. [root@localhost openssl-1.0.1s]# cd ../ruby-2.3.0
  2. [root@localhost ruby-2.3.0]# cd ext/openssl
  3. [root@localhost openssl]# ruby extconf.rb
  4. checking for t_open() in -lnsl... no
  5. checking for socket() in -lsocket... no
  6. checking for assert.h... yes
  7. checking for openssl/ssl.h... no


提示沒有找到ssl.h, 因為出現了錯誤:openssl/ssl.h:沒有那個文件或目錄

[plain] view plain copy
  1. [root@localhost openssl]# ruby extconf.rb --with-openssl-include=/usr/local/openssl/include/ --with-openssl-lib=/usr/local/openssl/lib
  2. checking for t_open() in -lnsl... no
  3. checking for socket() in -lsocket... no
  4. checking for assert.h... yes
  5. checking for openssl/ssl.h... yes
  6. .............................................中間略.............................................
  7. checking for EVP_CTRL_GCM_GET_TAG in openssl/evp.h... yes
  8. creating extconf.h
  9. creating Makefile

成功。

3.接下來並且將ruby 源碼目錄下的include目錄軟鏈接到 / 目錄下:

[plain] view plain copy
  1. [root@localhost openssl]# ln -s /usr/local/src/ruby-2.2.3/include /


接著再執行make,如果在配置openssl時沒有-fPIC參數時就會出現如下錯誤

[plain] view plain copy
  1. [root@localhost openssl]# make
  2. gcc -shared -o openssl.so ossl_x509.o ossl_x509cert.o ossl_x509crl.o ossl_pkcs7.o ossl_cipher.o ossl_pkey_dh.o ossl_ssl_session.o ossl_x509attr.o ossl_x509ext.o ossl_ocsp.o ossl_asn1.o ossl_x509name.o ossl_x509revoked.o ossl_rand.o ossl_pkcs12.o ossl_x509store.o ossl_ssl.o ossl.o ossl_digest.o ossl_config.o ossl_pkcs5.o ossl_bio.o ossl_pkey_dsa.o ossl_pkey.o ossl_x509req.o ossl_pkey_ec.o ossl_hmac.o openssl_missing.o ossl_ns_spki.o ossl_pkey_rsa.o ossl_engine.o ossl_bn.o -L. -L/usr/local/ruby/lib -Wl,-R/usr/local/ruby/lib -L/usr/local/ssl/lib -Wl,-R/usr/local/ssl/lib -L. -rdynamic -Wl,-export-dynamic -lssl -lcrypto -lrt -ldl -lcrypt -lm -lc
  3. /usr/bin/ld: /usr/local/ssl/lib/libssl.a(s2_meth.o): relocation R_X86_64_32 against `a local symbol‘
  4. can not be used when making a shared object; recompile with -fPIC
  5. /usr/local/ssl/lib/libssl.a: could not read symbols: Bad value
  6. collect2: ld returned 1 exit status
  7. make: *** [openssl.so] Error 1


有配置-fPIC參數時就繼續走下去:

[plain] view plain copy
  1. [root@localhost openssl]# make
  2. compiling ossl_pkey_dsa.c
  3. compiling openssl_missing.c
  4. compiling ossl_x509name.c
  5. compiling ossl_pkey_rsa.c
  6. .............................................中間略.............................................
  7. compiling ossl_bn.c
  8. compiling ossl.c
  9. linking shared-object openssl.so

[plain] view plain copy
  1. [root@localhost openssl]# make install
  2. /usr/bin/install -c -m 0755 openssl.so /usr/local/ruby/lib/ruby/site_ruby/2.2.0/x86_64-linux
  3. installing default openssl libraries

成功。

4.回過頭來,這時候我們已經把配置集群遇到的各種問題已經解決好了,再次使用gem install 安裝 ruby redis 接口:

[plain] view plain copy
  1. # [root@localhost src]# gem install redis --version 3.0.0
  2. # # 由於源的原因,可能下載失敗,就手動下載下來安裝
  3. [root@localhost src]# gem install /usr/local/src/redis-3.2.1.gem
  4. Successfully installed redis-3.2.1
  5. Parsing documentation for redis-3.2.1
  6. Installing ri documentation for redis-3.2.1
  7. Done installing documentation for redis after 0 seconds
  8. WARNING: Unable to pull data from ‘https://rubygems.org/‘: SSL_connect returned=1 errno=0 state=error: certificate verify failed (https://rubygems.org/specs.4.8.gz)
  9. 1 gem installed

可以看到這時ruby redis接口已經安裝成功了;

當Redis也安裝好,這時我們來做一個Redis集群測試,在一臺服務器中創建了6個Redis實例,開啟6個Redis服務。

[plain] view plain copy
  1. [root@localhost redis-cluster]# redis-trib.rb create --replicas 1 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006
  2. >>> Creating cluster
  3. >>> Performing hash slots allocation on 6 nodes...
  4. Using 3 masters:
  5. 127.0.0.1:7001
  6. 127.0.0.1:7002
  7. 127.0.0.1:7003
  8. Adding replica 127.0.0.1:7004 to 127.0.0.1:7001
  9. Adding replica 127.0.0.1:7005 to 127.0.0.1:7002
  10. Adding replica 127.0.0.1:7006 to 127.0.0.1:7003
  11. M: e18c4d9b2a9c2b92b3695cb7236512bc3569349e 127.0.0.1:7001
  12. slots:0-5460 (5461 slots) master
  13. M: bfd2c5320bfa800713e18b8f57900fd63995d7cf 127.0.0.1:7002
  14. slots:5461-10922 (5462 slots) master
  15. M: 9d41b514413bcf348d55fe7239ce93b94fab7b01 127.0.0.1:7003
  16. slots:10923-16383 (5461 slots) master
  17. S: fef13f9a028d8a5de2442f562aa88941eb591ba5 127.0.0.1:7004
  18. replicates e18c4d9b2a9c2b92b3695cb7236512bc3569349e
  19. S: 7845903bdd01e2992877e27110bbbc7ff4036828 127.0.0.1:7005
  20. replicates bfd2c5320bfa800713e18b8f57900fd63995d7cf
  21. S: c0becb06b09e957fd34fad5ae85dec15d0b59cd8 127.0.0.1:7006
  22. replicates 9d41b514413bcf348d55fe7239ce93b94fab7b01
  23. Can I set the above configuration? (type ‘yes‘ to accept): yes
  24. >>> Nodes configuration updated
  25. >>> Assign a different config epoch to each node
  26. >>> Sending CLUSTER MEET messages to join the cluster
  27. Waiting for the cluster to join.....
  28. >>> Performing Cluster Check (using node 127.0.0.1:7001)
  29. M: e18c4d9b2a9c2b92b3695cb7236512bc3569349e 127.0.0.1:7001
  30. slots:0-5460 (5461 slots) master
  31. M: bfd2c5320bfa800713e18b8f57900fd63995d7cf 127.0.0.1:7002
  32. slots:5461-10922 (5462 slots) master
  33. M: 9d41b514413bcf348d55fe7239ce93b94fab7b01 127.0.0.1:7003
  34. slots:10923-16383 (5461 slots) master
  35. M: fef13f9a028d8a5de2442f562aa88941eb591ba5 127.0.0.1:7004
  36. slots: (0 slots) master
  37. replicates e18c4d9b2a9c2b92b3695cb7236512bc3569349e
  38. M: 7845903bdd01e2992877e27110bbbc7ff4036828 127.0.0.1:7005
  39. slots: (0 slots) master
  40. replicates bfd2c5320bfa800713e18b8f57900fd63995d7cf
  41. M: c0becb06b09e957fd34fad5ae85dec15d0b59cd8 127.0.0.1:7006
  42. slots: (0 slots) master
  43. replicates 9d41b514413bcf348d55fe7239ce93b94fab7b01
  44. [OK] All nodes agree about slots configuration.
  45. >>> Check for open slots...
  46. >>> Check slots coverage...
  47. [OK] All 16384 slots covered.
  48. [root@localhost redis-cluster]# redis-trib.rb check
  49. [ERR] Wrong number of arguments for specified sub command
  50. [root@localhost redis-cluster]# redis-trib.rb check 127.0.0.1:7001
  51. >>> Performing Cluster Check (using node 127.0.0.1:7001)
  52. M: e18c4d9b2a9c2b92b3695cb7236512bc3569349e 127.0.0.1:7001
  53. slots:0-5460 (5461 slots) master
  54. 1 additional replica(s)
  55. S: c0becb06b09e957fd34fad5ae85dec15d0b59cd8 127.0.0.1:7006
  56. slots: (0 slots) slave
  57. replicates 9d41b514413bcf348d55fe7239ce93b94fab7b01
  58. S: fef13f9a028d8a5de2442f562aa88941eb591ba5 127.0.0.1:7004
  59. slots: (0 slots) slave
  60. replicates e18c4d9b2a9c2b92b3695cb7236512bc3569349e
  61. S: 7845903bdd01e2992877e27110bbbc7ff4036828 127.0.0.1:7005
  62. slots: (0 slots) slave
  63. replicates bfd2c5320bfa800713e18b8f57900fd63995d7cf
  64. M: bfd2c5320bfa800713e18b8f57900fd63995d7cf 127.0.0.1:7002
  65. slots:5461-10922 (5462 slots) master
  66. 1 additional replica(s)
  67. M: 9d41b514413bcf348d55fe7239ce93b94fab7b01 127.0.0.1:7003
  68. slots:10923-16383 (5461 slots) master
  69. 1 additional replica(s)
  70. [OK] All nodes agree about slots configuration.
  71. >>> Check for open slots...
  72. >>> Check slots coverage...
  73. [OK] All 16384 slots covered.

這樣就表示我們的集群(三主三從)創建成功了!

主節點:127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003

從節點:127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006

解決方法:配置群集時# gem install redis 報錯:Unable to require openssl, install OpenSSL and rebuild ruby