某用户之前买了个16G 的单实例 redis,但是由于其只是存放一些简单的 session 数据,所以用不到这么大,因此希望把数据迁移到一个规格比较小的实例,本文就演示下如何做迁移
模拟环境 A 库: 10.173.32.111 port 6379 B 库:10.173.32.114 port 6379
说明
1.环境必须在 linux 下编译安装,mac 我测试一直提示密码错误,参考 issue
模拟写入数据到 A 库 [root@centos ~] # redis-cli -h 10 .173 .32 .111 10.173.32.111:6379 > auth xxxx OK10.173.32.111:6379 > set foo bar OK10.173.32.111:6379 > get foo"bar" 10.173.32.111:6379 >
特点
快速。
多线程。
基于redis复制。
实时迁移。
迁移过程中,源集群不影响对外提供服务。
异构迁移。
支持Twemproxy集群,redis cluster集群,rdb文件 和 aof文件。
过滤功能。
当目标集群是Twemproxy,数据会跳过Twemproxy直接导入到后端的redis。
迁移状态显示。
完善的数据抽样校验。
迁移工具的来源可以是:单独的redis实例,twemproxy集群,redis cluster,rdb文件,aof文件。
迁移工具的目标可以是:单独的redis实例,twemproxy集群,redis cluster,rdb文件。
地址:https://github.com/vipshop/redis-migrate-tool
centos 先把开发包安装上
yum group install "Development Tools"
编译
$ cd redis-migrate-tool$ autoreconf -fvi $ ./configure $ make $ src/redis-migrate-tool -h
执行
src/redis-migrate-tool -c ~/Downloads/rmt.conf -o log -d
rmt.conf
[source]type : singleservers :- 10.173.32.111:6379redis_auth : xxxx [target]type : singleservers :- 10.173.32.114:6379redis_auth : xxxx [common]listen : 0.0.0.0:8888
连接到B 库去查看下是否有数据
[root@centos redis-migrate-tool] # redis-cli -h 10 .173 .32 .114 10.173.32.114:6379 > auth xxxx OK10.173.32.114:6379 > get foo"bar" 10.173.32.114:6379 >
出现异常可以看下日志
[root@centos redis-migrate-tool]# cat log.log [2018-04-10 13 :34:24.331 ] rmt_core.c:525 Nodes count of source group : 1 [2018-04-10 13 :34:24.332 ] rmt_core.c:526 Total threads count : 2 [2018-04-10 13 :34:24.332 ] rmt_core.c:527 Read threads count assigned: 1 [2018-04-10 13 :34:24.332 ] rmt_core.c:528 Write threads count assigned: 1 [2018-04-10 13 :34:24.332 ] rmt_core.c:836 instances_by_host: [2018-04-10 13 :34:24.332 ] rmt_core.c:840 10.173 .32.111:6379 [2018-04-10 13 :34:24.332 ] rmt_core.c:842 [2018-04-10 13 :34:24.332 ] rmt_core.c:2444 Total threads count in fact: 2 [2018-04-10 13 :34:24.332 ] rmt_core.c:2445 Read threads count in fact: 1 [2018-04-10 13 :34:24.332 ] rmt_core.c:2446 Write threads count in fact: 1 [2018-04-10 13 :34:24.332 ] rmt_core.c:2455 read thread(0 ): [2018-04-10 13 :34:24.332 ] rmt_core.c:2461 10.173 .32.111:6379 [2018-04-10 13 :34:24.332 ] rmt_core.c:2488 write thread(0 ): [2018-04-10 13 :34:24.332 ] rmt_core.c:2494 10.173 .32.111:6379 [2018-04-10 13 :34:24.333 ] rmt_core.c:2551 migrate job is running... [2018-04-10 13 :34:24.335 ] rmt_redis.c:1706 Start connecting to MASTER[10.173.32.111 :6379 ]. [2018-04-10 13 :34:24.335 ] rmt_redis.c:1740 Master[10.173.32.111 :6379 ] replied to PING, replication can continue... [2018-04-10 13 :34:24.335 ] rmt_redis.c:1051 Partial resynchronization for MASTER[10.173.32.111 :6379 ] not possible (no cached master). [2018-04-10 13 :34:24.336 ] rmt_redis.c:1110 Full resync from MASTER[10.173.32.111 :6379 ]: d48a2a3890d782e5f4a34f9d0d463fded99770dc:141768 [2018-04-10 13 :34:24.378 ] rmt_redis.c:1517 MASTER <-> SLAVE sync: receiving 29 bytes from master[10.173.32.111 :6379 ] [2018-04-10 13 :34:24.378 ] rmt_redis.c:1623 MASTER <-> SLAVE sync: RDB data for node[10.173.32.111 :6379 ] is received, used: 0 s [2018-04-10 13 :34:24.379 ] rmt_redis.c:1643 rdb file node10.173.32.111 :6379 -1523338464336559 -33353 .rdb write complete [2018-04-10 13 :34:24.379 ] rmt_redis.c:6601 Rdb file for node[10.173.32.111 :6379 ] parsed finished, use: 0 s. [2018-04-10 13 :34:24.379 ] rmt_redis.c:6709 All nodes' rdb file parsed finished for this write thread(0 ).
查看复制进度
➜ ~ redis-cli -h 127.0 .0 .1 -p 8888 info# Server version: 0.1 .0 os: Darwin 17.5 .0 x86_64multiplexing_api: kqueuegcc_version: 4.2 .1 process_id: 9546 tcp_port: 8888 uptime_in_seconds: 214 uptime_in_days: 0 config_file: /Users/wenjun/Downloads/rmt.conf# Clients connected_clients: 1 max_clients_limit: 100 total_connections_received: 2 # Memory mem_allocator: jemalloc-0.0 .0 # Group source_nodes_count: 1 target_nodes_count: 1 # Stats all_rdb_received: 1 all_rdb_parsed: 0 all_aof_loaded: 0 rdb_received_count: 1 rdb_parsed_count: 0 aof_loaded_count: 0 total_msgs_recv: 0 total_msgs_sent: 0 total_net_input_bytes: 383 total_net_output_bytes: 0 total_net_input_bytes_human: 383 Btotal_net_output_bytes_human: 0 Btotal_mbufs_inqueue: 21 total_msgs_outqueue: 0
info命令响应指令:
服务器:
版本:redis-migrate-tool版本号。
操作系统:操作系统uname。
multiplexing_api:复用API。
gcc_version:Gcc版本。
process_id:redis-migrate-tool的进程ID。
tcp_port:tcp端口redis-migrate-tool监听。
uptime_in_seconds:秒运行redis-migrate-tool。
uptime_in_days:运行redis-migrate- tools的日子。
config_file:redis-migrate-tool的配置文件名。
客户:
connected_clients:目前连接的客户端的数量。
max_clients_limit:允许同时接受的最大客户数量。
total_connections_received:到目前为止收到的连接总数。 组:
source_nodes_count:源redis组的节点数。
target_nodes_count:目标redis组的节点数。 统计:
all_rdb_received:是否收到源组中所有节点的rdb。
all_rdb_parsed:源组中已解析的节点的所有rdb是否完成。
all_aof_loaded:源组中的节点的所有aof文件是否已加载完成。
rdb_received_count:源组中节点的接收rdb计数。
rdb_parsed_count:源组中节点的解析完成rdb数量。
aof_loaded_count:加载完成的源组中节点的aof文件数量。
total_msgs_recv:从源组收到的消息总数。
total_msgs_sent:已发送到目标组并收到目标组响应的消息总数。
total_net_input_bytes:从源组收到的输入字节总数。
total_net_output_bytes:已发送到目标组的输出字节总数。
total_net_input_bytes_human:同total_net_input_bytes,但转换为人类可读的。
total_net_output_bytes_human:同total_net_output_bytes,但转换为人类可读的。
total_mbufs_inqueue:通过mbufs从源组输入缓存的命令数据(不包括rdb数据)。
total_msgs_outqueue:消息将被发送到目标组,消息已发送到目标,但正在等待响应。
停止
➜ ~ redis-cli -h 127 .0 .0 .1 -p 8888 127.0.0.1:8888 > shutdown OK (10 .00s)127.0.0.1:8888 >
文章作者: 阿文
版权声明: 本博客所有文章除特别声明外,均采用
CC BY-NC-SA 4.0 许可协议。转载请注明来自
阿文的博客 !