redis集群的创建安装与配置,以及维护

server/2024/10/21 4:00:03/

一、redis集群配置

port 7000

cluster-enabled yes

cluster-config-file nodes.conf

cluster-node-timeout 5000

appendonly yes

二、安装rubyruby可以充当redis客户端的角色)

yum -y install ruby ruby-devel rubygems rpm-build

gem install redis

三、创建redis集群

1、依次启动node1:7000/7001, node2:7000/7001, node3:7000/7001

[root@node1 7000]# ../src/redis-server redis.conf

2、# 必须使用IP地址不能使用主机名

src/redis-trib.rb create --replicas 1 192.168.199.238:7000 192.168.199.238:7001 \

192.168.199.134:7000 192.168.199.134:7001 192.168.199.237:7000 192.168.199.237:7001

四、启动redis集群

1、 检查

[root@node1 redis]# src/redis-cli -c -h 192.168.0.31 -p 7000 cluster nodes

ebda3f1dad0da2996df119182eab46ed7abedcd9 192.168.0.35:7001 slave 490354a9f25120ee5ae10acc681dc412864ecb03 0 1522055848174 6 connected

490354a9f25120ee5ae10acc681dc412864ecb03 192.168.0.35:7000 master - 0 1522055850183 5 connected 10923-16383

d1a11bf4cc508a11f71d9a40e0aca6c7e491a3c4 192.168.0.33:7000 master - 0 1522055847170 3 connected 5461-10922

c9b21659527f7ce2f234102c4d6b6361e270e5a8 192.168.0.31:7001 slave d1a11bf4cc508a11f71d9a40e0aca6c7e491a3c4 0 1522055849178 3 connected

34604603c5b970b98f0d8351e8811f2688a9c83e 192.168.0.31:7000 myself,master - 0 0 1 connected 0-5460

22c867aa1f70b4cc0ea5c3ca011dd1a2df7da66e 192.168.0.33:7001 slave 34604603c5b970b98f0d8351e8811f2688a9c83e 0 1522055845161 4 connected

2、测试

[root@node1 redis]# src/redis-cli -c -h 192.168.0.31 -p 7000

五、集群扩容

1、增加主节点

# 新节点:192.168.0.31:7002

# 老节点:192.168.0.31:7000

src/redis-trib.rb add-node 192.168.0.31:7002 192.168.0.31:7000

2、增加从节点

# 新节点:192.168.0.31:7002

# 老节点:192.168.0.31:7000

src/redis-trib.rb add-node --slave --master-id 5da7b4b37f4e14638d9558e66166c042b752d417 192.168.0.31:7002 192.168.0.31:7000

六、redis   重新分配redis资源即重新分配槽位

# 老节点:192.168.0.31:7000

src/redis-trib.rb reshard 192.168.0.31:7000

How many slots do you want to move (from 1 to 16384)? 1000 //设置slot数1000 

What is the receiving node ID?  03ccad2ba5dd1e062464bc7590400441fafb63f2 //新节点node 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 //表示全部节点重新洗牌 

Do you want to proceed with the proposed reshard plan (yes/no)?  yes //确认重新分

七、redis集群缩容

1、删除从节点

# 老节点:192.168.0.31:7001

src/redis-trib.rb del-node 192.168.0.31:7001 '9c240333476469e8e2c8e80b089c48f389827265' 

2、删除主节点

1. 删除从节点(注意:需要将从节点转移到其他主节点)

49ed626134079dc301f586ff4edb1670a3a42a8c 被删除主节点ID

192.168.0.31:7000> cluster replicate 49ed626134079dc301f586ff4edb1670a3a42a8c

3. 取消槽位

src/redis-trib.rb reshard 192.168.0.31:7000 // 重新分配槽位

How many slots do you want to move (from 1 to 16384)? 1000 // 被删除master的所有slot数量 

What is the receiving node ID? 5d8ef5a7fbd72ac586bef04fa6de8a88c0671052 // 接收slot的master 

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:49ed626134079dc301f586ff4edb1670a3a42a8c  //被删除master的node-id 

Source node #2:done  

Do you want to proceed with the proposed reshard plan (yes/no)? yes // 取消slot后,reshard

3. 删除主节点

src/redis-trib.rb del-node 192.168.0.31:7000 '49ed626134079dc301f586ff4edb1670a3a42a8c'


http://www.ppmy.cn/server/31928.html

相关文章

08 - 步骤 表输出

简介 表输出(Table Output)步骤是用于将 Kettle 中的数据写入关系型数据库表的步骤。它允许用户将数据流中的数据插入、更新或删除到目标数据库表中。 使用 场景 我要将处理完的数据流中的sysOrgCode 跟 plateNumber 保存记录到mysql 1、拖拽表输出…

基于Spring Boot的音乐网站与分享平台设计与实现

基于Spring Boot的音乐网站与分享平台设计与实现 开发语言:Java框架:springbootJDK版本:JDK1.8数据库工具:Navicat11开发软件:eclipse/myeclipse/idea 系统部分展示 系统功能界面图,在系统首页可以查看首…

GPT-ArcGIS数据处理、空间分析、可视化及多案例综合应用

在数字化和智能化的浪潮中,GIS(地理信息系统)和GPT(生成式预训练模型)的结合正日益成为推动科研、城市规划、环境监测等领域发展的关键技术。GIS以其强大的空间数据处理、先进的空间分析工具、灵活的地图制作与可视化能…

Ubuntu22.04 Jammy新装之后apt不起作用

解决问题:Ubuntu22.04 Jammy新装之后apt不起作用 新安装好Ubuntu22.04 Jammy版本后,发现apt无法使用。 先在个人账户里sudo apt search nvidia 没有显示 跑到root账户apt search nvidia 还是没有显示 测试安装wget: rootfb14:/# apt inst…

【bbs02补】注册功能form组件-前端-后端-总结、登录功能(前端、后端、生成验证码)

1 注册功能 1.1 注册功能form组件 1.2 注册功能前端 1.3 注册功能后端 1.4 forms组件和前后端总结 2 登录功能 2.1 登录前端 2.2 生成验证码 1 注册功能 1.1 注册功能form组件 # 注册页面-用户名-密码-确认密码-邮箱-手机号-头像# form组件 可以帮助我们1 快速生成前端页面2 数…

排序算法之希尔排序(缩小增量排序)

希尔排序是插入排序的优化,如果不了解插入排序可以看排序算法之插入排序-CSDN博客这篇博客,希尔排序算法通过对原始数据集使用 gap 分组的方法,先将数据分组进行插入排序,随着排序的进行,逐渐减小 gap 的值&#xff0c…

爬虫自动化之drissionpage实现随时切换代理ip

目录 一、视频二、dp首次启动设置代理三、dp利用插件随时切换代理一、视频 视频直接点击学习SwitchyOmega插件使用其它二、dp首次启动设置代理 from DrissionPage import ChromiumPage, ChromiumOptions from loguru

数据库(MySQL)—— 多表查询

数据库(MySQL)—— 多表查询 多表关系一对多多对多一对一多表查询概述数据准备查询形式笛卡尔积 分类连接查询内连接外连接左外连接右外连接 自连接联合查询 今天我们来进入MySQL中一个非常重要的部分:多表查询: 多表关系 多表关…