Redis Cluster(无中心化设计)

news2024/9/27 6:49:48

目录

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 help

Cluster 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-owners
  info           <host:port> or <host> <port> - separated by either colon or space
  fix            <host:port> or <host> <port> - separated by either colon or space
                 --cluster-search-multiple-owners
                 --cluster-fix-with-unreachable-masters
  reshard        <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-replace
  rebalance      <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-replace
  add-node       new_host:new_port existing_host:existing_port
                 --cluster-slave
                 --cluster-master-id <arg>
  del-node       host:port node_id
  call           host:port command arg arg .. arg
                 --cluster-only-masters
                 --cluster-only-replicas
  set-timeout    host:port milliseconds
  import         host:port
                 --cluster-from <arg>
                 --cluster-from-user <arg>
                 --cluster-from-pass <arg>
                 --cluster-from-askpass
                 --cluster-copy
                 --cluster-replace
  backup         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 1

Warning: 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:6379
   slots:[0-5460] (5461 slots) master
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379
   slots:[5461-10922] (5462 slots) master
M: df5b83fd072236a8fe1c54284ba5bc2dc7aebc42 192.168.239.30:6379
   slots:[10923-16383] (5461 slots) master
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379
   replicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379
   replicates fd34e44d501a46a8544453d3f1fb026adaa75862
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379
   replicates 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:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: df5b83fd072236a8fe1c54284ba5bc2dc7aebc42 192.168.239.30:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379
   slots: (0 slots) slave
   replicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379
   slots: (0 slots) slave
   replicates fd34e44d501a46a8544453d3f1fb026adaa75862
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379
   slots: (0 slots) slave
   replicates 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:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379
   slots: (0 slots) slave
   replicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
M: df5b83fd072236a8fe1c54284ba5bc2dc7aebc42 192.168.239.30:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379
   slots: (0 slots) slave
   replicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379
   slots: (0 slots) slave
   replicates 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:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379
   slots: (0 slots) slave
   replicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379
   slots: (0 slots) slave
   replicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379
   slots: (0 slots) slave
   replicates 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:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379
   slots: (0 slots) slave
   replicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379
   slots: (0 slots) slave
   replicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
M: 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 192.168.239.70:6379
   slots: (0 slots) master
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379
   slots: (0 slots) slave
   replicates 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:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379
   slots: (0 slots) slave
   replicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379
   slots: (0 slots) slave
   replicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
M: 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 192.168.239.70:6379
   slots: (0 slots) master
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379
   slots: (0 slots) slave
   replicates 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:6379
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379
   slots: (0 slots) slave
   replicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379
   slots: (0 slots) slave
   replicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
M: 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 192.168.239.70:6379
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379
   slots: (0 slots) slave
   replicates 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的ID

Warning: 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:6379
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379
   slots: (0 slots) slave
   replicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379
   slots: (0 slots) slave
   replicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
M: 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 192.168.239.70:6379
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379
   slots: (0 slots) slave
   replicates 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:6379
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 77ddb87d8eb45e59ee451129bce4279d8649b885 192.168.239.80:6379
   slots: (0 slots) slave
   replicates 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379
   slots: (0 slots) slave
   replicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379
   slots: (0 slots) slave
   replicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
M: 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 192.168.239.70:6379
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
   1 additional replica(s)
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379
   slots: (0 slots) slave
   replicates 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 77ddb87d8eb45e59ee451129bce4279d8649b885

Warning: 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:6379
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379
   slots: (0 slots) slave
   replicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379
   slots: (0 slots) slave
   replicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
M: 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 192.168.239.70:6379
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379
   slots: (0 slots) slave
   replicates 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:6379
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379
   slots: (0 slots) slave
   replicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379
   slots: (0 slots) slave
   replicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
M: 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 192.168.239.70:6379
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379
   slots: (0 slots) slave
   replicates 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:6379
   slots:[0-1364],[5461-6826],[10923-16383] (8192 slots) master
   2 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379
   slots: (0 slots) slave
   replicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379
   slots: (0 slots) slave
   replicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
S: 0f2dd0c4abbe6fe44482c04e76c1bf9a3e83efc1 192.168.239.70:6379
   slots: (0 slots) slave
   replicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379
   slots: (0 slots) slave
   replicates 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:6379
   slots:[0-1364],[5461-6826],[10923-16383] (8192 slots) master
   1 additional replica(s)
S: 57b15b219dc8d165de5d55fd7de3a1e305478e5a 192.168.239.50:6379
   slots: (0 slots) slave
   replicates fd34e44d501a46a8544453d3f1fb026adaa75862
M: fd34e44d501a46a8544453d3f1fb026adaa75862 192.168.239.10:6379
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8 192.168.239.20:6379
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: 6fed09bcd3438e98d89c73928a1194bdd53a6144 192.168.239.60:6379
   slots: (0 slots) slave
   replicates d1993d8c1502eafdc775c6d6a04cc55a8e46c4a8
S: bd925eea56441db2009bb2f4bdd942b642665787 192.168.239.40:6379
   slots: (0 slots) slave
   replicates df5b83fd072236a8fe1c54284ba5bc2dc7aebc42
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2077428.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

vue 实现简单AI聊天程序(二): python 对接通义千问API

申请账号流程&#xff0c;参考&#xff1a;https://blog.csdn.net/u012917925/article/details/140794192 登录阿里云&#xff0c;然后找到阿里云百炼&#xff0c;创建一个API KEY 配置环境变量&#xff1a;https://help.aliyun.com/zh/model-studio/developer-reference/con…

java直接内存

Java中的内存从广义上可以划分为两个部分&#xff0c;一部分是受JVM管理的堆内存&#xff0c;另一部分则是不受JVM管理的堆外内存&#xff0c;也称为直接内存。直接内存由操作系统来管理&#xff0c;这部分内存的应用可以减少垃圾收集对应用程序的影响。 直接内存概述 直接内…

酒店PMS系统源码之会员系统读取身份证-CyberWinApp-SAAS 本地化及未来之窗行业应用跨平台架构

一、酒店 PMS&#xff08;&#xff09;会员系统 1. 客户关系管理&#xff1a;帮助酒店有效地管理会员信息&#xff0c;包括个人资料、消费记录、偏好等&#xff0c;从而更好地了解会员需求&#xff0c;提供个性化的服务和优惠。 2. 会员忠诚度提升&#xff1a;通过积分、折扣、…

使用CORS解决跨域问题

CORS&#xff08;Cross-Origin Resource Sharing&#xff09;跨域资源共享 因为浏览器的同源策略才出现了跨域问题。 CORS是一套机制&#xff0c;用于浏览器校验跨域请求。 它的基本理念是&#xff1a; 只要服务器明确表示允许&#xff0c;则校验通过服务器明确拒绝或没有表…

读取FTP中不同文件格式的文件流后导出到浏览器

序言 有一个新的需求&#xff0c;前端提供下载的入口&#xff0c;后端能将指定了全路径的各种文件格式的文件下载到浏览器。 对于压缩的zip文件格式需要解析后写入到txt文件格式的文件中&#xff0c;其他的写入原本的文件格式的文件中。 1、连接ftp <!-- jsch-sftp连接…

构建第一个zk

1 必要步骤 视频学习&#xff1a;5. Circcom 中的基本算术电路_哔哩哔哩_bilibili 文字学习&#xff1a;https://hackmd.io/YlNLZS2ESI21OSqdTW_mPw/S1jqN-h80/edit 第五课&#xff0c;circom实践&#xff0c;需要安装 1 vscode 2 rust&#xff1a;Windows安装Rust环境&…

【C++】模拟(例题 学习)

引言 模拟就是用计算机来模拟题目中要求的操作。 模拟题目通常具有码量大、操作多、思路繁复的特点。由于它代码量大&#xff0c;经常会出现难以查错的情况&#xff0c;如果在考试中写错是相当浪费时间的。 注&#xff1a;模拟没有基础思路和模板&#xff0c;所以要多刷题锻…

vscode中文设置(一招解决)

打开vscode 点击这个Estentions图标 搜索Chinese,直接安装,重启就生效了

Jmeter提取token并设置为全局变量

参考文章&#xff1a;Jmeter提取token并设置为全局变量&#xff08;最详细的步骤&#xff09;_jmeter提取token到全局变量-CSDN博客 一般来说&#xff0c;系统内大多数接口&#xff0c;都需要先获取登录后的token值&#xff0c;所以我们需要创建一个获取token的接口&#xff0c…

es相关概念、索引操作(相当于mysql中的数据库操作)

文章目录 1、概念2、索引操作&#xff08;index&#xff09;2.1、查询索引&#xff08;数据库&#xff09;2.2、创建索引&#xff08;数据库&#xff09;2.3、查看单个索引&#xff08;数据库&#xff09;2.4、删除索引&#xff08;数据库&#xff09; 1、概念 RDBMSesMongoDB…

87.游戏改造-UI修正全面分析

免责声明&#xff1a;内容仅供学习参考&#xff0c;请合法利用知识&#xff0c;禁止进行违法犯罪活动&#xff01; 内容参考于&#xff1a;易道云信息技术研究院 上一个内容&#xff1a;86.游戏改造-UI修正暴力分析 首先来到下图位置 一个函数上来就 ECX4 这种不用想直接就看…

羚羊软件:处理sql server 2008 R2 Error 9003

在很多情况下,服务器突然断电或其他原因会造成&#xff0c;数据库附加时出现&#xff1a;错误代码为90003的错误。 解决办法&#xff1a; 1、新建一个同名得数据库&#xff08;Ly_Men_16_2005&#xff09;。 2、停止SQL服务。 3、用原来得主数据库文件&#xff0c;覆盖新建得…

使用在AMD GPU上运行的ROCm进行大语言模型的自然语言处理任务

Performing natural language processing tasks with LLMs on ROCm running on AMD GPUs — ROCm Blogs 在这篇博客中&#xff0c;您将学习如何使用在AMD的Instinct GPU上运行的ROCm进行一系列流行且有用的自然语言处理&#xff08;NLP&#xff09;任务&#xff0c;使用不同的大…

CSS学习笔记(01)flex布局

1、首先对父元素设置disiplay&#xff1a;felx&#xff0c; 其有6个属性 fex-direction:设置主轴的方向 justify-content:设置主轴上的子元素排列方式 flex-wrap:设置子元素是否换行 align-content:设置侧轴上的子元素的排列方式(多行) align-items:设置侧轴上的子元素排列方式…

Debain 安装 MySql

一 Debian安装MySQL 5.7 1 更新安装列表 sudo apt update 2 添加MySql官方APT仓库到Debian wget https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb sudo dpkg -i mysql-apt-config_0.8.22-1_all.deb先下载再安装源&#xff0c;如下图&#xff1a; 再次执行更新…

从零到一,2024年数据恢复软件新手到专家指南

在数字化的时代&#xff0c;相信你的数据大部分也都是存在一些电子设备里吧。很多时候因为一些意外情况会导致我们数据的丢失&#xff0c;这个时候有什么办法能恢复我们的数据资料呢&#xff1f;这次我们就来一起探讨一些大家都在用的数据恢复工具吧。 1.福昕数据恢复 链接直…

热点 | 爆款游戏的诞生与游戏出海的持续增长

近日&#xff0c;《黑神话&#xff1a;悟空》一经上线就在国内获得了空前的关注。国产大IP3A国际水准带来的超炫视觉体验专业发行与市场营销等&#xff0c;共同引爆了这个现象级的话题。同时&#xff0c;我们也关注到&#xff0c;这款游戏同时在海外多个发行平台进行全球发售。…

Redis 源码安装

目录 1 Redis 的获取 2 Redis 部署 2.1 下载并解压 2.2 Makerfile 文件 2.3 安装所需要编译所需要的包 2.4 开始源码编译 2.5 utils 下的 install_server.sh 脚本文件 2.5 运行脚本进行安装 3 systemd 管理 3.1 编写Redis systemd 服务脚本 3.2 重新加载 systemd 系统 3.3 …

Apache CloudStack Official Document 翻译节选(九)

关于 Apache CloudStack 的 最佳实践 &#xff08;三&#xff09; 配置云外的 防火墙与交换机 对Cisco VNMC&#xff08;Cisco Virtual Network Management Center&#xff09;设备集成云外的客户机网路防火墙&#xff1a; 思科虚拟网络管理中心为思科网络虚拟服务提供了中心…

考试:计算机网络(01)

网络功能和分类 计算机网络是计算机技术与通信技术相结合的产物&#xff0c;它实现了远程通信、远程信息处理和资源共享。 计算机网络的功能&#xff1a;数据通信、资源共享、管理集中化、实现分布式处理、负载均衡。 网络性能指标&#xff1a;速率、带宽(频带宽度或传送线路…