Redis cluster搭建

所需软件
  • 1、redis-3.X.X版本即可 redis-3.2.1.tar.gz
  • 2、tcl 8.5以上版本  tcl8.6.1-src.tar.gz 
  • 3、ruby-redis redis-3.0.0.gem gem install redis-3.0.0.gem 
  • 4、gcc
  • 5、ruby1.8.7 http://storysky.blog.51cto.com/628458/1155353/

安装redis
  • 1、安装之前先看看环境下的gcc,tcl,ruby等版本
  • 2、把压缩包放到/apps/svr下:
  • 1)、tar -xzvf redis-3.2.1.tar.gz redis-3.2.1
  • 2)、cd redis-3.2.1 && make -j  && make test(安装过程中肯会出现错误,一般是gcc版本或者是tcl版本的问题,按照好高版本的gcc,tcl即可)
  • 3)、redis-server在redis-3.2.1/src/文件夹下面,所以需要把这个配置到环境变量里面,然后source /etc/profile
  • 4)、查看redis版本: redis-cli -v 

Redis cluster 配置

  • 1、这里搭建一个3个节点,每个节点一主一从的集群。因此需要创建6个redis实例
  • 2、创建文件夹 /apps/svr/redis-cluster/cluster1,在此文件夹下创建6个以端口命名的文件夹,这里是8001~8006.
  • 3、把redis-3.2.1下的redis.conf文件复制到每个端口对应的文件夹下。redis.conf需要修改的地方有:
    • port 8001             //port就是redis启动的时候的端口,即8001~8006
      cluster-enabled yes
      cluster-config-file nodes.conf  //可以统一设置为nodes.conf,启动redis实例之后,就会在对应的端口文件夹下生产一个nodes.conf文件
      cluster-node-timeout 15000
      appendonly yes
  • 4、将/apps/svr/redis-3.2.1/utils/create-cluster/create-cluster复制到/apps/svr/redis-cluster/cluster1
  • 5、修改create-cluster
  • #!/bin/bash
    
    # Settings
    PORT=8000
    TIMEOUT=2000
    NODES=6
    REPLICAS=1
    
    # You may want to put the above config parameters into config.sh in order to
    # override the defaults without modifying this script.
    
    if [ -a config.sh ]
    then
        source "config.sh"
    fi
    
    # Computed vars
    ENDPORT=$((PORT+NODES))
    
    if [ "$1" == "start" ]
    then
        while [ $((PORT < ENDPORT)) != "0" ]; do
            PORT=$((PORT+1))
            echo "Starting $PORT"
            redis-server /apps/svr/redis-cluster/cluster1/$PORT/redis.conf --port $PORT --cluster-enabled yes --cluster-config-file nodes-${PORT}.conf --cluster-node-timeout $TIMEOUT --appendonly yes --appendfilename appendonly-${PORT}.aof --dbfilename dump-${PORT}.rdb --logfile ${PORT}.log --daemonize yes
        done
        exit 0
    fi
    
    if [ "$1" == "create" ]
    then
        HOSTS=""
        while [ $((PORT < ENDPORT)) != "0" ]; do
            PORT=$((PORT+1))
            HOSTS="$HOSTS 127.0.0.1:$PORT"
        done
        /apps/svr/redis-3.2.1/redis-trib.rb create --replicas $REPLICAS $HOSTS
        exit 0
    fi
    
    ......
  • 6、启动集群实例:./create-cluster start
  • Starting 8001
    Starting 8002
    Starting 8003
    Starting 8004
    Starting 8005
    Starting 8006
  • 7、创建集群:./create-cluster create
  • >>> Creating cluster
    >>> Performing hash slots allocation on 6 nodes...
    Using 3 masters:
    127.0.0.1:8001
    127.0.0.1:8002
    127.0.0.1:8003
    Adding replica 127.0.0.1:8004 to 127.0.0.1:8001
    Adding replica 127.0.0.1:8005 to 127.0.0.1:8002
    Adding replica 127.0.0.1:8006 to 127.0.0.1:8003
    M: 098ab4079e2a19c49a402b4e5f3c302c5cd0b69c 127.0.0.1:8001
       slots:0-5460 (5461 slots) master
    M: ec8aea8b02008eb1da3e0c9831e98bdbc42ce1a7 127.0.0.1:8002
       slots:5461-10922 (5462 slots) master
    M: 6604af1df2e8cf852b1ea38a992066dcbf8a9a89 127.0.0.1:8003
       slots:10923-16383 (5461 slots) master
    S: ac2ae41ce7210ac2960e8f45f46b7836f834511f 127.0.0.1:8004
       replicates 098ab4079e2a19c49a402b4e5f3c302c5cd0b69c
    S: 9caf7504b133f8bb24107e64c895e53ba25e408e 127.0.0.1:8005
       replicates ec8aea8b02008eb1da3e0c9831e98bdbc42ce1a7
    S: c46b1e12fa999f2b787e3f006201569052c6a326 127.0.0.1:8006
       replicates 6604af1df2e8cf852b1ea38a992066dcbf8a9a89
    Can I set the above configuration? (type 'yes' to accept): yes
    >>> Nodes configuration updated
    >>> Assign a different config epoch to each node
    >>> Sending CLUSTER MEET messages to join the cluster
    Waiting for the cluster to join.
    >>> Performing Cluster Check (using node 127.0.0.1:8001)
    M: 098ab4079e2a19c49a402b4e5f3c302c5cd0b69c 127.0.0.1:8001
       slots:0-5460 (5461 slots) master
    M: ec8aea8b02008eb1da3e0c9831e98bdbc42ce1a7 127.0.0.1:8002
       slots:5461-10922 (5462 slots) master
    M: 6604af1df2e8cf852b1ea38a992066dcbf8a9a89 127.0.0.1:8003
       slots:10923-16383 (5461 slots) master
    M: ac2ae41ce7210ac2960e8f45f46b7836f834511f 127.0.0.1:8004
       slots: (0 slots) master
       replicates 098ab4079e2a19c49a402b4e5f3c302c5cd0b69c
    M: 9caf7504b133f8bb24107e64c895e53ba25e408e 127.0.0.1:8005
       slots: (0 slots) master
       replicates ec8aea8b02008eb1da3e0c9831e98bdbc42ce1a7
    M: c46b1e12fa999f2b787e3f006201569052c6a326 127.0.0.1:8006
       slots: (0 slots) master
       replicates 6604af1df2e8cf852b1ea38a992066dcbf8a9a89
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
  • 8、查看集群:./create-cluster watch
  • Tue Jul 19 14:13:56 CST 2016
    098ab4079e2a19c49a402b4e5f3c302c5cd0b69c 127.0.0.1:8001 myself,master - 0 0 1 connected 0-5460
    ec8aea8b02008eb1da3e0c9831e98bdbc42ce1a7 127.0.0.1:8002 master - 0 1468908835878 2 connected 5461-10922
    6604af1df2e8cf852b1ea38a992066dcbf8a9a89 127.0.0.1:8003 master - 0 1468908835878 3 connected 10923-16383
    9caf7504b133f8bb24107e64c895e53ba25e408e 127.0.0.1:8005 slave ec8aea8b02008eb1da3e0c9831e98bdbc42ce1a7 0 1468908836679 5 connected
    ac2ae41ce7210ac2960e8f45f46b7836f834511f 127.0.0.1:8004 slave 098ab4079e2a19c49a402b4e5f3c302c5cd0b69c 0 1468908836679 4 connected
    c46b1e12fa999f2b787e3f006201569052c6a326 127.0.0.1:8006 slave 6604af1df2e8cf852b1ea38a992066dcbf8a9a89 0 1468908835878 6 connected
  • 9、stop集群:./create-cluster stop
  • Stopping 8001
    Stopping 8002
    Stopping 8003
    Stopping 8004
    Stopping 8005
    Stopping 8006


发布了7 篇原创文章 · 获赞 1 · 访问量 1万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览