redis中的AOF和RDB备份 [英] AOF and RDB backups in redis

查看:46
本文介绍了redis中的AOF和RDB备份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是关于Redis持久化的.

This question is about Redis persistence.

我使用 redis 作为社交网站的快速后端".这是一个单一的服务器设置.我一直在稳步地将 PostgreSQL 的职责转移到 Redis.目前在 etc/redis/redis.conf 中,appendonly 设置设置为 appendonly no.快照设置为save 900 1save 300 10save 60 10000.所有这些都适用于生产和开发.根据生产日志,save 60 10000 被大量调用.这是否意味着实际上,我每 60 秒获取一次备份?

I'm using redis as a 'fast backend' for a social networking website. It's a single server set up. I've been transferring PostgreSQL responsibilities to Redis steadily. Currently in etc/redis/redis.conf, the appendonly setting is set to appendonly no. Snapshotting settings are save 900 1, save 300 10, save 60 10000. All this is true for production and development both. As per production logs, save 60 10000 gets invoked heavily. Does this mean that practically, I'm getting backups every 60 seconds?

一些文献建议同时使用 AOF 和 RDB 备份.因此,我正在权衡打开 appendonly 并使用 appendfsync everysec.对于任何有过硬币两面经验的人:

Some literature suggests using AOF and RDB backups together. Thus I was weighing in on turning appendonly on and using appendfsync everysec. For anyone who has had experience of both sides of the coin:

1) 使用 appendonly onappendfsync everysec 会导致性能下降吗?会撞到CPU吗?写入负载偏高.

1) Will using appendonly on and appendfsync everysec cause a performance downgrade? Will it hit the CPU? The write load is on the high side.

2) 使用这些新设置重新启动 redis 服务器后,我仍然会丢失最后 60 秒的数据,对吗?

2) Once I restart the redis server with these new settings, I'll still lose the last 60 secs of my data, correct?

3) 重启时间需要担心吗?我的 dump.rdb 文件很小;约 90MB.

3) Are restart times something to worry about? My dump.rdb file is small; ~90MB.

我正在尝试了解有关 redis 持久性的更多信息,并满足我的期望.就我个人而言,在灾难的情况下丢失 60s 的数据我很好,因此我是否应该使用 AOF 也是我正在思考的事情.随意插话.谢谢!

I'm trying to find out more about redis persistence, and getting my expectations right. Personally, I'm fine with losing 60s of data in the case of a catastrophe, thus whether I should use AOF is also something I'm pondering. Feel free to chime in. Thanks!

推荐答案

这是否意味着实际上,我每 60 秒获取一次备份?

Does this mean that practically, I'm getting backups every 60 seconds?

.Redis 在 60 秒后进行后台保存,如果至少有 10000 个键被更改.否则,它不会进行后台保存.

NO. Redis does a background save after 60 seconds, if there're at least 10000 keys have been changed. Otherwise, it doesn't do a background save.

使用 appendonly on 和 appendfsync 是否会导致性能下降?会撞到CPU吗?写入负载偏高.

Will using appendonly on and appendfsync everysec cause a performance downgrade? Will it hit the CPU? The write load is on the high side.

这取决于很多事情,例如磁盘性能(SSD VS HDD)、写/读负载(QPS)、数据模型等.您需要在特定环境中使用自己的数据进行基准测试.

It depends on many things, e.g. disk performance (SSD VS HDD), write/read load (QPS), data model, and so on. You need do a benchmark with your own data in your specific environment.

一旦我使用这些新设置重新启动 redis 服务器,我仍然会丢失最后 60 秒的数据,对吗?

Once I restart the redis server with these new settings, I'll still lose the last 60 secs of my data, correct?

.如果同时开启AOF和RDB,当Redis重启时,会使用AOF文件重建数据库.由于您将其配置为appendfsync everysec,您只会丢失最后1 秒 的数据.

NO. If you turn on both AOF and RDB, when Redis restarts, the AOF file will be used to rebuild the database. Since you config it to appendfsync everysec, you will only lose the last 1 second of data.

重启时间需要担心吗?我的 dump.rdb 文件很小;约 90MB.

Are restart times something to worry about? My dump.rdb file is small; ~90MB.

如果开启AOF,当Redis重启时,它会重放AOF文件中的日志来重建数据库.通常 AOF 文件比 RDB 文件大,并且它可能比从 RDB 文件恢复慢.你应该担心吗?在您的特定环境中使用您自己的数据进行基准测试.

If you turn on AOF, and when Redis restarts, it replays logs in AOF file to rebuild the database. Normally AOF file is larger then RDB file, and it might be slower than recovering from RDB file. Should you worry about that? Do a benchmark with your own data in your specific environment.

编辑

重要通知

假设您已经将Redis设置为使用RDB保存,并向Redis写入大量数据.过了一会儿,你要打开AOF保存.切勿修改配置文件以打开 AOF 并重新启动 Redis,否则您将丢失一切.

Assume that you already set Redis to use RDB saving, and write lots of data to Redis. After a while, you want to turn on AOF saving. NEVER MODIFY THE CONFIG FILE TO TURN ON AOF AND RESTART REDIS, OTHERWISE YOU'LL LOSE EVERYTHING.

因为,一旦你在redis.conf中设置了appendonly yes,并重启Redis,它会从AOF文件中加载数据,不管文件是否存在.如果文件不存在,它会创建一个空文件,并尝试从该空文件加载数据.所以你会失去一切.

Because, once you set appendonly yes in redis.conf, and restart Redis, it will load data from AOF file, no matter whether the file exists or not. If the file doesn't exist, it creates an empty file, and tries to load data from that empty file. So you'll lose everything.

其实不用重启Redis就可以开启AOF.相反,您可以使用 config set 命令动态打开它:config set appendonly yes.

In fact, you don't have to restart Redis to turn on AOF. Instead, you can use config set command to dynamically turn it on: config set appendonly yes.

这篇关于redis中的AOF和RDB备份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆