本文摘自:https://www.cnblogs.com/hjfeng1988/p/7146009.html
方法一、Redis数据导出导入-redis-dump and redis-load
一:安装redis-dump
1、yum install ruby rubygems ruby-devel //安装rubygems 以及相关包
# 更改gem源
2、 gem sources -a https://ruby.taobao.org/
[root@172.20.0.3 ~]# gem sources -a http://ruby.taobao.org Error fetching http://ruby.taobao.org: bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
访问http://ruby.taobao.org,公告通知镜像维护站点已迁往Ruby China镜像
#gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/ [root@172.20.0.3 ~]# gem sources --add http://gems.ruby-china.org/ --remove http://rubygems.org/ http://gems.ruby-china.org/ added to sources source http://rubygems.org/ not present in cache [root@172.20.0.3 ~]# gem sources -l *** CURRENT SOURCES *** http://gems.ruby-china.org/ 3、 gem install redis-dump -V
#######报版本错误########
ERROR: Error installing redis-dump: redis requires Ruby version >= 2.2.2.
解决办法:
1.安装RVM: gpg2 --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3 curl -L get.rvm.io | bash -s stable find / -name rvm -print /usr/local/rvm /usr/local/rvm/src/rvm /usr/local/rvm/src/rvm/bin/rvm /usr/local/rvm/src/rvm/lib/rvm /usr/local/rvm/src/rvm/scripts/rvm /usr/local/rvm/bin/rvm /usr/local/rvm/lib/rvm /usr/local/rvm/scripts/rvm 2, source /usr/local/rvm/scripts/rvm 查看rvm库中已知的ruby版本 rvm list known 3,安装一个版本 rvm install 2.3.3 4.使用一个ruby版本 rvm use 2.3.3 [5].设置默认版本 rvm use 2.3.3 --default [root@docker /data/redis 22:14:11]# rvm use 2.3.3 --default Gemset '' does not exist, 'rvm ruby-2.3.3 do rvm gemset create ' first, or append '--create'. [root@docker /data/redis 22:14:22]# rvm use 2.3.3 --default --create ruby-2.3.3 - #gemset created /usr/local/rvm/gems/ruby-2.3.3 ruby-2.3.3 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list ruby-2.3.3 - #generating default wrappers.............. Using /usr/local/rvm/gems/ruby-2.3.3 [6].卸载一个已知版本 rvm remove 2.0.0 查看ruby版本: ruby --version 二、重新安装redis-dump gem install redis-dump -V
2、redis-dump导出
redis-dump -u 127.0.0.1:6379 > test.json redis-dump -u :password@127.0.0.1:6379 > 127.0.0.1.json
3、redis-load导入
cat 172.20.0.1.json | redis-load -u :password@127.0.0.1:6379 cat test.json |redis-load -u 127.0.0.1:6379
方法二、aof导入方式
1、源实例生成aof数据
# 清空上文目标实例全部数据 [root@172.20.0.1 ~]# redis-cli -h 172.20.0.2 -a password flushall OK # 源实例开启aof功能,将在dir目录下生成appendonly.aof文件 [root@172.20.0.1 ~]# redis-cli -h 172.20.0.1 -a password config set appendonly yes OK
2、目标实例导入aof数据
# 假设appendonly.aof就在当前路径下
[root@172.20.0.1 ~]# redis-cli -h 172.20.0.2 -a password --pipe < appendonly.aof All data transferred. Waiting for the last reply... Last reply received from server. errors: 0, replies: 5 # 源实例关闭aof功能 [root@172.20.0.1 ~]# redis-cli -h 172.20.0.1 -a password config set appendonly no OK
方法三、rdb文件迁移方式
暂略
方法四、源实例db0迁移至目标实例db1
[root@172.20.0.1 ~]# cat redis_mv.sh #!/bin/bash redis-cli -h 172.20.0.1 -p 6379 -a password -n 0 keys "*" | while read key do redis-cli -h 172.20.0.1 -p 6379 -a password -n 0 --raw dump $key | perl -pe 'chomp if eof' | redis-cli -h 172.20.0.2 -p 6379 -a password -n 1 -x restore $key 0 echo "migrate key $key" done
原文地址:http://blog.51cto.com/dellinger/2091771