//安装依赖
yum install autoconf automake libtool bzip2
//下载redis-migrate-tool包,并解压
git clone https://github.com/vipshop/redis-migrate-tool
//编译安装
cd redis-migrate-tool
autoreconf -fvi //将configure.ac中的宏展开,生成configure脚本,参考:http://blog.chinaunix.net/uid-17188120-id-5794379.html
./configure //测试
make
src/redis-migrate-tool -h
//配置,单机到cluster ,rmt.conf内容如下
[source]
type: single
hash: fnv1a_64
distribution: ketama
servers :
-192.168.210.141:6381
-192.168.210.141:6380
[target]
type: redis cluster
servers:
-176.17.33.47:7000
-176.17.33.47:7001
-176.17.33.47:7002
[common]
listen: 0.0.0.0:8888
//执行
/usr/local/bin/redis-migrate-tool -c rmt.conf -o log -d
//状态查看
redis-cli -p 8888
127.0.0.1:8888> info
//校验数据
/usr/local/bin/redis-migrate-tool -c rmt.conf -o log -C redis_check
--------------------------- rmt.conf 详细说明 https://github.com/tanruixing88/redis-migrate-tool
Configuration
Config file has three parts: source, target and common.
source OR target:
type: (类型:单机、twemproxy代理、集群和rdb aof等)The group redis type. Possible values are:
single
twemproxy
redis cluster
rdb file
aof file
servers:: (一个redis服务器的列表)The list of redis address in the group. If type is twemproxy, this is same as the twemproxy config file. If type is rdb file, this is the file name.
redis_auth: (密码,有坑,密码需要一致)Authenticate to the Redis server on connect.
timeout: (读写连接时间)Timeout in milliseconds for read/write with Redis server. Now just for source redis group. Defaults to 120000.
hash: (对key做hash操作时使用的哈希函数)The name of the hash function. Just for type is twemproxy. Possible values are:
one_at_a_time
md5
crc16
crc32 (crc32 implementation compatible with libmemcached)
crc32a (correct crc32 implementation as per the spec)
fnv1_64
fnv1a_64
fnv1_32
fnv1a_32
hsieh
murmur
jenkins
hash_tag: (将很多key映射到同一个redis服务器)A two character string that specifies the part of the key used for hashing. Eg "{}" or "$$". Hash tag enable mapping different keys to the same server as long as the part of the key within the tag is the same. Just for type is twemproxy.
distribution: (一半不用,twemproxy类型才用)The key distribution mode. Just for type is twemproxy. Possible values are:
ketama
modula
random
common:
listen: (监听端口 8888)The listening address and port (name:port or ip:port). Defaults to 127.0.0.1:8888.
max_clients: (最大连接数)The max clients count for the listen port. Defaults to 100.
threads: (最大线程数)The max threads count can be used by redis-migrate-tool. Defaults to the cpu core count.
step: (越大越快,但是占用内存)The step for parse request. The higher the number, the more quickly to migrate, but the more memory used. Defaults to 1.
mbuf_size: (缓存大小)Mbuf size for request. Defaults to 512.
noreply: (。。。。。)A boolean value that decide whether to check the target group replies. Defaults to false.
source_safe:(。。。。) A boolean value that protect the source group machines memory safe. If it is true, the tool can guarantee only one redis to generate rdb file at one time on the same machine for source group. In addition, 'source_safe: true' may use less threads then you set. Defaults to true.
dir: (rdb存放目录)Work directory, used to store files(such as rdb file). Defaults to the current directory.
filter: (过滤器,不咋用)Filter keys if they do not match the pattern. The pattern is Glob-style. Defaults is NULL.
filter supported glob-style patterns:
h?llo matches hello, hallo and hxllo
h*llo matches hllo and heeeello
h[ae]llo matches hello and hallo, but not hillo
h[^e]llo matches hallo, hbllo, ... but not hello
h[a-b]llo matches hallo and hbllo