Redis 集群环境安装

本贴最后更新于 2069 天前,其中的信息可能已经物是人非

<font size=4>集群管理工具: redis-trib.rb

redis-trib.rb 是 redis 官方推出的用 Ruby 开发的 redis 集群的工具,集成在源码包的 src 目录下,redis 集群需要先安装 ruby 环境。

工具介绍

gem:Ruby 第三方插件、模块管理工具
rvm:Ruby 多版本环境的切换、管理工具

1.安装 Ruby 环境

``` [root@linkdood ~]# yum install -y ruby rubygems #(ruby软件包管理器) [root@linkdood ~]# ruby --version #查询ruby当前版本,安装gem插件要求ruby版本>=2.2.2 ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux] ```

2.安装 Redis 插件

``` [root@linkdood src]# gem install redis ERROR: Error installing redis: redis requires Ruby version >= 2.2.2. #要求Ruby版本>=2.2.2 ``` ## 3.升级Ruby版本 ### 3.1.源码安装新版本

3.3.rvm 安装新版本

<font size=4> 安装 rvm 管理工具

[root@linkdood src]# curl -L get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 24361  100 24361    0     0   7836      0  0:00:03  0:00:03 --:--:-- 14279
Downloading https://github.com/rvm/rvm/archive/1.29.4.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.4/1.29.4.tar.gz.asc
gpg: Signature made Mon 02 Jul 2018 03:41:26 AM CST using RSA key ID BF04FF17
gpg: Can't check signature: No public key
Warning, RVM 1.26.0 introduces signed releases and automated check of signatures when GPG software found. Assuming you trust Michal Papis import the mpapis public key (downloading the signatures).

GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.29.4.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.4/1.29.4.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:

    gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

or if it fails:

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

the key can be compared with:

    https://rvm.io/mpapis.asc
    https://keybase.io/mpapis

NOTE: GPG version 2.1.17 have a bug which cause failures during fetching keys from remote server. Please downgrade or upgrade to newer version (if available) or use the second method described above.	

导入公钥,并继续安装

[root@linkdood src]#  curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
gpg: key D39DC0E3: public key "Michal Papis (RVM signing) <mpapis@gmail.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
gpg: no ultimately trusted keys found


[root@linkdood src]# curl -L get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 24361  100 24361    0     0   3780      0  0:00:06  0:00:06 --:--:-- 10.8M
Downloading https://github.com/rvm/rvm/archive/1.29.4.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.4/1.29.4.tar.gz.asc
gpg: Signature made Mon 02 Jul 2018 03:41:26 AM CST using RSA key ID BF04FF17
gpg: Good signature from "Michal Papis (RVM signing) <mpapis@gmail.com>"
gpg:                 aka "Michal Papis <michal.papis@toptal.com>"
gpg:                 aka "[jpeg image of size 5015]"
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 409B 6B17 96C2 7546 2A17  0311 3804 BB82 D39D C0E3
     Subkey fingerprint: 62C9 E5F4 DA30 0D94 AC36  166B E206 C29F BF04 FF17
GPG verified '/usr/local/rvm/archives/rvm-1.29.4.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!》```

执行命令

source /etc/profile.d/rvm.sh

重新打开 session,查询可用版本

[root@linkdood ~]# 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[.7]
[ruby-]2.4[.4]
[ruby-]2.5[.1]
[ruby-]2.6[.0-preview2]
ruby-head

# for forks use: rvm install ruby-head-<name> --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.0.0]
jruby-head

# Rubinius
rbx-1[.4.3]
rbx-2.3[.0]
rbx-2.4[.1]
rbx-2[.5.8]
rbx-3[.100]
rbx-head

# TruffleRuby
truffleruby[-1.0.0-rc2]

# Opal
opal

# Minimalistic ruby implementation - ISO 30170:2012
mruby-1.0.0
mruby-1.1.0
mruby-1.2.0
mruby-1.3.0
mruby-1[.4.0]
mruby[-head]

# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]

# Topaz
topaz

# MagLev
maglev-1.0.0
maglev-1.1[RC1]
maglev[-1.2Alpha4]
maglev-head

# Mac OS X Snow Leopard Or Newer
macruby-0.10
macruby-0.11
macruby[-0.12]
macruby-nightly
macruby-head

# IronRuby
ironruby[-1.1.3]
ironruby-head

安装 Ruby2.4.0 版本

[root@linkdood ~]# rvm install  2.4.0
Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/centos/6/x86_64/ruby-2.4.0.tar.bz2
Checking requirements for centos.
Installing requirements for centos.
Installing required packages: libffi-devel, sqlite-devel...............
Requirements installation successful.
ruby-2.4.0 - #configure
ruby-2.4.0 - #download
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 15.5M  100 15.5M    0     0  23607      0  0:11:30  0:11:30 --:--:-- 39323
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.4.0 - #validate archive
ruby-2.4.0 - #extract
ruby-2.4.0 - #validate binary
Libraries missing for ruby-2.4.0: libyaml-0.so.2. Refer to your system manual for installing libraries
Mounting remote ruby failed with status 10, trying to compile.
Checking requirements for centos.
Requirements installation successful.
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-2.4.0, this may take a while depending on your cpu(s)...
ruby-2.4.0 - #downloading ruby-2.4.0, 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 11.9M  100 11.9M    0     0  13912      0  0:15:03  0:15:03 --:--:-- 16099
ruby-2.4.0 - #extracting ruby-2.4.0 to /usr/local/rvm/src/ruby-2.4.0.....
ruby-2.4.0 - #applying patch /usr/local/rvm/patches/ruby/2.4.0/ruby_2_4_gcc7.patch.
ruby-2.4.0 - #applying patch /usr/local/rvm/patches/ruby/2.4.0/random_c_using_NR_prefix.patch.
ruby-2.4.0 - #configuring..................................................................
ruby-2.4.0 - #post-configuration..
ruby-2.4.0 - #compiling............................................|
..........................................................
ruby-2.4.0 - #installing.........................
ruby-2.4.0 - #making binaries executable..
ruby-2.4.0 - #downloading rubygems-2.7.7
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  894k  100  894k    0     0  24053      0  0:00:38  0:00:38 --:--:-- 14368
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.4.0 - #extracting rubygems-2.7.7....................................................................................................................................................................................................................................
ruby-2.4.0 - #removing old rubygems........
ruby-2.4.0 - #installing rubygems-2.7.7................................
ruby-2.4.0 - #gemset created /usr/local/rvm/gems/ruby-2.4.0@global
ruby-2.4.0 - #importing gemset /usr/local/rvm/gemsets/global.gems...................................................
ruby-2.4.0 - #generating global wrappers.......
ruby-2.4.0 - #gemset created /usr/local/rvm/gems/ruby-2.4.0
ruby-2.4.0 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.4.0 - #generating default wrappers.......
ruby-2.4.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.4.0 - #complete 
Please be aware that you just installed a ruby that requires 2 patches just to be compiled on an up to date linux system.
This may have known and unaccounted for security vulnerabilities.
Please consider upgrading to ruby-2.5.1 which will have all of the latest security patches.
Ruby was built without documentation, to build it run: rvm docs generate-ri

查询 Ruby 版本,已经升级到 2.4.0

[root@linkdood ~]# ruby --version
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]

4.安装 Redis 插件

>注意:这里默认安装了redis-4.0.2.gem,如果redis版本是3.2的。一定要注意安装的插件版本,否则在集群调整的时候会报错

安装默认版本

[root@linkdood ~]# gem install redis
Fetching: redis-4.0.2.gem (100%)
Successfully installed redis-4.0.2
Parsing documentation for redis-4.0.2
Installing ri documentation for redis-4.0.2
Done installing documentation for redis after 2 seconds
1 gem installed

安装指定版本

[root@linkdood src]# gem uninstall redis
Successfully uninstalled redis-4.0.1

[root@linkdood src]# gem install redis -v 3.3.5
Fetching: redis-3.3.5.gem (100%)
Successfully installed redis-3.3.5
Parsing documentation for redis-3.3.5
Installing ri documentation for redis-3.3.5
Done installing documentation for redis after 2 seconds
1 gem installed
## 5.插件版本导致的故障 ``` [root@linkdood src]# ./redis-trib.rb rebalance 127.0.0.1:7001 >>> Performing Cluster Check (using node 127.0.0.1:7001) [OK] All nodes agree about slots configuration. >>> Check for open slots... [WARNING] Node 127.0.0.1:7001 has slots in migrating state (449). [WARNING] Node 127.0.0.1:7007 has slots in importing state (449). [WARNING] The following slots are open: 449 >>> Check slots coverage... [OK] All 16384 slots covered. *** Please fix your cluster problems before rebalancing ``` 按照提示执行fix ``` [root@linkdood src]# ./redis-trib.rb fix 127.0.0.1:7001 >>> Performing Cluster Check (using node 127.0.0.1:7001) M: 61c43cb315147539f9caa87d0bc0d5a192bb9c02 127.0.0.1:7001 slots:449-5460 (5012 slots) master 1 additional replica(s) M: 25d28f19dfaf789d09c5dc091151388fafa63c7e 127.0.0.1:7007 slots:0-448,5461-6826,10923-12287 (3180 slots) master 1 additional replica(s) M: 8fb4e01999d75f2c0e305e9ea316aa0b057f0c60 127.0.0.1:7003 slots:12288-16383 (4096 slots) master 1 additional replica(s) S: 6a5dea4ff0e869f00321f10f42bb3da6ec69ff2e 127.0.0.1:7005 slots: (0 slots) slave replicates f54ccc62e76f51e387740188aa5f2321f299e8d2 S: 32870cdc5a156a58660d1d8d55c23a6fbc444ba0 127.0.0.1:7008 slots: (0 slots) slave replicates 25d28f19dfaf789d09c5dc091151388fafa63c7e S: 0623c55d544ad33d5f2eb7b90a1a45c29e081ad6 127.0.0.1:7006 slots: (0 slots) slave replicates 8fb4e01999d75f2c0e305e9ea316aa0b057f0c60 M: f54ccc62e76f51e387740188aa5f2321f299e8d2 127.0.0.1:7002 slots:6827-10922 (4096 slots) master 1 additional replica(s) S: d6e52443eb69eec219e1a3d27caaabb0b8a1e43b 127.0.0.1:7004 slots: (0 slots) slave replicates 61c43cb315147539f9caa87d0bc0d5a192bb9c02 [OK] All nodes agree about slots configuration. >>> Check for open slots... [WARNING] Node 127.0.0.1:7001 has slots in migrating state (449). [WARNING] Node 127.0.0.1:7007 has slots in importing state (449). [WARNING] The following slots are open: 449 >>> Fixing open slot 449 Set as migrating in: 127.0.0.1:7001 Set as importing in: 127.0.0.1:7007 Moving slot 449 from 127.0.0.1:7001 to 127.0.0.1:7007: [ERR] Calling MIGRATE: ERR Syntax error, try CLIENT (LIST | KILL | GETNAME | SETNAME | PAUSE | REPLY)
解决方法,卸载当前redis插件,安装与Redis版本匹配的插件

[root@linkdood src]# gem uninstall redis
Successfully uninstalled redis-4.0.1

[root@linkdood src]# gem install redis -v xxx
Fetching: redis-3.3.5.gem (100%)
Successfully installed redis-3.3.5
Parsing documentation for redis-3.3.5
Installing ri documentation for redis-3.3.5
Done installing documentation for redis after 2 seconds
1 gem installed

  • 服务

    提供一个服务绝不仅仅是简单的把硬件和软件累加在一起,它包括了服务的可靠性、服务的标准化、以及对服务的监控、维护、技术支持等。

    41 引用 • 24 回帖 • 3 关注
  • Redis

    Redis 是一个开源的使用 ANSI C 语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value 数据库,并提供多种语言的 API。从 2010 年 3 月 15 日起,Redis 的开发工作由 VMware 主持。从 2013 年 5 月开始,Redis 的开发由 Pivotal 赞助。

    284 引用 • 247 回帖 • 177 关注

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...