zoukankan      html  css  js  c++  java
  • Redis 创建集群

    [root@node01 ~]# mkdir cluster-test
    
    [root@node01 ~]# cd cluster-test/
    
    [root@node01 cluster-test]# mkdir 7000 7001 7002 7003 7004 7005
    [root@node01 cluster-test]# ls
    7000  7001  7002  7003  7004  7005
    
    
    
    创建和使用一个Redis Cluster:
    
    注: 手动部署一个Redis Cluster它是非常重要的学习某些操作。
    
    然而如果你需要得到一个集群运行ASAP(尽快) 跳过这个章节,
    
    下一个和直接创建一个Redis Cluster 使用 create-cluster script.
    
    
    创建一个集群,第一件事我们需要是有一些空的Redis 实例运行在cluster 集群。
    
    
    这个基本意味着cluster 不是使用正常的Redis 实例创建作为一个特定模式需要被配置,
    
    这样Redis 实例可以启动Cluster 指定功能和命令。
    
    下面是最小的Redis Cluster 配置文件:
    
    port 7000
    cluster-enabled yes
    cluster-config-file nodes.conf
    cluster-node-timeout 5000
    appendonly yes
    
    正如你所看到的,cluster mode 是简单的启动cluster.
    
    
    每个实例也包含文件的路径 配置用于这个节点,默认的nodes.conf.
    
    这个文件不是有人为创建的, 它是在Redis Cluster 实例启动的时候创建,每次需要更新时
    
    注意: 最小的集群正常工作需要包含至少3个master节点。
    
    
    对于你的第一个测试,强烈建议开始一个6节点的cluster 其中3个节点的masters和3个节点的slaves.
    
    
    为此,进入一个新的目录,创建下面的目录 名字为实例的端口号
    
    Something like:
    mkdir cluster-test
    cd cluster-test
    mkdir 7000 7001 7002 7003 7004 7005
    
    
    创建一个redis.conf 文件在每个节点,从7000到7005.
    
    
    作为一个模板对于你的配置文件只是使用上面小的例子,
    
    
    但是确保替换端口号7000 使用正确端口号按照目录名称:
    
    
    现在复制你的redi-server执行,从最新的源在GitHUB分支,
    
    到cluster-test目录
    
    
    启动每个实例像这样,每个标签:
    
    cd 7000
    ../redis-server ./redis.conf
    
    
    你可以每个实例的日志看到,因为没有nodes.conf 文件存在 每个节点分片一个NEW ID。
    
    
    [root@node01 7000]# ls -ltr
    total 8
    -rw-r--r-- 1 root root 102 Jun 16 18:57 redis.conf
    -rw-r--r-- 1 root root  18 Jun 16 18:57 dump.rdb
    [root@node01 7000]# redis-server redis.conf 
    26433:M 16 Jun 19:04:37.445 * Increased maximum number of open files to 10032 (it was originally set to 1024).
    26433:M 16 Jun 19:04:37.445 * No cluster configuration found, I'm f2bebbe62d4bf019993900814b09be295759e3f3
    
    
    这个ID会被使用通过这个特定的实例对于实例有一个唯一的名字在cluster环境。
    
    每个节点记住所有其他节点使用这个IDs,
    
    不是IP或者端口。
    
    Ip 地址和端口可以改变,但是唯一的node 标识永远不会改变对于节点的生命周期,我们称这个简单的标识为Node ID.
    
    
    
    Creating the cluster
    
    现在我们有很多实例运行, 我们需要创建我们的cluster通过写一些有意义的配置到节点;
    
    
    这是一个非常简单的完成因为我们是通过Redis Cluster 命令行称为redis-trib, 
    
    一个Ruby 程序执行特定的命令在实例当为了创建新的集群,
    
    检查或者reshard 一个存在的cluster,等等:
    
    
     redis-trib功能是在Redis source code 在src目录,你需要安装redis gem 来运行redis-trib
    
    
    [root@node01 ~]# gem install redis
    ^CERROR:  Interrupted
    [root@node01 ~]# gem install redis
    Successfully installed redis-3.3.3
    1 gem installed
    Installing ri documentation for redis-3.3.3...
    Installing RDoc documentation for redis-3.3.3...
    [root@node01 ~]# 
    
    
    创建你的cluster 简单的type:
    
    
    ./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@node01 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
    >>> Creating cluster
    >>> 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
    Adding replica 127.0.0.1:7003 to 127.0.0.1:7000
    Adding replica 127.0.0.1:7004 to 127.0.0.1:7001
    Adding replica 127.0.0.1:7005 to 127.0.0.1:7002
    M: f2bebbe62d4bf019993900814b09be295759e3f3 127.0.0.1:7000
       slots:0-5460 (5461 slots) master
    M: 50801711b2d9b88e7a92d63151958c4e2c76c050 127.0.0.1:7001
       slots:5461-10922 (5462 slots) master
    M: a2ba1f50a77f729a0276a5087f621c214e34cfed 127.0.0.1:7002
       slots:10923-16383 (5461 slots) master
    S: 112e2e15b9dece48483b554b66d054bf01f71c5c 127.0.0.1:7003
       replicates f2bebbe62d4bf019993900814b09be295759e3f3
    S: 7dcea3f3475ddb66dc9de7527cae9865ca65dff3 127.0.0.1:7004
       replicates 50801711b2d9b88e7a92d63151958c4e2c76c050
    S: 00d5ccf205e1d98fa8ec647505eecfde59908fa4 127.0.0.1:7005
       replicates a2ba1f50a77f729a0276a5087f621c214e34cfed
    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:7000)
    M: f2bebbe62d4bf019993900814b09be295759e3f3 127.0.0.1:7000
       slots:0-5460 (5461 slots) master
       1 additional replica(s)
    S: 00d5ccf205e1d98fa8ec647505eecfde59908fa4 127.0.0.1:7005
       slots: (0 slots) slave
       replicates a2ba1f50a77f729a0276a5087f621c214e34cfed
    S: 112e2e15b9dece48483b554b66d054bf01f71c5c 127.0.0.1:7003
       slots: (0 slots) slave
       replicates f2bebbe62d4bf019993900814b09be295759e3f3
    M: 50801711b2d9b88e7a92d63151958c4e2c76c050 127.0.0.1:7001
       slots:5461-10922 (5462 slots) master
       1 additional replica(s)
    S: 7dcea3f3475ddb66dc9de7527cae9865ca65dff3 127.0.0.1:7004
       slots: (0 slots) slave
       replicates 50801711b2d9b88e7a92d63151958c4e2c76c050
    M: a2ba1f50a77f729a0276a5087f621c214e34cfed 127.0.0.1:7002
       slots:10923-16383 (5461 slots) master
       1 additional replica(s)
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    
    
    这个命令在这儿是创建,因为我们需要创建一个新的集群。
    
    选项 --replicas 1 意味着我们需要一个slave对于每个创建的master.
    
    其他的参数我们需要用来创建新的集群。
    
    
    显然,唯一的步骤我们需要来创建一个集群有3个masters和3个slaves.
    
    
    Redis-trib 会提出一个配置,接收提出的配置通过输入yes.
    
    [OK] All 16384 slots covered
    

  • 相关阅读:
    (转)一篇教会你写90%的shell脚本
    (转)printf命令详解
    (转)linux shell 字符串操作详解 (长度,读取,替换,截取,连接,对比,删除,位置 )
    (转)Shell中read的选项及用法
    (转)linux中shell变量$#,$@,$0,$1,$2的含义解释/Shell中的${}、##和%%使用范例/export
    (转)linux运维人员必会的22道shell编程面试题及视频讲解
    (转)李文周的博客
    ROS报错“An error occurred during the signature verification”的解决办法
    RRT and RRT Variants
    ROS LocalPlanner 基于自行车模型的DWA
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349648.html
Copyright © 2011-2022 走看看