redis实战第十篇 集群收缩

2024-06-22 19:18

本文主要是介绍redis实战第十篇 集群收缩,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

集群收缩的过程和集群扩容的过程正好是反过来的
将207和207的从节点208从集群下线
1.迁移207上的4096个槽
使用redis-cli迁移槽,先将1365个槽迁移到31上

# redis-cli --cluster reshard 192.168.0.207:6380
...
How many slots do you want to move (from 1 to 16384)? 1365
What is the receiving node ID? 92fd7c2a7b7b8933d1019e72a852f621f6b4faff
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: b94828e8816574d66b413c6bfa6de130eb14ee66
Source node #2: done
...

再将1365个槽迁移到32上

# redis-cli --cluster reshard 192.168.0.207:6380
How many slots do you want to move (from 1 to 16384)? 1365                                    
What is the receiving node ID? ed93d5ea74751d7124a2d5830ce0806a0c962d43
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: b94828e8816574d66b413c6bfa6de130eb14ee66
Source node #2: done
...

再将1366个槽迁移到33上

# redis-cli --cluster reshard 192.168.0.207:6380
How many slots do you want to move (from 1 to 16384)? 1366
What is the receiving node ID? 3641ec8359d5400e5540d77600a2360de8ca367e
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: b94828e8816574d66b413c6bfa6de130eb14ee66
Source node #2: done
...

确认状态,207不再负责任何槽

127.0.0.1:6380> cluster nodes
3c1b16407c984f33b7c0ff06b8a7bbcc59c1d91b 192.168.0.208:6380@16380 slave 3641ec8359d5400e5540d77600a2360de8ca367e 0 1550231654002 15 connected
b94828e8816574d66b413c6bfa6de130eb14ee66 192.168.0.207:6380@16380 master - 0 1550231657009 12 connected

2.忘记节点
Redis提供了cluster forget {downNodeId}命令实现该功能,当节点收到cluster forget {downNodeId}该命令后会在60秒内将该节点加入到禁用列表,但是到了60秒后又会与节点进行Gossip通信。所以要在60秒内在所有节点上执行该操作,如果节点较多很明显执行起来不方便。好在redis还提供另一个更方便的命令 redis-cli --cluster del-node {host:port} {downNodeId}。显示建议使用redis-cli来做忘记节点操作。对于主从都下线的情况,先下线从节点,再下线主节点,避免不必要的全量复制。

[root@kafka31 data]# redis-cli --cluster del-node 192.168.0.31:6380 3c1b16407c984f33b7c0ff06b8a7bbcc59c1d91b
>>> Removing node 3c1b16407c984f33b7c0ff06b8a7bbcc59c1d91b from cluster 192.168.0.31:6380
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
[root@kafka31 data]# redis-cli --cluster del-node 192.168.0.31:6380 b94828e8816574d66b413c6bfa6de130eb14ee66
>>> Removing node b94828e8816574d66b413c6bfa6de130eb14ee66 from cluster 192.168.0.31:6380
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

3.确认集群状态

[root@kafka31 data]# redis-cli -p 6380
127.0.0.1:6380> cluster nodes
ed93d5ea74751d7124a2d5830ce0806a0c962d43 192.168.0.32:6380@16380 master - 0 1550232273000 14 connected 5461-6825 6827-10922
3ba3e8323b7b637c958977335bf7f7213c009929 192.168.0.35:6380@16380 slave ed93d5ea74751d7124a2d5830ce0806a0c962d43 0 1550232273000 14 connected
7fbf45fdc4d0780074f8fe324aac28ae686eebaa 192.168.0.34:6380@16380 slave 92fd7c2a7b7b8933d1019e72a852f621f6b4faff 0 1550232273753 13 connected
3641ec8359d5400e5540d77600a2360de8ca367e 192.168.0.33:6380@16380 master - 0 1550232275759 15 connected 6826 10923-16383
a5ac7dfedd81f2ecd9dd101ef8d9d4f70f895bbf 192.168.0.36:6380@16380 slave 3641ec8359d5400e5540d77600a2360de8ca367e 0 1550232274757 15 connected
92fd7c2a7b7b8933d1019e72a852f621f6b4faff 192.168.0.31:6380@16380 myself,master - 0 1550232274000 13 connected 0-5460

至此,集群节点下线完成。

这篇关于redis实战第十篇 集群收缩的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1085171

相关文章

redis中使用lua脚本的原理与基本使用详解

《redis中使用lua脚本的原理与基本使用详解》在Redis中使用Lua脚本可以实现原子性操作、减少网络开销以及提高执行效率,下面小编就来和大家详细介绍一下在redis中使用lua脚本的原理... 目录Redis 执行 Lua 脚本的原理基本使用方法使用EVAL命令执行 Lua 脚本使用EVALSHA命令

Redis 热 key 和大 key 问题小结

《Redis热key和大key问题小结》:本文主要介绍Redis热key和大key问题小结,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录一、什么是 Redis 热 key?热 key(Hot Key)定义: 热 key 常见表现:热 key 的风险:二、

C#使用StackExchange.Redis实现分布式锁的两种方式介绍

《C#使用StackExchange.Redis实现分布式锁的两种方式介绍》分布式锁在集群的架构中发挥着重要的作用,:本文主要介绍C#使用StackExchange.Redis实现分布式锁的... 目录自定义分布式锁获取锁释放锁自动续期StackExchange.Redis分布式锁获取锁释放锁自动续期分布式

Redis Pipeline(管道) 详解

《RedisPipeline(管道)详解》Pipeline管道是Redis提供的一种批量执行命令的机制,通过将多个命令一次性发送到服务器并统一接收响应,减少网络往返次数(RTT),显著提升执行效率... 目录Redis Pipeline 详解1. Pipeline 的核心概念2. 工作原理与性能提升3. 核

redis过期key的删除策略介绍

《redis过期key的删除策略介绍》:本文主要介绍redis过期key的删除策略,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录第一种策略:被动删除第二种策略:定期删除第三种策略:强制删除关于big key的清理UNLINK命令FLUSHALL/FLUSHDB命

Redis消息队列实现异步秒杀功能

《Redis消息队列实现异步秒杀功能》在高并发场景下,为了提高秒杀业务的性能,可将部分工作交给Redis处理,并通过异步方式执行,Redis提供了多种数据结构来实现消息队列,总结三种,本文详细介绍Re... 目录1 Redis消息队列1.1 List 结构1.2 Pub/Sub 模式1.3 Stream 结

SpringBoot中配置Redis连接池的完整指南

《SpringBoot中配置Redis连接池的完整指南》这篇文章主要为大家详细介绍了SpringBoot中配置Redis连接池的完整指南,文中的示例代码讲解详细,具有一定的借鉴价值,感兴趣的小伙伴可以... 目录一、添加依赖二、配置 Redis 连接池三、测试 Redis 操作四、完整示例代码(一)pom.

Python列表去重的4种核心方法与实战指南详解

《Python列表去重的4种核心方法与实战指南详解》在Python开发中,处理列表数据时经常需要去除重复元素,本文将详细介绍4种最实用的列表去重方法,有需要的小伙伴可以根据自己的需要进行选择... 目录方法1:集合(set)去重法(最快速)方法2:顺序遍历法(保持顺序)方法3:副本删除法(原地修改)方法4:

在Spring Boot中浅尝内存泄漏的实战记录

《在SpringBoot中浅尝内存泄漏的实战记录》本文给大家分享在SpringBoot中浅尝内存泄漏的实战记录,结合实例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录使用静态集合持有对象引用,阻止GC回收关键点:可执行代码:验证:1,运行程序(启动时添加JVM参数限制堆大小):2,访问 htt

Redis在windows环境下如何启动

《Redis在windows环境下如何启动》:本文主要介绍Redis在windows环境下如何启动的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Redis在Windows环境下启动1.在redis的安装目录下2.输入·redis-server.exe