部署ruby环境时需要注意什么
admin
2023-02-22 23:00:08
0

前言:

一年多前业务使用到redis-cluster集群,然而当时部署时,redis-cluster集群采用的是ruby 语言开发的脚本redis-trib.rb 来进行管理集群的。所以当时给服务器安装了ruby环境。最近项目再一次使用到了redis-cluster集群,所以没多想,直接照着当时的文档记录直接开干,居然行不通了,遇到了各种报错,此次记录在此方便后续使用查看.

服务器环境:centos7.6x84_64位,最小化安装
直接部署ruby环境:

yum -y install ruby ruby-devel
yum -y install rubygems
[root@localhost ~]# which gem
/usr/bin/gem
[root@localhost ~]# gem sources --remove http://rubygems.org/   http://rubygems.org/ removed from sources
source http://rubygems.org/ not present in cache
[root@localhost ~]# gem sources -l
***CURRENT SOURCES ***
https://rubygems.org/
[root@localhost ~]# curl -L get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   194  100   194    0     0    379      0 --:--:-- --:--:-- --:--:--   379
curl: (7) Failed connect to raw.githubusercontent.com:443; 拒绝连接

于是添加淘宝ruby源:

 [root@localhost ~]# gem sources --add https://ruby.taobao.org/   https://ruby.taobao.org/ added to sources
Error fetching https://ruby.taobao.org/:
    hostname "ruby.taobao.org" does not match the server certificate (https://ruby.taobao.org/specs.4.8.gz)

原来是taobao Gems 源已停止维护,现由 ruby-china 提供镜像服务,即我们要换源
参考地址:https://blog.csdn.net/chris_ime/article/details/52013349

gem sources -a   https://gems.ruby-china.com/
[root@localhost ~]# gem sources -a   https://gems.ruby-china.com/
https://gems.ruby-china.com/ added to sources
[root@localhost ~]# gem sources -l
*** CURRENT SOURCES ***
https://rubygems.org/
https://gems.ruby-china.com/

安装RVM:

[root@localhost soft]# curl -L get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   194  100   194    0     0     99      0  0:00:01  0:00:01 --:--:--    99
100 24535  100 24535    0     0   5477      0  0:00:04  0:00:04 --:--:-- 20299
Downloading https://github.com/rvm/rvm/archive/1.29.9.tar.gz

Downloading https://github.com/rvm/rvm/releases/download/1.29.9/1.29.9.tar.gz.asc
gpg: 已创建目录‘/root/.gnupg’
gpg: 新的配置文件‘/root/.gnupg/gpg.conf’已建立
gpg: 警告:在‘/root/.gnupg/gpg.conf’里的选项于此次运行期间未被使用
gpg: 钥匙环‘/root/.gnupg/pubring.gpg’已建立
gpg: 于 2019年07月10日 星期三 16时31分02秒 CST 创建的签名,使用 RSA,钥匙号 39499BDB
gpg: 无法检查签名:没有公钥
GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.29.9.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.9/1.29.9.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:

    gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

or if it fails:

    command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
    command curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -

In case of further problems with validation please refer to https://rvm.io/rvm/security
[root@localhost soft]# echo $?
2

报错了,根据提示如下操作:

[root@localhost soft]# gpg --keyserver hkp://keys.gnupg.net --recv-keys ^C
[root@localhost soft]# gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB 
gpg: 钥匙环‘/root/.gnupg/secring.gpg’已建立
gpg: 下载密钥‘D39DC0E3’,从 hkp 服务器 pool.sks-keyservers.net
gpg: 下载密钥‘39499BDB’,从 hkp 服务器 pool.sks-keyservers.net
gpg: /root/.gnupg/trustdb.gpg:建立了信任度数据库
gpg: 密钥 D39DC0E3:公钥“Michal Papis (RVM signing) ”已导入
gpg: 密钥 39499BDB:公钥“Piotr Kuczynski ”已导入
gpg: 没有找到任何绝对信任的密钥
gpg: 合计被处理的数量:2
gpg:           已导入:2  (RSA: 2)
[root@localhost soft]# curl -L http://get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   194  100   194    0     0     97      0  0:00:02  0:00:01  0:00:01    97
curl: (7) Failed connect to raw.githubusercontent.com:443; 拒绝连接
[root@localhost soft]# curl -L http://get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   194  100   194    0     0     94      0  0:00:02  0:00:02 --:--:--    94
100 24535  100 24535    0     0   2868      0  0:00:08  0:00:08 --:--:--  5254
Downloading https://github.com/rvm/rvm/archive/1.29.9.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.9/1.29.9.tar.gz.asc
gpg: 于 2019年07月10日 星期三 16时31分02秒 CST 创建的签名,使用 RSA,钥匙号 39499BDB
gpg: 完好的签名,来自于“Piotr Kuczynski ”
gpg: 警告:这把密钥未经受信任的签名认证!
gpg:       没有证据表明这个签名属于它所声称的持有者。
主钥指纹: 7D2B AF1C F37B 13E2 069D  6956 105B D0E7 3949 9BDB
GPG verified '/usr/local/rvm/archives/rvm-1.29.9.tgz'
Creating group 'rvm'
Installing RVM to /usr/local/rvm/
Installation of RVM in /usr/local/rvm/ is almost complete:

  * First you need to add all users that will be using rvm to 'rvm' group,
    and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.

  * To start using RVM you need to run `source /etc/profile.d/rvm.sh`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
  * Please do NOT forget to add your users to the rvm group.
     The installer no longer auto-adds root or users to the rvm group. Admins must do this.
     Also, please note that group memberships are ONLY evaluated at login time.
     This means that users must log out then back in before group membership takes effect!
Thanks for installing RVM 

[root@localhost soft]# echo $?
0

到此处rvm安装成功

加载rvm环境:

[root@localhost soft]#  find / -name rvm -print
/usr/local/rvm
/usr/local/rvm/src/rvm
/usr/local/rvm/src/rvm/bin/rvm
/usr/local/rvm/src/rvm/lib/rvm
/usr/local/rvm/src/rvm/scripts/rvm
/usr/local/rvm/bin/rvm
/usr/local/rvm/lib/rvm
/usr/local/rvm/scripts/rvm
[root@localhost soft]# source /usr/local/rvm/scripts/rvm

rvm查看当前可以安装的ruby环境的版本:

[root@localhost soft]# rvm list known
#MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.6]
[ruby-]2.5[.5]
[ruby-]2.6[.3]
[ruby-]2.7[.0-preview1]
ruby-head
#for forks use: rvm install ruby-head- --url https://github.com/github/ruby.git --branch 2.2
#JRuby
jruby-1.6[.8]
jruby-1.7[.27]
jruby-9.1[.17.0]
jruby[-9.2.7.0]
jruby-head

此次演示ruby环境安装的是ruby-2.4.6:

[root@localhost soft]# rvm install  2.4.6
Searching for binary rubies, this might take some time.
No binary rubies available for: centos/7/x86_64/ruby-2.4.6.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for centos.
Installing requirements for centos.
Installing required packages: libffi-devel, readline-devel, sqlite-devel.......
Requirements installation successful.
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-2.4.6, this may take a while depending on your cpu(s)...
ruby-2.4.6 - #downloading ruby-2.4.6, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 12.0M  100 12.0M    0     0  54872      0  0:03:50  0:03:50 --:--:-- 38723
ruby-2.4.6 - #extracting ruby-2.4.6 to /usr/local/rvm/src/ruby-2.4.6.....
ruby-2.4.6 - #configuring..................................................................
ruby-2.4.6 - #post-configuration..
ruby-2.4.6 - #compiling...............................-
....................................................................................
ruby-2.4.6 - #installing...........................
ruby-2.4.6 - #making binaries executable..
ruby-2.4.6 - #downloading rubygems-3.0.6
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  866k  100  866k    0     0  40767      0  0:00:21  0:00:21 --:--:-- 39023
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.4.6 - #extracting rubygems-3.0.6.....
ruby-2.4.6 - #removing old rubygems........
ruby-2.4.6 - #installing rubygems-3.0.6...............................................
ruby-2.4.6 - #gemset created /usr/local/rvm/gems/ruby-2.4.6@global
ruby-2.4.6 - #importing gemset /usr/local/rvm/gemsets/global.gems................................................................
ruby-2.4.6 - #generating global wrappers.......
ruby-2.4.6 - #gemset created /usr/local/rvm/gems/ruby-2.4.6
ruby-2.4.6 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.4.6 - #generating default wrappers.......
ruby-2.4.6 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.4.6 - #complete 
Ruby was built without documentation, to build it run: rvm docs generate-ri
[root@localhost soft]# 
[root@localhost soft]# echo $?
0

此时ruby-2.4.6环境安装成功

查看当前ruby的版本:
[root@localhost soft]# ruby --version
ruby 2.4.6p354 (2019-04-01 revision 67394) [x86_64-linux]
切换到ruby-2.4.6环境:
[root@localhost soft]# rvm use 2.4.6
Using /usr/local/rvm/gems/ruby-2.4.6
[root@localhost soft]# ruby --version
ruby 2.4.6p354 (2019-04-01 revision 67394) [x86_64-linux]
把ruby-2.4.6环境设置成默认
[root@localhost soft]# rvm use 2.4.6 --default
Using /usr/local/rvm/gems/ruby-2.4.6
[root@localhost soft]# ruby --version
ruby 2.4.6p354 (2019-04-01 revision 67394) [x86_64-linux]

安装redis.gem 默认直接安装的是redis-4.1.3:

[root@localhost soft]# gem install redis
Fetching redis-4.1.3.gem
Successfully installed redis-4.1.3
Parsing documentation for redis-4.1.3
Installing ri documentation for redis-4.1.3
Done installing documentation for redis after 1 seconds
1 gem installed
[root@localhost soft]# echo $?
0

安装成功:

[root@localhost soft]# /data/soft/redis-4.0.12/src/redis-trib.rb 
Usage: redis-trib   

  create          host1:port1 ... hostN:portN
                  --replicas 
  check           host:port
  info            host:port
  fix             host:port
                  --timeout 
  reshard         host:port

友情提示:
在管理redis-cluster集群时,经常会使用到rvm环境,每次执行/data/soft/redis-4.0.12/src/redis-trib.rb 命令时,总得提前加载source /usr/local/rvm/scripts/rvm
然后切换到ruby-2.4.6 环境:  rvm use 2.4.6 ;有点繁琐,所以直接写入到环境变量文件,这样在登录这台安装有redis-trib.rb命令的机器时,会自动加载ruby环境,是可以减少每次在命令行执行加载rvm的命令

[root@mysql-redis182 ~]# cat .bashrc 
#.bashrc
#User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
#Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi
###
[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"
rvm use 2.4.6  >/dev/null 2>&1

相关内容

热门资讯

“直-20家族”全亮相 近日,在陆军某旅直升机分队演训中,直-20与直-20T表现亮眼。075型两栖攻击舰日前也搭载直-20...
蒋万安借“725上凯道”成蓝营... 中国国民党25日将于台北凯道举办“我是人,我反毒台”集会,向民进党当局抗议中联毒油案。对此,资深媒体...
波轮式全自动洗衣机脱水时波轮转 波轮式全自动洗衣机脱水时波轮转1、衣物放置不平导致;2、排水系统发生阻塞。3、顶部的安全开关损坏;4...
洗衣机不出水怎么查原因 当洗衣机不出水时,一定是出了问题。下面就是一些可能的原因及其解决方法:1. 电源问题洗衣机不能正常工...
半自动洗衣机放不出水是什么原因... 1、检查过滤网是否堵塞。若堵塞了需要将脏东西取出来,然后再用清水将过滤网清洗干净。2、检查一下是不是...
全自动洗衣机不出水是什么原因 1、进水口的滤网被水中的杂质堵住。2、控制板上的进水继电器坏了。3、电路故障,进水电磁阀有故障或者插...
抽油烟机只通电不转怎么回事 只通电不转的故障原因和解决方法:1、电容量减小或损坏。解决方法:抽油烟机电机不转,还有嗡嗡声,一般是...
谷歌被罚9亿欧元后,特朗普称欧... 当地时间7月23日,欧盟委员会指控美国谷歌公司违反欧盟《数字市场法》,对其处以8.9亿欧元罚款。这一...
14对14,中国反击欧盟,干净... 对于欧盟的指手画脚,中国第一时间反击了。14:14。干净利落,来而不往非礼也。国际博弈,从来如此:没...
风未到,人已行!凌晨不眠!一场... 7月24日晚,台风“红霞”持续逼近,市应急管理局五楼会议室灯火通明,市应急管理局党委书记、局长李见秋...