淘先锋技术网

首页 1 2 3 4 5 6 7

接着上一篇文章,redis集群配置:

https://blog.csdn.net/u010533511/article/details/89388547

Redis 3.0以上的集群方式是通过Redis安装目录下的redis-trib.rb脚本搭建。

这个脚本是用Ruby编写的,所以要先安装Ruby环境

yum安装ruby和依赖的包。

# yum -y install ruby ruby-devel rubygems

一般来说,这一步是能正常完成的。

使用gem这个命令来安装redis接口

gem install redis
    ERROR:  Error installing redis:
     redis requires Ruby version >= 2.2.2.

CentOS7 yum库中ruby的版本支持到 2.0.0,可gem 安装redis需要最低是2.2.2,采用rvm来更新ruby

安装RVM(具体RVM安装命令地址:http://rvm.io/)

[root@localhost /]# gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB 
[root@localhost /]# curl -sSL https://get.rvm.io | bash -s stable
[root@localhost /]# 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 /]# source /usr/local/rvm/scripts/rvm

查看已知ruby版本

# rvm list known
 
 
[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[.7]
[ruby-]2.4[.4]
[ruby-]2.5[.1]
[ruby-]2.6[.0-preview2]
......

安装一个ruby版本:

#rvm install 2.5.1
 
Searching for binary rubies, this might take some time.
    Found remote file https://rvm_io.global.ssl.fastly.net/binaries/centos/7/x86_64/ruby-2.5.1.tar.bz2
    Checking requirements for centos.
    Requirements installation successful.
    ruby-2.5.1 - #configure
    ruby-2.5.1 - #download
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 14.1M  100 14.1M    0     0    97k      0  0:02:27  0:02:27 --:--:--  159k
    No checksum for downloaded archive, recording checksum in user configuration.
    ruby-2.5.1 - #validate archive
    ruby-2.5.1 - #extract
    ruby-2.5.1 - #validate binary
    ruby-2.5.1 - #setup
    ruby-2.5.1 - #gemset created /usr/local/rvm/gems/ruby-2.5.1@global
    ruby-2.5.1 - #importing gemset /usr/local/rvm/gemsets/global.gems..............................
    ruby-2.5.1 - #generating global wrappers........
    ruby-2.5.1 - #gemset created /usr/local/rvm/gems/ruby-2.5.1
    ruby-2.5.1 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
    ruby-2.5.1 - #generating default wrappers........

使用某个Ruby版本:

# rvm use 2.5.1
 
     Using /usr/local/rvm/gems/ruby-2.5.1

设置默认版本:

#rvm use 2.5.1 --default
 
    Using /usr/local/rvm/gems/ruby-2.5.1

卸载某个已知ruby版本:

#rvm remove 2.5.1

查看ruby版本:

[root@localhost redis]# ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]

至此,ruby版本已经升级至2.5.1,可以使用gem安装redis了

# gem install redis
 
    Fetching: redis-4.0.1.gem (100%)
    Successfully installed redis-4.0.1
    Parsing documentation for redis-4.0.1
    Installing ri documentation for redis-4.0.1
    Done installing documentation for redis after 3 seconds
    1 gem installed

安装redis成功

# yum install -y rubygems
 
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
base                                                                                                                                                   | 3.7 kB     00:00     
didi_jenkins_enable                                                                                                                                    | 1.5 kB     00:00     
didi_op_toa_enable                                                                                                                                     | 1.5 kB     00:00     
didi_txjenkins_enable                                                                                                                                  | 1.5 kB     00:00     
didi_update                                                                                                                                            | 1.5 kB     00:00     
epel                                                                                                                                                   | 4.3 kB     00:00     
extras                                                                                                                                                 | 3.4 kB     00:00     
tmprepo                                                                                                                                                | 1.5 kB     00:00     
updates                                                                                                                                                | 3.4 kB     00:00     
Package rubygems-1.3.7-5.el6.noarch already installed and latest version
Nothing to do

安装rubygems,成功!

至此,我们的Ruby和运行redis-trib.rb需要的环境安装完成了。