Redis集群环境安装指南

系统 2023 0

Redis集群环境安装指南

环境

RHLinux-6.4-64-EN, 红帽6.4 64位,英文正式公布版。

Redis3.0.0

  • redis2.x版本号还不支持集群,3.0版本号将会支持,如今3.0版本号还在开发中,如今是beta-3版本号(截止2014-5-8),但功能是可用的。
  • 下载Redis3.0.0 beta-3版本号,点击 这里 下载。
  • Redis3的安装能够參照之前的 单机安装指南 操作。

创建Redis集群实例

  • 创建集群节点的目录,先创建cluster-test目录,再以port为名称创建子目录。这里我们要创建6个Redis实例,3个作为master,3个作为slave。
                
                  1
                
                
                  2
                
                
                  3
                
              
                
                  
                    mkdir cluster-test 
                  
                  
                    
                      cd 
                    
                    cluster-test 
                  
                  
                    mkdir 7000 7001 7002 7003 7004 7005 
                  
                
              
  • 在每一个目录以下创建创建Redis配置文件,注意依据不同实例的port号改动以下的配置文件,nodes.conf文件为Redis实例启动时自己主动生成。
                
                  1
                
                
                  2
                
                
                  3
                
                
                  4
                
                
                  5
                
              
                
                  
                    port 7000 
                  
                  
                    cluster-enabled yes 
                  
                  
                    cluster-config-file nodes.conf 
                  
                  
                    cluster-node-timeout 5000 
                  
                  
                    appendonly yes 
                  
                
              
  • 开6个terminal窗体,分别启动这6个Redis实例。
                
                  1
                
                
                  2
                
              
                
                  
                    
                      cd 
                    
                    7000 
                  
                  
                    ../redis-server ./redis.conf 
                  
                
              
  • 当成功启动后,能看到每一个terminal出现以下的字样,是由于node.conf文件不存在,所以给每一个实例分配了一个新的ID。
                
                  1
                
              
                
                  
                    [
                  
                  82462
                  
                    ]
                  
                   26 Nov 11:56:55.329 * No cluster configuration found, I
                  
                    '
                  
                  m 97a3a64667477371c4479320d683e4c8db5858b1

                
              

创建集群

  • 如今Redis的6个实例都已经启动了,如今来開始创建集群。创建集群用到了一个ruby文件,放在redis3文件夹的src子文件夹下,找到后运行下面命令。这里的 -replicas 1 表示每一个master配备1个slave,后面的參数就是6个实例的ip加port,以空格隔开。
                
                  1
                
                
                  2
                
                
                  3
                
              
                
                  
                    
                      cd 
                    
                    redis-3.0.0-beta3/src 
                  
                  
                    ./redis-trib.rb create --replicas 1 127.0.0.1:7000 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 
                  
                
              
  • 运行命令后会提示你是否接受提示的配置信息,默认的是前3台作为master机器,后3台作为slave机器,输入 yes ,出现最后的信息表示集群已经创建好了。
                
                  1
                
                
                  2
                
                
                  3
                
                
                  4
                
                
                  5
                
                
                  6
                
                
                  7
                
                
                  8
                
                
                  9
                
                
                  10
                
                
                  11
                
                
                  12
                
                
                  13
                
                
                  14
                
                
                  15
                
                
                  16
                
                
                  17
                
                
                  18
                
                
                  19
                
                
                  20
                
                
                  21
                
                
                  22
                
                
                  23
                
                
                  24
                
                
                  25
                
                
                  26
                
                
                  27
                
                
                  28
                
                
                  29
                
                
                  30
                
                
                  31
                
                
                  32
                
                
                  33
                
                
                  34
                
                
                  35
                
                
                  36
                
                
                  37
                
                
                  38
                
                
                  39
                
                
                  40
                
                
                  41
                
                
                  42
                
              
                
                  
                    Creating cluster 
                  
                  
                    Connecting to node 127.0.0.1:7000: OK 
                  
                  
                    Connecting to node 127.0.0.1:7001: OK 
                  
                  
                    Connecting to node 127.0.0.1:7002: OK 
                  
                  
                    Connecting to node 127.0.0.1:7003: OK 
                  
                  
                    Connecting to node 127.0.0.1:7004: OK 
                  
                  
                    Connecting to node 127.0.0.1:7005: OK >>> 
                  
                  
                    Performing 
                    
                      hash 
                    
                    slots allocation on 6 nodes... 
                  
                  
                    Using 3 masters: 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 
                  
                  
                    127.0.0.1:7000 replica 
                    
                      #1 is 127.0.0.1:7003
                    
                  
                  
                    127.0.0.1:7001 replica 
                    
                      #1 is 127.0.0.1:7004
                    
                  
                  
                    127.0.0.1:7002 replica 
                    
                      #1 is 127.0.0.1:7005
                    
                  
                  
                    M: 9991306f0e50640a5684f1958fd754b38fa034c9 127.0.0.1:7000 slots:0-5460 
                    
                      (
                    
                    5461 slots
                    
                      )
                    
                     master 
                  
                  
                    M: e68e52cee0550f558b03b342f2f0354d2b8a083b 127.0.0.1:7001 slots:5461-10921 
                    
                      (
                    
                    5461 slots
                    
                      )
                    
                     master 
                  
                  
                    M: 393c6df5eb4b4cec323f0e4ca961c8b256e3460a 127.0.0.1:7002 slots:10922-16383 
                    
                      (
                    
                    5462 slots
                    
                      )
                    
                     master 
                  
                  
                    S: 48b728dbcedff6bf056231eb44990b7d1c35c3e0 127.0.0.1:7003 
                  
                  
                    S: 345ede084ac784a5c030a0387f8aaa9edfc59af3 127.0.0.1:7004 
                  
                  
                    S: 3375be2ccc321932e8853234ffa87ee9fde973ff 127.0.0.1:7005 
                  
                  
                    Can I 
                    
                      set 
                    
                    the above configuration? 
                    
                      (
                    
                    
                      type
                    
                    
                      'yes'
                    
                     to accept
                    
                      )
                    
                    : yes 
                  
                  
                  
                  
                    Nodes configuration updated >>> 
                  
                  
                    Sending CLUSTER MEET messages to join the cluster Waiting 
                    
                      for 
                    
                    the cluster to join... >>> 
                  
                  
                    Performing Cluster Check 
                    
                      (
                    
                    using node 127.0.0.1:7000
                    
                      )
                    
                  
                  
                    M: ebbb890e899244e4a2a6303826a29543ebf9885d 127.0.0.1:7000 
                  
                  
                     slots:0-5460 
                    
                      (
                    
                    5461 slots
                    
                      )
                    
                     master 
                  
                  
                    M: ebbb890e899244e4a2a6303826a29543ebf9885d 127.0.0.1:7001 
                  
                  
                     slots:5461-10922 
                    
                      (
                    
                    5462 slots
                    
                      )
                    
                     master 
                  
                  
                    M: 73c22198cd1d0782ec24e3c9b03378030891c9a3 127.0.0.1:7002 
                  
                  
                     slots:10923-16383 
                    
                      (
                    
                    5461 slots
                    
                      )
                    
                     master 
                  
                  
                    M: c785d85b95d7bdc28ec90384ab8a5885b289542c 127.0.0.1:7003 
                  
                  
                     slots: 
                    
                      (
                    
                    0 slots
                    
                      )
                    
                     master 
                  
                  
                     replicates b949ea2d9c822ff069521a354b4ed48855ac6203 
                  
                  
                    M: 570c472fe553ba3c9d0fb3ba16fcdb8579b4fc86 127.0.0.1:7004 
                  
                  
                     slots: 
                    
                      (
                    
                    0 slots
                    
                      )
                    
                     master 
                  
                  
                     replicates ebbb890e899244e4a2a6303826a29543ebf9885d 
                  
                  
                    M: f86667ec42cff41a5666162a912713173f5306d7 127.0.0.1:7005 
                  
                  
                     slots: 
                    
                      (
                    
                    0 slots
                    
                      )
                    
                     master 
                  
                  
                     replicates 73c22198cd1d0782ec24e3c9b03378030891c9a3 
                  
                  
                    
                      [
                    
                    OK
                    
                      ]
                    
                     All nodes agree about slots configuration. 
                  
                  
                    >>> Check 
                    
                      for 
                    
                    open slots... 
                  
                  
                    >>> Check slots coverage... 
                  
                  
                    
                      [
                    
                    OK
                    
                      ]
                    
                     All 16384 slots covered. 
                  
                
              

PS: 安装过程还发现RedHat系统上没有安装ruby,须要先安装ruby,并且公司机器还不能上网下载安装,仅仅能通过离线的方式安装ruby,这里有离线安装的文档能够參考一下: https://rvm.io/rvm/offline

验证

能够使用Redis3.0的redis-cliclient进行验证,须要加上 -c 參数,表示集群的意思。

                
                  1
                
                
                  2
                
                
                  3
                
                
                  4
                
                
                  5
                
                
                  6
                
                
                  7
                
                
                  8
                
                
                  9
                
                
                  10
                
                
                  11
                
                
                  12
                
                
                  13
                
              
                
                  
                    
                      $ 
                    
                    redis-cli -c -p 7000 
                  
                  
                    redis 127.0.0.1:7000> 
                    
                      set 
                    
                    foo bar 
                  
                  
                    -> Redirected to slot 
                    
                      [
                    
                    12182
                    
                      ]
                    
                     located at 127.0.0.1:7002 
                  
                  
                    OK 
                  
                  
                    redis 127.0.0.1:7002> 
                    
                      set 
                    
                    hello world 
                  
                  
                    -> Redirected to slot 
                    
                      [
                    
                    866
                    
                      ]
                    
                     located at 127.0.0.1:7000 
                  
                  
                    OK 
                  
                  
                    redis 127.0.0.1:7000> get foo 
                  
                  
                    -> Redirected to slot 
                    
                      [
                    
                    12182
                    
                      ]
                    
                     located at 127.0.0.1:7002 
                  
                  
                    
                      "bar"
                    
                  
                  
                    redis 127.0.0.1:7000> get hello 
                  
                  
                    -> Redirected to slot 
                    
                      [
                    
                    866
                    
                      ]
                    
                     located at 127.0.0.1:7000 
                  
                  
                    
                      "world"
                    
                  
                
              

很多其它的资料能够參考这里: http://redis.io/topics/cluster-tutorial

Redis集群环境安装指南


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论