In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
How does Redis backup and restore database data? In fact, it is not difficult to solve this problem. For this reason, Xiaobian summarized this article. Let's take a look at Redis backup and recovery methods.
All Redis data is stored in memory. Three backup methods are described below:
1. Periodically saved to disk asynchronously, called semi-persistent mode.
1)Semi-persistent RDB mode is also the default mode of Redis backup, which is completed by snapshot. When the relevant conditions set in the redis.conf configuration file are met, Redis will automatically snapshot all data in memory and store it on the hard disk to complete the data backup.
2)RDB snapshot conditions are defined by the user in the redis.conf configuration file, determined by the time and the number of keys changed, when the number of keys changed in the specified time is greater than the specified number, the snapshot will be taken. The following are three preset conditions, as long as one of them is met, the snapshot will be taken.
save 900 1 #Refresh snapshot to hard disk, both requirements must be met before triggering, that is, at least one keyword changes after 900 seconds.
save 300 10 #must be at least 10 keywords changed after 300 seconds.
save 60 10000 #must be at least 10000 keywords changed after 60 seconds.
3)If auto-snapshot is disabled, delete or comment all save parameters.
4)Get the path where redis data is saved:
127.0.0.1:6379> config get dir
"dir"
"/usr/local/redis/bin"
5)It is recommended to modify the data saving path: # vim redis.conf
dir ./ #Default installation directory
dir /data/redis #modified to new path
Operation skill: the configuration file will take effect only if the save path is created first, otherwise the redis service will be destroyed.
[root@redis_master /]# mkdir -p /data/redis
6)Test the modified data storage effect
127.0.0.1:6379> config get dir
"dir"
"/data/redis"
7) The RDB method realizes persistence. Once Redis exits abnormally, all data changed after the last snapshot will be lost.
2. fully persistent AOF model
1)If the data is very important and cannot be lost, you can consider using AOF for persistence. By default, Redis does not have full persistence mode with AOF enabled.
2)Allows AOF and RDB to be turned on simultaneously, ensuring data security and making backup operations very easy.
3)Detailed parameter configuration:
appendonly yes #Enable AOF persistence
appendifilename appendonly.aof #Save filename
appendfsync always #Synchronization is performed every time a write is performed, the safest and slowest
auto-aof-rewirte-percentage 100 #Meaning of parameter When the current AOF file size exceeds the percentage of the file size at the time of the last AOF rewrite, it will be rewritten again. If it has not been rewritten before, it will be based on the AOF file size at startup.
auto-aof-rewrite-min-size 64MB #Limits the minimum size of an AOF file that is allowed to be rewritten.
appendsync everysec #Perform synchronization once per second.
appendsync no #does not actively synchronize, once every 30 seconds, the fastest and not the safest.
3. Redis master-slave replication backup
1)Through persistence, it ensures that even if the server restarts, there will be no loss or small loss of data. However, since the data is stored on a server, if the hard disk of this server fails, it will also cause data loss.
2)To avoid a single point of failure, multiple copies of the database are replicated and deployed on different servers, so that even if one server fails, the other servers can continue to provide service. This requires that when the database on one server is updated, the updated data can be automatically synchronized to other servers.
3)Read/write separation can be achieved based on master-slave synchronization to improve server load capacity.
4)The master database only performs operations, while the slave database is responsible for read operations.
5)Redis can be balanced and highly available based on LVS+keepalived.
6)The master library can be downgraded to a slave library when it crashes, and the slave library can also be upgraded to the master library.
About Redis backup and restore database methods to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you like this post, share it with more people.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.