Redis 3.0集群搭建/配置/FAQ

系统 2022 0

·声明

1,已官网中文教程为基础,边看边学,结合环境现状搭建。

2,哥对Ruby不热爱、不熟悉、不感冒,所述内容如有疑义请谅解。

3,3.0官说集群还在测试中,其实用用也还算马马虎虎,对外集群API真心少,望有识之士能够出力。

 

·准备材料

VM9,CentOS 6.4_x86_64(2.6+),SecureCRT,CentOS-6.4-x86_64-bin-DVD1.iso

redis官网:redis-3.0.0-beta1.tar.gz

ruby官网:rubygems-2.0.7.zip

rubygem官网:redis-3.0.7.gem

 

·下锅

1,把一些基础包装一下,后面会用到

service iptables stop

放入DVD1-

yum install –y gcc*

yum install –y ruby

yum install –y ruby-rdoc

2,装redis

tar -xvf redis-3.0.0-beta1.tar.gz

cd redis-3.0.0-beta

make

make install

ll /usr/local/bin

3,配置集群(假定 $REDIS_HOME=/root/soft/redis,就像ORACLE_HOME一样)

cd $REDIS_HOME

mkdir cluster-test

cd cluster-test

mkdir 7000 7001 7002 7003 7004 7005

vim redis.conf,修改内容如下:

port 7000 个性化

      cluster-
      
        enabled yes

cluster
      
      -config-file nodes.
      
        7000
      
      
        .conf 个性化

cluster
      
      -node-timeout 
      
        5000
      
      
        

appendonly yes

appendfilename 
      
      
        "
      
      
        appendonly.7000.aof
      
      
        "
      
      
         个性化

deamonize yes

pidfile 个性化

log 个性化
      
    

 

cp ../redis.conf ./7000

cp ../redis.conf ./7001

cp ../redis.conf ./7002

cp ../redis.conf ./7003

cp ../redis.conf ./7004

cp ../redis.conf ./7005

cp /usr/local/bin/redis-server ./7000

cp /usr/local/bin/redis-server ./7001

cp /usr/local/bin/redis-server ./7002

cp /usr/local/bin/redis-server ./7003

cp /usr/local/bin/redis-server ./7004

cp /usr/local/bin/redis-server ./7005

/root/soft/redis/cluster-test/redis-server /root/soft/redis/cluster-test/7000/redis.conf

/root/soft/redis/cluster-test/redis-server /root/soft/redis/cluster-test/7001/redis.conf

/root/soft/redis/cluster-test/redis-server /root/soft/redis/cluster-test/7002/redis.conf

/root/soft/redis/cluster-test/redis-server /root/soft/redis/cluster-test/7003/redis.conf

/root/soft/redis/cluster-test/redis-server /root/soft/redis/cluster-test/7004/redis.conf

/root/soft/redis/cluster-test/redis-server /root/soft/redis/cluster-test/7005/redis.conf

如果需要看一看:ps –ef|grep redis

如果需要杀一杀:ps -ef|grep redis|egrep -v grep|awk -F ' ' '{print $2}'|xargs kill -9

4,配置ruby集群脚本

cd /root/soft/rubygems

ruby setup.rb

到redis-3.0.7.gem路径下

gem install -l redis(不用L的话,走ruby官网,95%被WALL,你懂得,自己改source吧)

./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7002 127.0.0.3:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7005(半路记得“yes"一下)

      >>>
      
         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: bc66d90ca24eb6b69a3b375a4e242fef00de2052 
      
      
        127.0
      
      .
      
        0.1
      
      :
      
        7000
      
      
        

   slots:
      
      
        0
      
      -
      
        5460
      
       (
      
        5461
      
      
         slots) master

M: bc66d90ca24eb6b69a3b375a4e242fef00de2052 
      
      
        127.0
      
      .
      
        0.1
      
      :
      
        7001
      
      
        

   slots:
      
      
        5461
      
      -
      
        10921
      
       (
      
        5461
      
      
         slots) master

M: bc66d90ca24eb6b69a3b375a4e242fef00de2052 
      
      
        127.0
      
      .
      
        0.1
      
      :
      
        7002
      
      
        

   slots:
      
      
        10922
      
      -
      
        16383
      
       (
      
        5462
      
      
         slots) master

S: bc66d90ca24eb6b69a3b375a4e242fef00de2052 
      
      
        127.0
      
      .
      
        0.1
      
      :
      
        7003
      
      
        

   replicates bc66d90ca24eb6b69a3b375a4e242fef00de2052

S: bc66d90ca24eb6b69a3b375a4e242fef00de2052 
      
      
        127.0
      
      .
      
        0.1
      
      :
      
        7004
      
      
        

   replicates bc66d90ca24eb6b69a3b375a4e242fef00de2052

S: bc66d90ca24eb6b69a3b375a4e242fef00de2052 
      
      
        127.0
      
      .
      
        0.1
      
      :
      
        7005
      
      
        

   replicates bc66d90ca24eb6b69a3b375a4e242fef00de2052

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: 75bab28893c3536aecdb9879df97db89b24ce21e 
      
      
        127.0
      
      .
      
        0.1
      
      :
      
        7000
      
      
        

   slots:
      
      
        5461
      
      -
      
        10921
      
       (
      
        5461
      
      
         slots) master

M: cfc344721cad8a5ddb7a8d675eb3a4d6e5b9d1c1 
      
      
        127.0
      
      .
      
        0.1
      
      :
      
        7002
      
      
        

   slots:
      
      
        10922
      
      -
      
        16383
      
       (
      
        5462
      
      
         slots) master

M: 01b3977a3f592fd1538e8c83f86bbba37d0c1058 
      
      
        127.0
      
      .
      
        0.3
      
      :
      
        7003
      
      
        

   slots:
      
      
        0
      
      -
      
        5460
      
       (
      
        5461
      
      
         slots) master

M: df59fce238a1c538933bdc170edb27835d0b7cc7 
      
      
        127.0
      
      .
      
        0.1
      
      :
      
        7004
      
      
        

   slots: (
      
      
        0
      
      
         slots) master

   replicates 01b3977a3f592fd1538e8c83f86bbba37d0c1058

M: b6bdb2d309aa7f0b810288f24e975230419f25b1 
      
      
        127.0
      
      .
      
        0.1
      
      :
      
        7005
      
      
        

   slots: (
      
      
        0
      
      
         slots) master

   replicates 75bab28893c3536aecdb9879df97db89b24ce21e

M: b6bdb2d309aa7f0b810288f24e975230419f25b1 
      
      
        127.0
      
      .
      
        0.1
      
      :
      
        7005
      
      
        

   slots: (
      
      
        0
      
      
         slots) master

   replicates cfc344721cad8a5ddb7a8d675eb3a4d6e5b9d1c1

[OK] All nodes agree about slots configuration.


      
      >>> Check 
      
        for
      
      
         open slots...


      
      >>>
      
         Check slots coverage...

[OK] All 
      
      
        16384
      
       slots covered.
    

  redis-cli -c -p 7000

      
        127.0
      
      .
      
        0.1
      
      :
      
        7000
      
      > 
      
        set
      
      
         b c


      
      -> Redirected to slot [
      
        3300
      
      ] located at 
      
        127.0
      
      .
      
        0.1
      
      :
      
        7003
      
      
        

OK


      
      
        127.0
      
      .
      
        0.1
      
      :
      
        7003
      
      > 
      
        set
      
      
         hello world

OK


      
      
        127.0
      
      .
      
        0.1
      
      :
      
        7003
      
      > 
      
        get
      
      
         foo


      
      -> Redirected to slot [
      
        12182
      
      ] located at 
      
        127.0
      
      .
      
        0.1
      
      :
      
        7002
      
      
        

(nil)


      
      
        127.0
      
      .
      
        0.1
      
      :
      
        7002
      
      > 
      
        get
      
      
         hello


      
      -> Redirected to slot [
      
        866
      
      ] located at 
      
        127.0
      
      .
      
        0.1
      
      :
      
        7003
      
      
        "
      
      
        world
      
      
        "
      
      
        127.0
      
      .
      
        0.1
      
      :
      
        7003
      
      > 
      
        get
      
      
         b


      
      
        "
      
      
        c
      
      
        "
      
      
        127.0
      
      .
      
        0.1
      
      :
      
        7003
      
      > 
    

 

·FAQ

      *** ERROR: Invalid configuration 
      
        for
      
      
         cluster creation.




      
      *** Redis Cluster requires at least 
      
        3
      
      
         master nodes.




      
      *** This 
      
        is
      
       not possible with 
      
        4
      
       nodes and 
      
        1
      
      
         replicas per node.




      
      *** At least 
      
        6
      
       nodes are required.
    

 

·Redis官说,至少3+3,还延续着Master-Slave的设计理念,这点上个人觉得Cassandra的一致性确实了得。

 

      Either the node already knows other nodes
    

 

·因为报错是ruby报的,不太能够理解其意思,因为我之前做了些单机压测,可能直接叠上集群会有垃圾数据,所以把/var/db/和/var/log/下能清空的都清空了。

 

      [
      
        13321
      
      ] 
      
        09
      
       Mar 
      
        08
      
      :
      
        09
      
      :
      
        24.290
      
       # Handshake error: we already know node bc66d90ca24eb6b69a3b375a4e242fef00de2052, updating the address 
      
        if
      
       needed.
    

 

·同样道理,ruby报的错,一开始一直在join被我ctrl+c之后开始报错,用上面的方法无果。把所有app目录清空然后redis重装。大家测试时,最后事先vmware快照一下或者redis现网数据备份一下。

 

·OK,自己爽一下吧

 

Redis 3.0集群搭建/配置/FAQ


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

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

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

【本文对您有帮助就好】

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

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