当前位置: 首页 > news >正文

Redis Cluster(无中心化设计)

目录

1 Redis Cluster 的介绍

1.1 Redis Cluster 工作原理

1.2 Redis Cluster特点如下

1.3 Redis cluster 架构

1.4 Redis cluster 主从架构

1.5 Redis Cluster 部署架构说明

1.6 创建redis cluster的前提

2 部署redis cluster

2.1 修改Redis主配置文件参数

2.2 查看端口是否启动

3 创建redis-cluster

3.1 实验环境

3.2 创建集群

3.3 获取Redis集群信息

3.4 检查Redis集群的状态

3.5 写入数据测试

3 Redis-cluster 配置扩展内存

3.1 添加新的机子进入集群中

3.2 重新分配slots槽位

3.3 将剩余的机子以slave身份加入集群

4 clsuter集群维护

 4.1 将节点从集群中移除

4.2 迁移槽位


1 Redis Cluster 的介绍

1.1 Redis Cluster 工作原理

在哨兵 sentinel 机制中,可以解决 redis 高可用问题,即当 master 故障后可以自动将 slave 提升为 master ,从而可以保证redis 服务的正常使用,但是无法解决 redis 单机写入的瓶颈问题,即单机 redis 写入性能受 限于单机的内存大小、并发数量、网卡速率等因素。
redis 3.0 版本之后推出了无中心架构的 redis cluster 机制,在无中心的 redis 集群当中,其每个节点保存当前节点数据和整个集群状态, 每个节点都和其他所有节点连接 

1.2 Redis Cluster特点如下

  1. 所有Redis节点使用(PING机制)互联
  2. 集群中某个节点的是否失效,是由整个集群中超过半数的节点监测都失效,才能算真正的失效
  3. 客户端不需要proxy即可直接连接redis,应用程序中需要配置有全部的redis服务器IP
  4. redis cluster把所有的redis node 平均映射到 0-16383个槽位(slot)上,读写需要到指定的redis node上进行操作,因此有多少个redis node相当于redis 并发扩展了多少倍,每个redis node 承担 16384/N个槽位
  5. Redis cluster预先分配16384(slot)槽位,当需要在redis集群中写入一个key -value的时候,会使用CRC16(key) mod 16384之后的值,决定将key写入值哪一个槽位从而决定写入哪一个Redis节点上,从而有效解决单机瓶颈

1.3 Redis cluster 架构

假如三个主节点分别是: A, B, C 三个节点,采用哈希槽 (hash slot) 的方式来分配 16384 slot 的话它们 三个节点分别承担的slot 区间可以是:

节点A覆盖 05460

节点B覆盖 546110922

节点C覆盖 1092316383

1.4 Redis cluster 主从架构

Redis cluster的架构虽然解决了并发的问题,但是又引入了一个新的问题,每个Redis master的高可用如何解决?

那就是对每个master 节点都实现主从复制,从而实现 redis 高可用性

1.5 Redis Cluster 部署架构说明

1.6 创建redis cluster的前提

1.每个redis node节点采用相同的硬件配置、相同的密码、相同的redis版本。

2.每个节点必须开启的参数

cluster-enabled yes    #必须开启集群状态,开启后redis进程会有cluster显示

cluster-config-file nodes-6380.conf #此文件有redis cluster集群自动创建和维护,不需要任何手

动操作

3.所有redis服务器必须没有任何数据

4.先启动为单机redis且没有任何key value

2 部署redis cluster

2.1 修改Redis主配置文件参数

[root@node-1 redis]# vim /etc/redis/redis.conf bind * -::*
requirepass "123456" #集群主从认证
masterauth "123456"    #redis登陆密码 redis-cli 命令连接redis后要用“auth 密码”进行认证
cluster-enabled yes    #开启cluster集群功能
cluster-config-file nodes-6379.conf    #指定集群配置文件
cluster-node-timeout 15000            #节点加入集群的超时时间单位是ms

将配置好的配置文件复制给其他主机

[root@node-1 redis]# for i in 20 30 40 50 60
do 
scp /etc/redis/redis.conf root@192.168.239.$i:/etc/redis 
done

2.2 查看端口是否启动

重启六个节点的Redis并查看Redis端口号是否启动

这里只查询了一个

[root@node-1 redis]# systemctl daemon-reload 
[root@node-1 redis]# systemctl restart redis_6379.service 
[root@node-1 redis]# netstat -antlupe | grep redis
tcp        0      0 0.0.0.0:16379           0.0.0.0:*               LISTEN      0          95997      11311/redis-server  
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      0          95995      11311/redis-server  
tcp6       0      0 :::16379                :::*                    LISTEN      0          95998      11311/redis-server  
tcp6       0      0 :::6379                 :::*                    LISTEN      0          95996      11311/redis-server 
[root@node-1 redis]# redis-cli --cluster helpCluster Manager Commands:create         host1:port1 ... hostN:portN--cluster-replicas <arg>check          <host:port> or <host> <port> - separated by either colon or space--cluster-search-multiple-ownersinfo           <host:port> or <host> <port> - separated by either colon or spacefix            <host:port> or <host> <port> - separated by either colon or space--cluster-search-multiple-owners--cluster-fix-with-unreachable-mastersreshard        <host:port> or <host> <port> - separated by either colon or space--cluster-from <arg>--cluster-to <arg>--cluster-slots <arg>--cluster-yes--cluster-timeout <arg>--cluster-pipeline <arg>--cluster-replacerebalance      <host:port> or <host> <port> - separated by either colon or space--cluster-weight <node1=w1...nodeN=wN>--cluster-use-empty-masters--cluster-timeout <arg>--cluster-simulate--cluster-pipeline <arg>--cluster-threshold <arg>--cluster-replaceadd-node       new_host:new_port existing_host:existing_port--cluster-slave--cluster-master-id <arg>del-node       host:port node_idcall           host:port command arg arg .. arg--cluster-only-masters--cluster-only-replicasset-timeout    host:port millisecondsimport         host:port--cluster-from <arg>--cluster-from-user <arg>--cluster-from-pass <arg>--cluster-from-askpass--cluster-copy--cluster-replacebackup         host:port backup_directory
命令参数描述
createhost1:port1 ... hostN:portN创建集群
checkhost:port or <host> <port>检测集群信息
infohost:port or <host> <port>查看集群信息
fixhost:port or <host> <port>修复集群
reshardhost:port or <host> <port>在线热迁移集群指定主机的 slots 数据
rebalancehost:port or <host> <port>平衡各集群主机的 slot 数量
add-nodenew_host:new_port existing_host:existing_port添加主机
del-nodehost:port node_id删除主机
importhost:port导入外部 redis 服务器的数据到当前集群

3 创建redis-cluster

3.1 实验环境

节点名称角色IP地址
node-1MASTER192.168.239.10
node-2MASTER192.168.239.20
node-3MASTER

192.168.239.30

node-4SLAVE192.168.239.40
node-5SLAVE192.168.239.50
node-6SLAVE192.168.239.60

六台机子 -- 三主三从

并且Redis--cluster 要求最低的就是三主三从

3.2 创建集群

[root@node-1 ~]# redis-cli --cluster create -a 
123456 192.168.239.10:6379 192.168.239.20:6379 \
192.168.239.30:6379 192.168.239.40:6379 \
192.168.239.50:6379 192.168.239.60:6379 \
--cluster-replicas 1Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.239.50:6379 to 192.168.239.10:6379
Adding replica 192.168.239.60:6379 to 192.168.239.20:6379
Adding replica 192.168.239.40:6379 to 192.168.239.30:6379
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379slots:[0-5460] (5461 slots) master
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379slots:[5461-10922] (5462 slots) master
M: df5b83fd072236a8fe1c54284ba5bc2dc7aebc42 192.168.239.30:6379slots:[10923-16383] (5461 slots) master
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379replicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379replicates fd34e44d501a46a8544453d3f1fb026adaa75862
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379replicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
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 192.168.239.10:6379)
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379slots:[0-5460] (5461 slots) master1 additional replica(s)
M: df5b83fd072236a8fe1c54284ba5bc2dc7aebc42 192.168.239.30:6379slots:[10923-16383] (5461 slots) master1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379slots:[5461-10922] (5462 slots) master1 additional replica(s)
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379slots: (0 slots) slavereplicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379slots: (0 slots) slavereplicates fd34e44d501a46a8544453d3f1fb026adaa75862
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379slots: (0 slots) slavereplicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
[OK] All nodes agree about slots configuration.
>>> Check for open slots...            # 检查打开的哈希槽位
>>> Check slots coverage...            # 检查槽位覆盖范围
[OK] All 16384 slots covered.          # 所有槽位分配完成

cluster配置文件所在地

#配置文件位置
[root@node-1 ~]# ll /var/lib/redis/nodes-6379.conf

检查集群配置: 如果想要检查整个集群的配置情况,使用 CLUSTER NODES 命令:

[root@node-1 ~]# redis-cli -h 192.168.239.30 -p 6379 -a 123456 CLUSTER NODES

重置集群状态: 如果想要创建一个新的集群,需要先重置现有节点的状态。由于你已经确认了节点的状态,可以选择重置节点 192.168.239.30:6379 的集群状态:

[root@node-1 ~]# redis-cli -h 192.168.239.30 -p 6379 -a 123456 CLUSTER RESET SOFT

3.3 获取Redis集群信息

redis-cli -a 123456 --cluster info 192.168.239.10:6379 (获取Redis集群的信息

[root@node-1 ~]# redis-cli -a 123456 --cluster info 192.168.239.10:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.239.10:6379 (fd34e44d...) -> 0 keys | 5461 slots | 1 slaves.
192.168.239.30:6379 (df5b83fd...) -> 0 keys | 5461 slots | 1 slaves.
192.168.239.20:6379 (d1993d8c...) -> 0 keys | 5462 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.

3.4 检查Redis集群的状态

redis-cli -a 123456 --cluster check 192.168.239.20:6379 (检查Redis集群的状态

[root@node-1 ~]# redis-cli -a 123456 --cluster check 192.168.239.20:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.239.20:6379 (d1993d8c...) -> 0 keys | 5462 slots | 1 slaves.
192.168.239.30:6379 (df5b83fd...) -> 0 keys | 5461 slots | 1 slaves.
192.168.239.10:6379 (fd34e44d...) -> 0 keys | 5461 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.239.20:6379)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379slots:[5461-10922] (5462 slots) master1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379slots: (0 slots) slavereplicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
M: df5b83fd072236a8fe1c54284ba5bc2dc7aebc42 192.168.239.30:6379slots:[10923-16383] (5461 slots) master1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379slots: (0 slots) slavereplicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379slots:[0-5460] (5461 slots) master1 additional replica(s)
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379slots: (0 slots) slavereplicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

3.5 写入数据测试

[root@node-1 ~]# redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> set name 123
# 通过hash运算123 确定 hash运算的记过 落在哪个机子负责的slot范围
# 这里同计算告诉我要求找 20 的机子
(error) MOVED 5798 192.168.239.20:6379[root@node-1 ~]# redis-cli -a 123456 -h 192.168.239.20
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.239.20:6379> set name 123
OK
192.168.239.20:6379> get name
"123"

3 Redis-cluster 配置扩展内存

对cluster 配置扩展内存 -- 多加一主一从

又原来的三主三从变为了四主四从

节点名称角色IP地址
node-1MASTER192.168.239.10
node-2MASTER192.168.239.20
node-3MASTER

192.168.239.30

node-4SLAVE192.168.239.40
node-5SLAVE192.168.239.50
node-6SLAVE192.168.239.60
node-7MASTER192.168.239.70
node-8SLAVE192.168.239.80

3.1 添加新的机子进入集群中

[root@node-1 src]# redis-cli -a 123456 \
--cluster add-node 192.168.239.70:6379 192.168.239.30:6379
# 将192.168.239.70 机子 添加到 192.168.239.30 所属的集群中,30最好是master
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 192.168.239.70:6379 to cluster 192.168.239.30:6379
>>> Performing Cluster Check (using node 192.168.239.30:6379)
M: df5b83fd072236a8fe1c54284ba5bc2dc7aebc42 192.168.239.30:6379slots:[10923-16383] (5461 slots) master1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379slots: (0 slots) slavereplicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379slots:[0-5460] (5461 slots) master1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379slots:[5461-10922] (5462 slots) master1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379slots: (0 slots) slavereplicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379slots: (0 slots) slavereplicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Getting functions from cluster
>>> Send FUNCTION LIST to 192.168.239.70:6379 to verify there is no functions in it
>>> Send FUNCTION RESTORE to 192.168.239.70:6379
>>> Send CLUSTER MEET to node 192.168.239.70:6379 to make it join the cluster.
[OK] New node added correctly.

查看集群的基本信息

查看30所在的集群

[root@node-1 src]# redis-cli -a 123456 --cluster info 192.168.239.30:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.239.30:6379 (df5b83fd...) -> 0 keys | 5461 slots | 1 slaves.
192.168.239.10:6379 (fd34e44d...) -> 0 keys | 5461 slots | 1 slaves.
192.168.239.20:6379 (d1993d8c...) -> 0 keys | 5462 slots | 1 slaves.
192.168.239.70:6379 (0f2dd0c4...) -> 0 keys | 0 slots | 0 slaves.

检查Redis集群的状态

检查30所在的集群状态,查看70是否被加进 了集群

[root@node-1 src]# redis-cli -a 123456 --cluster check 192.168.239.30:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.239.30:6379 (df5b83fd...) -> 0 keys | 5461 slots | 1 slaves.
192.168.239.10:6379 (fd34e44d...) -> 0 keys | 5461 slots | 1 slaves.
192.168.239.20:6379 (d1993d8c...) -> 0 keys | 5462 slots | 1 slaves.
192.168.239.70:6379 (0f2dd0c4...) -> 0 keys | 0 slots | 0 slaves.
[OK] 0 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.239.30:6379)
M: df5b83fd072236a8fe1c54284ba5bc2dc7aebc42 192.168.239.30:6379slots:[10923-16383] (5461 slots) master1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379slots: (0 slots) slavereplicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379slots:[0-5460] (5461 slots) master1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379slots:[5461-10922] (5462 slots) master1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379slots: (0 slots) slavereplicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
M: 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 192.168.239.70:6379slots: (0 slots) master
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379slots: (0 slots) slavereplicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

3.2 重新分配slots槽位

在这里能发现由于 slots被集群中的其他机子分完了,导致后来扩容的机子没有得到slots,这样子就算加了之后也使用不到,所以需要给这个集群重新分配 

[root@node-1 src]# redis-cli -a 123456 --cluster reshard 192.168.239.30:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 192.168.239.30:6379)
M: df5b83fd072236a8fe1c54284ba5bc2dc7aebc42 192.168.239.30:6379slots:[10923-16383] (5461 slots) master1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379slots: (0 slots) slavereplicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379slots:[0-5460] (5461 slots) master1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379slots:[5461-10922] (5462 slots) master1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379slots: (0 slots) slavereplicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
M: 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 192.168.239.70:6379slots: (0 slots) master
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379slots: (0 slots) slavereplicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 4096   # 四个人每个人4096,一共才16384
What is the receiving node ID? 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1  #填70 的ID
Please enter all the source node IDs.Type 'all' to use all the nodes as source nodes for the hash slots.Type 'done' once you entered all the source nodes IDs.
Source node #1: all    # 给每个人都划分槽位

查看是否划分成功 

[root@node-1 src]# redis-cli -a 123456 --cluster check 192.168.239.30:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.239.30:6379 (df5b83fd...) -> 0 keys | 4096 slots | 1 slaves.
192.168.239.10:6379 (fd34e44d...) -> 0 keys | 4096 slots | 1 slaves.
192.168.239.20:6379 (d1993d8c...) -> 0 keys | 4096 slots | 1 slaves.
192.168.239.70:6379 (0f2dd0c4...) -> 0 keys | 4096 slots | 0 slaves.
[OK] 0 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.239.30:6379)
M: df5b83fd072236a8fe1c54284ba5bc2dc7aebc42 192.168.239.30:6379slots:[12288-16383] (4096 slots) master1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379slots: (0 slots) slavereplicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379slots:[1365-5460] (4096 slots) master1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379slots:[6827-10922] (4096 slots) master1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379slots: (0 slots) slavereplicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
M: 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 192.168.239.70:6379slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379slots: (0 slots) slavereplicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

3.3 将剩余的机子以slave身份加入集群

还剩一台机子没加载进来集群

将剩余的机子加入集群并设为slave

[root@node-1 src]# redis-cli -a 123456 \
--cluster add-node 192.168.239.80:6379 192.168.239.30:6379 \
--cluster-slave \
--cluster-master-id 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 #填master的IDWarning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 192.168.239.80:6379 to cluster 192.168.239.30:6379
>>> Performing Cluster Check (using node 192.168.239.30:6379)
M: df5b83fd072236a8fe1c54284ba5bc2dc7aebc42 192.168.239.30:6379slots:[12288-16383] (4096 slots) master1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379slots: (0 slots) slavereplicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379slots:[1365-5460] (4096 slots) master1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379slots:[6827-10922] (4096 slots) master1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379slots: (0 slots) slavereplicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
M: 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 192.168.239.70:6379slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379slots: (0 slots) slavereplicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.239.80:6379 to make it join the cluster.

查看并检查集群状态 

[root@node-1 src]# redis-cli -a 123456 --cluster check 192.168.239.30:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.239.30:6379 (df5b83fd...) -> 0 keys | 4096 slots | 1 slaves.
192.168.239.10:6379 (fd34e44d...) -> 0 keys | 4096 slots | 1 slaves.
192.168.239.20:6379 (d1993d8c...) -> 0 keys | 4096 slots | 1 slaves.
192.168.239.70:6379 (0f2dd0c4...) -> 0 keys | 4096 slots | 1 slaves.
[OK] 0 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.239.30:6379)
M: df5b83fd072236a8fe1c54284ba5bc2dc7aebc42 192.168.239.30:6379slots:[12288-16383] (4096 slots) master1 additional replica(s)
S: 77ddb87d8eb45e59ee451129bce4279d8649b885 192.168.239.80:6379slots: (0 slots) slavereplicates 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379slots: (0 slots) slavereplicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379slots:[1365-5460] (4096 slots) master1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379slots:[6827-10922] (4096 slots) master1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379slots: (0 slots) slavereplicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
M: 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 192.168.239.70:6379slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master1 additional replica(s)
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379slots: (0 slots) slavereplicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

4 clsuter集群维护

添加节点的时候是先添加node节点到集群,然后分配槽位,删除节点的操作与添加节点的操作正好相反,是先将被删除的Redis node上的槽位迁移到集群中的其他Redis node节点上,然后再将其删除,如果一个Redis node节点上的槽位没有被完全迁移,删除该node的时候会提示有数据且无法删除。

 4.1 将节点从集群中移除

[root@node-1 src]# redis-cli -a 123456 --cluster \
del-node 192.168.239.80:6379 77ddb87d8eb45e59ee451129bce4279d8649b885Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Removing node 77ddb87d8eb45e59ee451129bce4279d8649b885 from cluster 192.168.239.80:6379
>>> Sending CLUSTER FORGET messages to the cluster...
>>> Sending CLUSTER RESET SOFT to the deleted node.

检查并查看槽位情况

[root@node-1 src]# redis-cli -a 123456 --cluster check 192.168.239.30:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.239.30:6379 (df5b83fd...) -> 0 keys | 4096 slots | 1 slaves.
192.168.239.10:6379 (fd34e44d...) -> 0 keys | 4096 slots | 1 slaves.
192.168.239.20:6379 (d1993d8c...) -> 0 keys | 4096 slots | 1 slaves.
192.168.239.70:6379 (0f2dd0c4...) -> 0 keys | 4096 slots | 0 slaves.
[OK] 0 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.239.30:6379)
M: df5b83fd072236a8fe1c54284ba5bc2dc7aebc42 192.168.239.30:6379slots:[12288-16383] (4096 slots) master1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379slots: (0 slots) slavereplicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379slots:[1365-5460] (4096 slots) master1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379slots:[6827-10922] (4096 slots) master1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379slots: (0 slots) slavereplicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
M: 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 192.168.239.70:6379slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379slots: (0 slots) slavereplicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

4.2 迁移槽位

[root@node-1 src]# redis-cli -a 123456 --cluster reshard 192.168.239.30:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 192.168.239.30:6379)
M: df5b83fd072236a8fe1c54284ba5bc2dc7aebc42 192.168.239.30:6379slots:[12288-16383] (4096 slots) master1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379slots: (0 slots) slavereplicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379slots:[1365-5460] (4096 slots) master1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379slots:[6827-10922] (4096 slots) master1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379slots: (0 slots) slavereplicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
M: 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 192.168.239.70:6379slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379slots: (0 slots) slavereplicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 4096    #需要分配多少槽位
What is the receiving node ID? df5b83fd072236a8fe1c54284ba5bc2dc7aebc42 #需要分给谁
Please enter all the source node IDs.Type 'all' to use all the nodes as source nodes for the hash slots.Type 'done' once you entered all the source nodes IDs.
Source node #1: 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1    # 从哪个槽位获取
Source node #2: done

检查槽位是否分配成功

[root@node-1 src]# redis-cli -a 123456 --cluster check 192.168.239.30:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.239.30:6379 (df5b83fd...) -> 0 keys | 8192 slots | 2 slaves.
192.168.239.10:6379 (fd34e44d...) -> 0 keys | 4096 slots | 1 slaves.
192.168.239.20:6379 (d1993d8c...) -> 0 keys | 4096 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.239.30:6379)
M: df5b83fd072236a8fe1c54284ba5bc2dc7aebc42 192.168.239.30:6379slots:[0-1364],[5461-6826],[10923-16383] (8192 slots) master2 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379slots: (0 slots) slavereplicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379slots:[1365-5460] (4096 slots) master1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379slots:[6827-10922] (4096 slots) master1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379slots: (0 slots) slavereplicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
S: 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 192.168.239.70:6379slots: (0 slots) slavereplicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379slots: (0 slots) slavereplicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

删除70主机

[root@node-1 src]# redis-cli -a 123456 --cluster del-node 192.168.239.70:6379 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Removing node 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 from cluster 192.168.239.70:6379
>>> Sending CLUSTER FORGET messages to the cluster...
>>> Sending CLUSTER RESET SOFT to the deleted node.

检查是否删除 

[root@node-1 src]# redis-cli -a 123456 --cluster check 192.168.239.30:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.239.30:6379 (df5b83fd...) -> 0 keys | 8192 slots | 1 slaves.
192.168.239.10:6379 (fd34e44d...) -> 0 keys | 4096 slots | 1 slaves.
192.168.239.20:6379 (d1993d8c...) -> 0 keys | 4096 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.239.30:6379)
M: df5b83fd072236a8fe1c54284ba5bc2dc7aebc42 192.168.239.30:6379slots:[0-1364],[5461-6826],[10923-16383] (8192 slots) master1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379slots: (0 slots) slavereplicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379slots:[1365-5460] (4096 slots) master1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379slots:[6827-10922] (4096 slots) master1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379slots: (0 slots) slavereplicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379slots: (0 slots) slavereplicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 信号量笔记
  • pytorch FSDP分布式训练minist案例
  • java springboot 集成activeMQ(保姆级别教程)
  • C++学习笔记——交换值
  • Unity3D UGUI性能消耗和管理详解
  • Redis集群技术
  • CSS3页面布局-三栏-中栏流动布局
  • 基于无人机边沿相关 ------- IBUS、SBUS协议和PPM信号
  • 目标检测:Cascade R-CNN: Delving into High Quality Object Detection - 2017【方法解读】
  • 张宇36讲+1000题重点强化!保100冲120速刷攻略
  • <WPF> xaml代码如何使用c#编写
  • 《一种个性化逻辑定制与类置换方案》
  • Android原生JobSchedulerContext内存泄漏导致设备重启的现象
  • java中位运算在算法中的应用
  • Ubuntu2004编译VLC-QT(记录)(根据官方步骤来)
  • SegmentFault for Android 3.0 发布
  • 4月23日世界读书日 网络营销论坛推荐《正在爆发的营销革命》
  • co.js - 让异步代码同步化
  • ES6核心特性
  • HashMap ConcurrentHashMap
  • iOS筛选菜单、分段选择器、导航栏、悬浮窗、转场动画、启动视频等源码
  • java 多线程基础, 我觉得还是有必要看看的
  • JavaWeb(学习笔记二)
  • Linux gpio口使用方法
  • oldjun 检测网站的经验
  • Spring Cloud Feign的两种使用姿势
  • SwizzleMethod 黑魔法
  • 理清楚Vue的结构
  • 利用阿里云 OSS 搭建私有 Docker 仓库
  • 模型微调
  • 前端面试之闭包
  • 说说动画卡顿的解决方案
  • shell使用lftp连接ftp和sftp,并可以指定私钥
  • # Swust 12th acm 邀请赛# [ A ] A+B problem [题解]
  • #if和#ifdef区别
  • #Z0458. 树的中心2
  • #调用传感器数据_Flink使用函数之监控传感器温度上升提醒
  • (~_~)
  • (152)时序收敛--->(02)时序收敛二
  • (2024)docker-compose实战 (9)部署多项目环境(LAMP+react+vue+redis+mysql+nginx)
  • (3) cmake编译多个cpp文件
  • (delphi11最新学习资料) Object Pascal 学习笔记---第13章第1节 (全局数据、栈和堆)
  • (Java数据结构)ArrayList
  • (Pytorch框架)神经网络输出维度调试,做出我们自己的网络来!!(详细教程~)
  • (简单) HDU 2612 Find a way,BFS。
  • (三)模仿学习-Action数据的模仿
  • (深入.Net平台的软件系统分层开发).第一章.上机练习.20170424
  • (一)Docker基本介绍
  • (转)Windows2003安全设置/维护
  • (轉貼) 資訊相關科系畢業的學生,未來會是什麼樣子?(Misc)
  • .gitignore文件—git忽略文件
  • .java 指数平滑_转载:二次指数平滑法求预测值的Java代码
  • .mysql secret在哪_MYSQL基本操作(上)
  • .Net 4.0并行库实用性演练
  • .NET CORE使用Redis分布式锁续命(续期)问题