昨晚进行了redis服务器迁移动作,按照常规迁移过程,应用停止redis触发rdb保存后,迁移服务器不会对数据产生影响。但是,今天早上有一台服务器丢数据了。
解决方案
出现了该问题后,我们进行了如下处理:
1,我们考虑是不是么有开启持久化,导致重启以后redis数据丢失。经过检查配置文件发现RDB默认已经开启。
2,于是怀疑以前运行的redis.conf和现在的redis.conf文件不同,导致rdb文件存储路径发生了变化。按照现在的redis.conf文件,重新启动了redis服务。
[root@shizhanxia.com ]# pkill -f redis-server [root@shizhanxia.com ]# redis-server /home/app01/redis/redis.conf
3,开启aof持久化。
在redis-cli中输入#config set appendonly yes 或者编辑redis.conf配置文件 [root@shizhanxia.com ]# vi /home/app01/redis/redis.conf appendonly yes
4,重启redis-server服务,发现数据又丢了。我的rdb和aof文件在哪里?
[root@shizhanxia.com ]# find / -name "*.rdb" [root@shizhanxia.com ]# find / -name "*.aof" 搜索发现,系统中出现了几个不同位置的持久化文件,我的工作目录在哪里? [root@shizhanxia.com ]#cat /home/app01/app01/redis/redis.conf |grep dir dir ./
问题总结
工作目录./不是梦想中的/home/app01/redis目录,而是,你在启动redis-server时候的当前目录。所以,随着启动redis-server次数及位置不同,你重启后的redis-server可能会找不到原来的持久化数据。
如何导入其他rdb文件中的数据呢?在命令行中执行:
redis-cli --rdb rdb_filename.rdb
导入该rdb文件中保存的数据。
扩展阅读
# The working directory. # The DB will be written inside this directory, with the filename specified # above using the ‘dbfilename’ configuration directive. # The Append Only File will also be created inside this directory. # Note that you must specify a directory here, not a file name.