0
点赞
收藏
分享

微信扫一扫

Redis 克隆数据至新实例


一、 新建目标实例

为方便测试,直接建在同一台服务器,起不同端口。

#建新实例目录
mkdir -p /data/redis/rd6380/{conf,datafile,log}

#编辑新实例配置文件
cp /data/redis/rd6379/conf/redis.conf /data/redis/rd6380/conf/redis.conf

#修改新实例配置文件
vi /data/redis/rd6380/conf/redis.conf

二、 数据克隆

#先用info检查源库key数量
redis-cli

127.0.0.1:6379> info
...
# Keyspace
db0:keys=2909,expires=0,avg_ttl=0
db1:keys=2,expires=0,avg_ttl=0
db2:keys=1,expires=0,avg_ttl=0

#进入源库数据文件目录,拷贝rdb或者aof文件至目标库数据文件目录(不需停业务)
cd /data/redis/rd6379/datafile

[root@redis01 datafile]# ls
appendonly.aof  dump.rdb

cp * /data/redis/rd6380/datafile/

三、 起目标库

#起目标库
redis-server /data/redis/rd6380/conf/redis.conf

#检查目标库key数量
redis-cli -p 6380

127.0.0.1:6380> info
...
# Keyspace
db0:keys=2909,expires=0,avg_ttl=0
db1:keys=2,expires=0,avg_ttl=0
db2:keys=1,expires=0,avg_ttl=0

key数量相同,克隆完成

查看起库日志

less redis.log
#输出
38761:C 04 Nov 16:50:57.430 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
38761:C 04 Nov 16:50:57.430 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=38761, just started
38761:C 04 Nov 16:50:57.431 # Configuration loaded
38762:M 04 Nov 16:50:57.433 * Increased maximum number of open files to 10032 (it was originally set to 1024).
38762:M 04 Nov 16:50:57.435 * Running mode=standalone, port=6380.
38762:M 04 Nov 16:50:57.435 # Server initialized
38762:M 04 Nov 16:51:04.713 * DB loaded from append only file: 7.277 seconds <-- 加载aof文件
38762:M 04 Nov 16:51:04.713 * Ready to accept connections
38762:M 04 Nov 16:51:58.055 * 10000 changes in 60 seconds. Saving...
38762:M 04 Nov 16:51:58.093 * Background saving started by pid 38786
38786:C 04 Nov 16:52:07.712 * DB saved on disk
38786:C 04 Nov 16:52:07.735 * RDB: 12 MB of memory used by copy-on-write
38762:M 04 Nov 16:52:07.817 * Background saving terminated with success

举报

相关推荐

0 条评论