• Redis cluster


    http://redis.io/topics/cluster-tutorial

    http://www.redis.cn/topics/cluster-tutorial.html

    Creating a Redis Cluster using the create-cluster script

    If you don't want to create a Redis Cluster by configuring and executing individual instances manually as explained above, there is a much simpler system (but you'll not learn the same amount of operational details).

    Just check utils/create-cluster directory in the Redis distribution. There is a script called create-cluster inside (same name as the directory it is contained into), it's a simple bash script. In order to start a 6 nodes cluster with 3 masters and 3 slaves just type the following commands:

    1. create-cluster start
    2. create-cluster create

    Reply to yes in step 2 when the redis-trib utility wants you to accept the cluster layout.

    You can now interact with the cluster, the first node will start at port 30001 by default. When you are done, stop the cluster with:

    1. create-cluster stop.

    Please read the README inside this directory for more information on how to run the script.

    可能会出现错误:

    /usr/bin/env: ruby: No such file or directory

    解决办法:

    yum install ruby

    可能会出现:

    ../../src/redis-trib.rb:24:in `require': no such file to load -- rubygems (LoadError)
    from ../../src/redis-trib.rb:24

    解决办法:

    yum install rubygems

    可能会出现:

    /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- redis (LoadError)
    from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from ../../src/redis-trib.rb:25

    解决办法:

    gem install redis

    [root@VM_7_88_centos create-cluster]# gem sources
    *** CURRENT SOURCES ***
    
    https://rubygems.org/
    [root@VM_7_88_centos create-cluster]# gem sources --remove https://rubygems.org/
    https://rubygems.org/ removed from sources
    [root@VM_7_88_centos create-cluster]# gem sources -a https://ruby.taobao.org/
    https://ruby.taobao.org/ added to sources
    gem 默认源ping 不通,切换淘宝gem 源
    Successfully installed redis-3.2.2
    1 gem installed
    Installing ri documentation for redis-3.2.2...
    Installing RDoc documentation for redis-3.2.2...

    好了!

    [root@AY1407171850011464e3Z create-cluster]# sh create-cluster create
    >>> Creating cluster
    >>> Performing hash slots allocation on 6 nodes...
    Using 3 masters:
    127.0.0.1:30001
    127.0.0.1:30002
    127.0.0.1:30003
    Adding replica 127.0.0.1:30004 to 127.0.0.1:30001
    Adding replica 127.0.0.1:30005 to 127.0.0.1:30002
    Adding replica 127.0.0.1:30006 to 127.0.0.1:30003
    M: 97700d3c5acf79f80fb7dbf237ba7315c29ab339 127.0.0.1:30001
       slots:0-5460 (5461 slots) master
    M: dcf9a309c34eb5bcc29eb82595d60fd71f17b623 127.0.0.1:30002
       slots:5461-10922 (5462 slots) master
    M: 7e1b46f4269d0b5eed4b2e412e62ba4dbd52dfc3 127.0.0.1:30003
       slots:10923-16383 (5461 slots) master
    S: aa586a89ed2360262b1f107be633ceab12bac838 127.0.0.1:30004
       replicates 97700d3c5acf79f80fb7dbf237ba7315c29ab339
    S: 4bb606254834745d7cf513b87cb004140462c29c 127.0.0.1:30005
       replicates dcf9a309c34eb5bcc29eb82595d60fd71f17b623
    S: dc1bb14d2056a0e81b4092f98cdc948111bcba63 127.0.0.1:30006
       replicates 7e1b46f4269d0b5eed4b2e412e62ba4dbd52dfc3
    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:30001)
    M: 97700d3c5acf79f80fb7dbf237ba7315c29ab339 127.0.0.1:30001
       slots:0-5460 (5461 slots) master
    M: dcf9a309c34eb5bcc29eb82595d60fd71f17b623 127.0.0.1:30002
       slots:5461-10922 (5462 slots) master
    M: 7e1b46f4269d0b5eed4b2e412e62ba4dbd52dfc3 127.0.0.1:30003
       slots:10923-16383 (5461 slots) master
    M: aa586a89ed2360262b1f107be633ceab12bac838 127.0.0.1:30004
       slots: (0 slots) master
       replicates 97700d3c5acf79f80fb7dbf237ba7315c29ab339
    M: 4bb606254834745d7cf513b87cb004140462c29c 127.0.0.1:30005
       slots: (0 slots) master
       replicates dcf9a309c34eb5bcc29eb82595d60fd71f17b623
    M: dc1bb14d2056a0e81b4092f98cdc948111bcba63 127.0.0.1:30006
       slots: (0 slots) master
       replicates 7e1b46f4269d0b5eed4b2e412e62ba4dbd52dfc3
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.

    最后设置自动启动:

    ① 修改文件rc.local

    vi /etc/rc.local

    添加这两行

    export REDIS_HOME=/usr/local/redis-stable
    $REDIS_HOME/utils/create-cluster/create-cluster start
    
    $REDIS_HOME/src/redis-server &  这行不需要,因为是集群
    $REDIS_HOME/utils/create-cluster/create-cluster create  这行也不需要,create 一次以后只需start   

    ② 修改 create-cluster 文件 (注意.conf 和.log 文件相对路径问题,见 http://www.cnblogs.com/zno2/p/5303398.html

    将全部相对路径修改为环境变量

    ../../src    ===========>       $REDIS_HOME/src

  • 相关阅读:
    CS round--36
    Vijos 1002 过河 dp + 思维
    汇编模拟36选7
    1137
    E. Mike and Foam 容斥原理
    Even-odd Boxes hackerrank 分类讨论
    112. 作业之地理篇 最小费用最大流模板题
    1550: Simple String 最大流解法
    Sam's Numbers 矩阵快速幂优化dp
    java.sql.SQLSyntaxErrorException: ORA-01722: 无效数字
  • 原文地址:https://www.cnblogs.com/zno2/p/5302916.html
Copyright © 2020-2023  润新知