美文网首页
redis 集群化部署 初体验

redis 集群化部署 初体验

作者: 不要重不要重 | 来源:发表于2019-06-03 17:18 被阅读0次

    1.redis 集群需要最少 3个master
    创建 cluster

    redis-cli --cluster create 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382  127.0.0.1:6383   127.0.0.1:6384   --cluster-replicas 1
    
    >>> Performing hash slots allocation on 6 nodes...
    Master[0] -> Slots 0 - 5460
    Master[1] -> Slots 5461 - 10922
    Master[2] -> Slots 10923 - 16383
    Adding replica 127.0.0.1:6382 to 127.0.0.1:6379
    Adding replica 127.0.0.1:6383 to 127.0.0.1:6380
    Adding replica 127.0.0.1:6384 to 127.0.0.1:6381
    >>> Trying to optimize slaves allocation for anti-affinity
    [WARNING] Some slaves are in the same host as their master
    M: dd7a081094f3df3eac846e8c92144636c3b05777 127.0.0.1:6379
       slots:[0-5460] (5461 slots) master
    M: daa2f0d2d9e0ef853e0c118800d3e8022d008ab5 127.0.0.1:6380
       slots:[5461-10922] (5462 slots) master
    M: bd1bb520b39298d25acfeb40b347dcaa53e65629 127.0.0.1:6381
       slots:[10923-16383] (5461 slots) master
    S: 5b01fb6f3bfe3c2472cb351910322de77f09704d 127.0.0.1:6382
       replicates daa2f0d2d9e0ef853e0c118800d3e8022d008ab5
    S: 873c3f9cbe5742a5bd19fc80ff0012312191283a 127.0.0.1:6383
       replicates bd1bb520b39298d25acfeb40b347dcaa53e65629
    S: d5d222140c5a3d46c2e69a613ec65281d6759b2b 127.0.0.1:6384
       replicates dd7a081094f3df3eac846e8c92144636c3b05777
    Can I set the above configuration? (type 'yes' to accept): yes
    ...
    ...
    9911:C 03 Jun 2019 16:54:00.102 * RDB: 0 MB of memory used by copy-on-write
    9085:M 03 Jun 2019 16:54:00.164 * Background saving terminated with success
    

    检查状态

    redis-cli --cluster check 127.0.0.1:6379
    127.0.0.1:6379 (dd7a0810...) -> 1 keys | 5461 slots | 1 slaves.
    127.0.0.1:6380 (daa2f0d2...) -> 2 keys | 5462 slots | 1 slaves.
    127.0.0.1:6381 (bd1bb520...) -> 1 keys | 5461 slots | 1 slaves.
    [OK] 4 keys in 3 masters.
    0.00 keys per slot on average.
    >>> Performing Cluster Check (using node 127.0.0.1:6379)
    M: dd7a081094f3df3eac846e8c92144636c3b05777 127.0.0.1:6379
       slots:[0-5460] (5461 slots) master
       1 additional replica(s)
    S: 873c3f9cbe5742a5bd19fc80ff0012312191283a 127.0.0.1:6383
       slots: (0 slots) slave
       replicates bd1bb520b39298d25acfeb40b347dcaa53e65629
    S: 5b01fb6f3bfe3c2472cb351910322de77f09704d 127.0.0.1:6382
       slots: (0 slots) slave
       replicates daa2f0d2d9e0ef853e0c118800d3e8022d008ab5
    M: daa2f0d2d9e0ef853e0c118800d3e8022d008ab5 127.0.0.1:6380
       slots:[5461-10922] (5462 slots) master
       1 additional replica(s)
    M: bd1bb520b39298d25acfeb40b347dcaa53e65629 127.0.0.1:6381
       slots:[10923-16383] (5461 slots) master
       1 additional replica(s)
    S: d5d222140c5a3d46c2e69a613ec65281d6759b2b 127.0.0.1:6384
       slots: (0 slots) slave
       replicates dd7a081094f3df3eac846e8c92144636c3b05777
    [OK] All nodes agree about slots configuration.
    >>> Check for open slots...
    >>> Check slots coverage...
    [OK] All 16384 slots covered.
    

    他们都说redis-trib 好,可惜我还不会用~
    下面来看redis 集群分布的图,一种分片的主备模式。


    image.png

    那么用户是怎么访问到不同的master上的数据的呢?代理,当然是代理了,看图[转自:https://juejin.im/post/5b8fc5536fb9a05d2d01fb11]

    image.png

    相关文章

      网友评论

          本文标题:redis 集群化部署 初体验

          本文链接:https://www.haomeiwen.com/subject/bozcxctx.html