zoukankan      html  css  js  c++  java
  • 搭建redis集群

    官方详细介绍请移步:http://www.redis.cn/topics/cluster-tutorial.html

    这里总结性给出搭建步骤:

    1、 至少6个节点,三主三从

    2、 编译redis源码

    3、放置集群的配置文件redis.conf

    port 7000
    cluster-enabled yes
    cluster-config-file nodes.conf
    cluster-node-timeout 5000
    appendonly yes
    

    创建工作目录:

    mkdir cluster-test
    cd cluster-test
    mkdir 7000 7001 7002 7003 7004 7005
    

    每个文件夹下新建redis.conf 改变端口,把二进制redis-server复制到cluster-test

    tree /cluster-test/
    ├── 7000
    │?? └── redis.conf
    ├── 7001
    │?? └── redis.conf
    ├── 7002
    │?? └── redis.conf
    ├── 7003
    │?? └── redis.conf
    ├── 7004
    │?? └── redis.conf
    ├── 7005
    │?? └── redis.conf
    └── redis-server
    

    4、启动各redis节点

    依次进入7000,7001等,执行:

    cd 7000
    ../redis-server ./redis.conf
    

    启动6个节点

    安装ruby

    yum install ruby
    

    安装ruby访问redis的客户端:

    gem install redis
    

    5、使用脚本创建redis集群

    ./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
    

    集群简单测试:

    [root@manager1 src]# ./redis-cli -c -p 7000
    
    127.0.0.1:7000> set foo bar
    
    -> Redirected to slot [12182] located at 127.0.0.1:7002
    
    OK
    
    127.0.0.1:7002> set hello world
    
    -> Redirected to slot [866] located at 127.0.0.1:7000
    
    OK
    
    127.0.0.1:7000> get foo
    
    -> Redirected to slot [12182] located at 127.0.0.1:7002
    
    "bar"
    
    127.0.0.1:7002> get foo
    
    "bar"
    
    127.0.0.1:7002> get hello
    
    -> Redirected to slot [866] located at 127.0.0.1:7000
    
    "world"
    
    127.0.0.1:7000> exit
    
  • 相关阅读:
    POJ 1905 Expanding Rods 木棍膨胀
    [JSOI2007] 文本生成器
    18.09.22模拟赛T2 历史
    [USACO18OPEN] Talent Show
    [国家集训队] 整数的lqp拆分
    [HNOI2008] GT考试
    读入优化效果测试
    Trie图 模板
    manacher算法 详解+模板
    [洛谷P4299] 首都
  • 原文地址:https://www.cnblogs.com/jjzd/p/7373800.html
Copyright © 2011-2022 走看看