LINUX:关于Redis集群的节点分配

文章来源:http://www.cnblogs.com/hello-tl/p/7808268.html 

  根据上述  Redis集群搭建:http://www.cnblogs.com/hello-tl/p/7804225.html 的步骤  今天来学习一下添加节点 / 节点重新分配

0、查看Redis nodes节点 / 退出Redis集群

目前是 7000 - - - - 7500 六个节点
# redis-cli -c -p 7000 cluster nodes  //查看REdis nodes节点
    28ec5253bab7d4a9e578dfcb750529bca08e0bfd 127.0.0.1:7300 slave 23927b9e69d3bc2e6bab95baf599ab4d38ec4bfd 0 1510210213694 4 connected
    462269d1bcb020c0aa7b95850c1aafacea86cbfc 127.0.0.1:7100 master - 0 1510210212692 2 connected 5461-10922
    78762d55924b0c1ba4411caf6d53d1abd88ae5bc 127.0.0.1:7400 slave 462269d1bcb020c0aa7b95850c1aafacea86cbfc 0 1510210215696 5 connected
    23927b9e69d3bc2e6bab95baf599ab4d38ec4bfd 127.0.0.1:7000 myself,master - 0 0 1 connected 0-5460
    7074b2ada87e0f390204dfda24e5abc9f7391201 127.0.0.1:7200 master - 0 1510210211691 3 connected 10923-16383
    ab433002f799d10dbf7f811d84c6ef327fe24d73 127.0.0.1:7500 slave 7074b2ada87e0f390204dfda24e5abc9f7391201 0 1510210214695 6 connected
    主----7000-7300
    7100-7400
    7200-7500

1、添加一个Redis nodes节点

# pwd
    /home/redis
    
## 添加一个端口目录 并且吧 redis.conf 复制到 7600文件夹
# mkdir 7600
# cp 7000/redis.conf 7600/
## 修改 7600 redis.conf 文件端口改成7600    

## 运行 7600 实例
# redis-server redis.conf
# ps aux | grep redis  查看7600实例是否成功
    root     12513  0.0  0.5 138964  9772 ?        Ssl  14:35   0:00 redis-server 127.0.0.1:7000 [cluster]
    root     12544  0.0  0.5 138964  9780 ?        Ssl  14:39   0:00 redis-server 127.0.0.1:7100 [cluster]
    root     12550  0.0  0.5 138964  9772 ?        Ssl  14:39   0:00 redis-server 127.0.0.1:7200 [cluster]
    root     12554  0.0  0.4 136916  7736 ?        Ssl  14:39   0:00 redis-server 127.0.0.1:7300 [cluster]
    root     12561  0.0  0.4 136916  7736 ?        Ssl  14:39   0:00 redis-server 127.0.0.1:7400 [cluster]
    root     12571  0.0  0.4 136916  7748 ?        Ssl  14:40   0:00 redis-server 127.0.0.1:7500 [cluster]
    root     12610  0.0  0.4 136916  7544 ?        Ssl  14:47   0:00 redis-server 127.0.0.1:7600 [cluster]
    root     12615  0.0  0.0 112644   964 pts/1    R+   14:48   0:00 grep --color=auto redis

*************************    添加节点
## 将7000 添加到 7600 节点下边
# pwd
    /home/redis/redis-3.2.9/src

# ./redis-trib.rb add-node 127.0.0.1:7600 127.0.0.1:7000

## 重新查看 nodes 节点
# redis-cli -c -p 7000 cluster nodes
    28ec5253bab7d4a9e578dfcb750529bca08e0bfd 127.0.0.1:7300 slave 23927b9e69d3bc2e6bab95baf599ab4d38ec4bfd 0 1510210715456 4 connected
    462269d1bcb020c0aa7b95850c1aafacea86cbfc 127.0.0.1:7100 master - 0 1510210716458 2 connected 5461-10922
    78762d55924b0c1ba4411caf6d53d1abd88ae5bc 127.0.0.1:7400 slave 462269d1bcb020c0aa7b95850c1aafacea86cbfc 0 1510210717460 5 connected
    23927b9e69d3bc2e6bab95baf599ab4d38ec4bfd 127.0.0.1:7000 myself,master - 0 0 1 connected 0-5460
    43be9c0e09eff614279721803c1ad9b36e06eb77 127.0.0.1:7600 master - 0 1510210720466 0 connected
    7074b2ada87e0f390204dfda24e5abc9f7391201 127.0.0.1:7200 master - 0 1510210719463 3 connected 10923-16383
    ab433002f799d10dbf7f811d84c6ef327fe24d73 127.0.0.1:7500 slave 7074b2ada87e0f390204dfda24e5abc9f7391201 0 1510210718461 6 connected

    主----7000-7300
    7100-7400
    7200-7500
    7600
## 增加了新的节点之后,这个新的节点可以成为主节点或者是从节点
## 把这个节点变成主节点,使用redis-trib程序,将集群中的某些哈希槽移动到新节点里面, 这个新节点就成为真正的主节点了。

 2、移动一个Redis nodes节点

********************** 方式一    
## 将 7600 节点移动到 7000 节点下
# redis-cli -c -p 7600 cluster replicate 23927b9e69d3bc2e6bab95baf599ab4d38ec4bfd
    OK
## 重新查看 nodes 节点
# redis-cli -c -p 7000 cluster nodes    
    28ec5253bab7d4a9e578dfcb750529bca08e0bfd 127.0.0.1:7300 slave 23927b9e69d3bc2e6bab95baf599ab4d38ec4bfd 0 1510211580854 4 connected
    462269d1bcb020c0aa7b95850c1aafacea86cbfc 127.0.0.1:7100 master - 0 1510211579852 2 connected 5461-10922
    78762d55924b0c1ba4411caf6d53d1abd88ae5bc 127.0.0.1:7400 slave 462269d1bcb020c0aa7b95850c1aafacea86cbfc 0 1510211582859 5 connected
    23927b9e69d3bc2e6bab95baf599ab4d38ec4bfd 127.0.0.1:7000 myself,master - 0 0 1 connected 0-5460
    43be9c0e09eff614279721803c1ad9b36e06eb77 127.0.0.1:7600 slave 23927b9e69d3bc2e6bab95baf599ab4d38ec4bfd 0 1510211583860 1 connected
    7074b2ada87e0f390204dfda24e5abc9f7391201 127.0.0.1:7200 master - 0 1510211578851 3 connected 10923-16383
    ab433002f799d10dbf7f811d84c6ef327fe24d73 127.0.0.1:7500 slave 7074b2ada87e0f390204dfda24e5abc9f7391201 0 1510211581857 6 connected
    
    主----7000-7300 7600
    7100-7400
    7200-7500
********************** 方式二    
## 将 7600 节点移动到 7000 节点下
# redis-cli -c -p 7600 
# cluster replicate 23927b9e69d3bc2e6bab95baf599ab4d38ec4bfd
# exit
    OK
## 重新查看 nodes 节点
# redis-cli -c -p 7000 cluster nodes    
    28ec5253bab7d4a9e578dfcb750529bca08e0bfd 127.0.0.1:7300 slave 23927b9e69d3bc2e6bab95baf599ab4d38ec4bfd 0 1510211580854 4 connected
    462269d1bcb020c0aa7b95850c1aafacea86cbfc 127.0.0.1:7100 master - 0 1510211579852 2 connected 5461-10922
    78762d55924b0c1ba4411caf6d53d1abd88ae5bc 127.0.0.1:7400 slave 462269d1bcb020c0aa7b95850c1aafacea86cbfc 0 1510211582859 5 connected
    23927b9e69d3bc2e6bab95baf599ab4d38ec4bfd 127.0.0.1:7000 myself,master - 0 0 1 connected 0-5460
    43be9c0e09eff614279721803c1ad9b36e06eb77 127.0.0.1:7600 slave 23927b9e69d3bc2e6bab95baf599ab4d38ec4bfd 0 1510211583860 1 connected
    7074b2ada87e0f390204dfda24e5abc9f7391201 127.0.0.1:7200 master - 0 1510211578851 3 connected 10923-16383
    ab433002f799d10dbf7f811d84c6ef327fe24d73 127.0.0.1:7500 slave 7074b2ada87e0f390204dfda24e5abc9f7391201 0 1510211581857 6 connected
    
    主----7000-7300 7600
    7100-7400
    7200-7500

 

 

文章来源:http://www.cnblogs.com/hello-tl/p/7808268.html 

posted @ 2017-11-09 10:48  小田吃饺子  阅读(1578)  评论(0编辑  收藏  举报