一:Redis集群环境准备

1:需要先安装好Redis集群环境并配置好集群

192.168.0.113 7001-7003

192.168.0.162 7004-7006

2:检查redis集群

[root@localhost src]# ./redis-cli -c -h 192.168.0.113 -a 123456 -p 7001

192.168.0.113:7001>  cluster nodes

3:确保redis集群没有数据

192.168.0.113:7001> dbsize

(integer)0

192.168.0.113:7002> dbsize

(integer) 0

192.168.0.113:7003> dbsize

(integer) 0

192.168.0.113:7004> dbsize

(integer) 0

192.168.0.113:7005> dbsize

(integer) 0

192.168.0.113:7006> dbsize

(integer) 0

4:如果有数据需要删除

47.91.110.137:7001> flushdb

二:Redis单节点环境准备

1:查看Redis单节点数据大小

[root@localhost src]# ./redis-cli -c -h 192.168.0.113 -p 6379 -a 123456

192.168.0.113:6379> dbsize

(integer) 10000

2:备份好单节点redis的 aof 数据(备注:如果开启的是  rdbcompression yes  请备份  rdb)

[root@ce redis-3.2.9]# du -h --max-depth=1 appendonly.aof

三:同步数据到Redis集群

1:查看Redis集群节点卡槽

[root@localhost src]# ./redis-cli --cluster check 192.168.0.113:7001 -a 123456

主节点对应的卡槽

7001

2fd4ec03e71d6f99718621303dcdf191189df70e 192.168.0.113:7001    slots:[0-5460] (5461 slots) master

7002

ccf4f69e46aa6c3918fb0ebb53172d463eba65e0 192.168.0.113:7002    slots:[10923-16383] (5461 slots) master

7004

1840c7329348d4f42dc89fa93526f91a4e172d33 192.168.0.162:7004    slots:[5461-10922] (5462 slots) master

2:在Redis集群上把 7002  和  7004 卡槽值迁移到7001卡槽上

7002值移动到7001

[root@localhost src]# ./redis-cli --cluster reshard 192.168.0.113:7001 --cluster-from ccf4f69e46aa6c3918fb0ebb53172d463eba65e0 --cluster-to 2fd4ec03e71d6f99718621303dcdf191189df70e --cluster-slots 5461 --cluster-yes -a 123456

7004值移动到7001

[root@localhost src]# ./redis-cli --cluster reshard 192.168.0.113:7001 --cluster-from 1840c7329348d4f42dc89fa93526f91a4e172d33 --cluster-to 2fd4ec03e71d6f99718621303dcdf191189df70e --cluster-slots 5462 --cluster-yes -a 123456

3:可以看到7001卡槽拥有了全部16384个slots,7002、7004卡槽上已经没有slots了

[root@localhost src]# ./redis-cli --cluster check 192.168.0.113:7001 -a 123456

四:把Redis单节点的aof数据导入到集群7001对应的aof目录下替换集群aof源文件

1:先备份好集群7001的aof数据

[root@localhost src]# cd /usr/local/cluster/7001/db/

172.26.225.1:7001>  set name diaocow

[root@localhost 7001]# cp appendonly.aof appendonly.aof.bwk

[root@localhost 7001]# cd /usr/local/redis-5.0.5/

[root@localhost redis-5.0.5]# cp appendonly.aof /usr/local/cluster/7001/db/

2:重启Redis集群7001节点

关闭

[root@localhost 7001]# ps -ef | grep redis

[root@localhost 7001]# kill -9 1371

启动

[root@localhost 7001]# ./redis-server redis.conf

查看redis集群7001节点是否正常启动

[root@localhost 7001]# ps -ef | grep redis

3:重启之后可以看到数据加载到7001卡槽上

[root@localhost src]# ./redis-cli -c -h 192.168.0.113 -p 7001 -a 123456

192.168.0.113:7001> dbsize

(integer) 1000

五:分配Redis集群7001卡槽值

1:7001卡槽值分配到7002

[root@localhost src]# ./redis-cli --cluster reshard 192.168.0.113:7001 -a 123456 --cluster-from 2fd4ec03e71d6f99718621303dcdf191189df70e --cluster-to ccf4f69e46aa6c3918fb0ebb53172d463eba65e0 --cluster-slots 5461 --cluster-yes

2:7001卡槽值分配到7004

[root@localhost src]# ./redis-cli --cluster reshard 192.168.0.113:7001 -a 123456 --cluster-from 2fd4ec03e71d6f99718621303dcdf191189df70e --cluster-to 1840c7329348d4f42dc89fa93526f91a4e172d33 --cluster-slots 5462 --cluster-yes

3:查看slots是否移动成功

[root@localhost src]# ./redis-cli -c -h 192.168.0.113 -a 123456 -p 7001

192.168.0.113:7001>  cluster nodes

六:验证数据的完整

1:查看集群是否正常,slots分配是否正常(cluster_state:ok)

[root@localhost src]# ./redis-cli -c -h 192.168.0.113 -a 123456 -p 7001

192.168.0.113:7001> cluster info

cluster_state:ok

cluster_slots_assigned:16384

cluster_slots_ok:16384

cluster_slots_pfail:0

cluster_slots_fail:0

cluster_known_nodes:6

cluster_size:2 cluster_current_epoch:9

cluster_my_epoch:7

cluster_stats_messages_ping_sent:7151

cluster_stats_messages_pong_sent:7087

cluster_stats_messages_update_sent:36

cluster_stats_messages_sent:14274

cluster_stats_messages_ping_received:7087

cluster_stats_messages_pong_received:7151

cluster_stats_messages_received:14238

2:验证key的数量是否正常

192.168.0.113(7001-7003)

[root@localhost src]# ./redis-cli -c -h 192.168.0.113 -a 123456 -p 7001 dbsize

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. (integer) 0

[root@localhost src]# ./redis-cli -c -h 192.168.0.113 -a 123456 -p 7002 dbsize

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. (integer) 6685

[root@localhost src]# ./redis-cli -c -h 192.168.0.113 -a 123456 -p 7003 dbsize

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. (integer) 3315

192.168.0.162(7004-7006)

[root@localhost src]#

[root@localhost src]# ./redis-cli -c -h 192.168.0.162 -a 123456 -p 7004 dbsize

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. (integer) 3315

[root@localhost src]# ./redis-cli -c -h 192.168.0.162 -a 123456 -p 7005 dbsize

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. (integer) 6685

[root@localhost src]# ./redis-cli -c -h 192.168.0.162 -a 123456 -p 7006 dbsize

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. (integer) 0

192.168.0.113(7001-7003)

6685+ 3315=10000        redis单卡槽key数量10000

192.168.0.162(7004-7006)

3315+6685=10000redis单卡槽key数量10000

七:注意  如果数据量很大  slots不要一次性迁移到Redis集群 ,需要一部分一部分转移

Redis单节点数据同步到Redis集群的更多相关文章

  1. 集群版本升级——rolling upgrade在ES 单节点从 restart 到加入集群,大概要 100s 左右的时间。也就是说,这 100s 内,该节点上的所有分片都是 unassigned 状态

    集群版本升级 Elasticsearch 作为一个新兴项目,版本更新非常快.而且每次版本更新都或多或少带有一些重要的性能优化.稳定性提升等特性.可以说,ES 集群的版本升级,是目前 ES 运维必然要做 ...

  2. Redis和MySQL数据同步及Redis使用场景

    1.同步MySQL数据到Redis (1) 在redis数据库设置缓存时间,当该条数据缓存时间过期之后自动释放,去数据库进行重新查询,但这样的话,我们放在缓存中的数据对数据的一致性要求不是很高才能放入 ...

  3. Redis单台的安装部署及集群部署

    Redis是一种高级key-value数据库.它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富.有字符串,链表,集 合和有序集合.支持在服务器端计算集合的并,交和补集(diff ...

  4. Redis02——Redis单节点安装

    Redis单节点安装 一.Redis的数据类型 string hash list set zset 二.安装 2.1.下载 wget http://download.redis.io/releases ...

  5. redhat6.5 redis单节点多实例3A集群搭建

    在进行搭建redis3M 集群之前,首先要明白如何在单节点上完成redis的搭建. 单节点单实例搭建可以参看这个网:https://www.cnblogs.com/butterflies/p/9628 ...

  6. Redis:Java链接redis单节点千万级别数据 写入,读取 性能测试

    本文是对Redis 单节点,针对不同的数据类型,做插入行测试. 数据总条数为:10058624 环境说明:             Redis 未做任何优化, 单节点    (服务器上, 内存64G) ...

  7. redis如何实现数据同步

    redis如何实现数据同步 两种,1全同步,2部分同步 全备份: 在slave启动时会向master发送sync消息,master收到slave这条消息之后,将启动后台备份进程,备份完成之后,将备份数 ...

  8. Redis源码阅读(六)集群-故障迁移(下)

    Redis源码阅读(六)集群-故障迁移(下) 最近私人的事情比较多,没有抽出时间来整理博客.书接上文,上一篇里总结了Redis故障迁移的几个关键点,以及Redis中故障检测的实现.本篇主要介绍集群检测 ...

  9. Redis源码阅读(四)集群-请求分配

    Redis源码阅读(四)集群-请求分配 集群搭建好之后,用户发送的命令请求可以被分配到不同的节点去处理.那Redis对命令请求分配的依据是什么?如果节点数量有变动,命令又是如何重新分配的,重分配的过程 ...

随机推荐

  1. 利用python+graphviz绘制数据结构关系图和指定目录下头文件包含关系图

    作为一名linux系统下的C语言开发,日常工作中经常遇到两个问题: 一是分析代码过程中,各种数据结构互相关联,只通过代码很难理清系统中所有结构体的整体架构,影响代码消化的效率; 二是多层头文件嵌套包含 ...

  2. ios 键盘弹起bug,出现的问题,光标穿透,页面无法点击

    有时候使用ios输入键盘以后,直接点击页面按钮会出现事件无效. 解决方法: 1. 输入框输入后点击提交按钮后,弹窗会发现光标穿透问题 解决方法: 使用input blur()事件使input失去焦点 ...

  3. shell基本运算符(五)

    shell支持多种运算符,包括:算术运算符.关系运算符.布尔运算符.字符串运算符.文件测试运算符. 注意:条件表达式要放在方括号之间,并且要有空格,eg:[$a==$b] 是错误的,必须写成 [ $a ...

  4. chrome devtools tip(1)--调试伪类

    开发中我们经常遇到,添加些focus,hover事件,样式,但当我们去打开 chrome devtools,浮动上去的时候,然后准备去改变样式的时候,结果由于光标移动了,样式不见了,非常不方便调试,其 ...

  5. ExtJs 扩展类CheckColumn修改源码,支持按条件禁用启用下拉框功能

    长话短说,具体的请看图 需求如图: 修改CheckColumn.js源码,添加鼠标点击改变事件 完整JS脚本 Ext.ns('Ext.ux.grid'); Ext.ux.grid.CheckColum ...

  6. OptimalSolution(4)--字符串问题(1)简单

    一.判断两个字符串是否互为变形词 问题:给定两个字符串str1和str2,如果str1和str2中出现的字符种类一样且每种字符出现的次数也一样,那么str1与str2互为变形词. 举例:str1=“1 ...

  7. Flask解析(二):Flask-Sqlalchemy与多线程、多进程

    Sqlalchemy flask-sqlalchemy的session是线程安全的,但在多进程环境下,要确保派生子进程时,父进程不存在任何的数据库连接,可以通过调用db.get_engine(app= ...

  8. MongoDB系列---用户及权限管理02

    MongoDB-——Privilege 学习大纲: 1.用户权限管理 2.用户操作 知识回顾:  本系列上一篇博文我们讲述了如何搭建环境以及配置我们的MongoDB,通过搭建环境后我们又学习了如何通过 ...

  9. 构建企业级数据湖?Azure Data Lake Storage Gen2实战体验(下)

    相较传统的重量级OLAP数据仓库,“数据湖”以其数据体量大.综合成本低.支持非结构化数据.查询灵活多变等特点,受到越来越多企业的青睐,逐渐成为了现代数据平台的核心和架构范式. 作为微软Azure上最新 ...

  10. Apache Solr Velocity模板远程代码执行复现

    0x01漏洞描述 2019年10月31日,国外安全研究员s00py在Github公开了一个Apache Solr Velocity模板注入远程命令执行的poc. 经过研究,发现该0day漏洞真实有效并 ...