In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Redis supports two persistence strategies: snapshot and commandlog. The former is achieved by periodically writing snapshots of the current memory data to the RDB file, while the latter is achieved by recording the write operations received by the Redis process in log. The next time Redis restarts, the commandlog is played back to restore the data state.
Depending on the actual needs, users can choose to disable persistence completely, or they can enable both RDB and AOF in the same Redis instance.
Special note: if the deployment mode is master-slave, the persistence timing of different instances should be staggered! Prevent master and slaves from going into background persistence at the same time, which may degrade the performance of the system.
1. RDB related configuration
1) databases
Configure the number of db files. You can use the select instruction to specify a db file for each connection for subsequent persistence. New connections use db 0 by default.
2) save
There are a variety of save strategies to choose from for SNAPSHOTTING persistence, and mixed use is supported, such as:
Save 900 1
Save 300 100
Save 60 10000
The effect of the above configuration is that snapshotting will be triggered when any of the three conditions are met: at least one key changes in a. 900s; at least 100 key changes in b. 300s; and at least 10000 key changes in c. 60s
When the save condition is triggered, the Redis implements the asynchronous dump disk in the background through the dump child process. According to fork's write-time replication strategy, if there are many write requests during persistence, in the worst case, the memory required is twice the memory occupied by the current dataset.
Note 1: the three trigger conditions in the above configuration are actually strengthened one by one, and the save policy will be triggered first if the condition is met first.
Note 2: if the business does not need persistence or RDB persistence, you can do so by commenting out the save configuration items.
3) stop-writes-on-bgsave-error
Specify the behavior of Redis when there is an error in the backend dump disk. The default is yes, which means that if there is an error in the backend dump, RedisServer rejects a new write request. This is a way to alert the user and avoid further accidents caused by the user not discovering the exception.
4) rdbcompression
Whether the RDB file is compressed or not, if it is yes, it will consume a little CPU during compression, but save disk space.
5) rdbchecksum
Whether the RDB file needs a CRC64 check. If it is yes, the CRC64 of the RDB file will be calculated and the result will be appended to the end of the file. Similarly, when Redis starts Load RDB, it will first calculate the CRC64 of the file and compare it with the calculation result of dump.
Benefits: the integrity and security of RDB can be strictly guaranteed.
Cost: 10% performance loss in dump or load. If you want to maximize Redis performance, this configuration item should be turned off with no
6) dbfilename
Specifies the RDB file name, which defaults to dump.rdb
7) dir
Specify the path to the directory where the RDB file is stored. If it contains a multi-level path, the relevant parent path must be mkdir in advance, otherwise the startup fails.
2. AOF related configuration
By default, Redis persists data as a RDB file (unless the user actively disables RDB persistence). If the Redis process hangs or the machine is powered off, the new data during the period from the last save completion time to the failure time will be lost. The introduction of AOF can reduce the degree of data loss to 1 second or 1 write instruction.
1) appendonly
Configure whether AOF persistence is enabled. Default is no.
2) appendfilename
Specifies the aof file name, which defaults to appendonly.aof
3) appendfsync
Configure the synchronization method of aof files. Redis supports three methods:
A. no = > redis does not call fsync actively, and when to brush the disk is scheduled by OS
B. always = > redis actively invokes fsync flushing disk for each write command
C. Everysec = > adjust the fsync flush disk every second.
Users can choose the appropriate synchronization strategy according to the sensitivity of the business to data.
4) no-appendfsync-on-rewrite
Specifies whether to call fsync during the background aof file rewrite, which defaults to no, indicating that you want to call fsync (regardless of whether there is a child process in the background or not). Note: there will be a large number of disk IO when Redis writes RDB files or rewrites afo files in the background, and in some linux systems, calling fsync may block.
5) auto-aof-rewrite-percentage
Specifies the condition for Redis to rewrite aof files. The default is 100, which means that background rewrite will be triggered when the current aof file growth exceeds 100% of the last afo file size compared to the aof file size of the last rewrite. If configured to 0, automatic rewrite is disabled.
6) auto-aof-rewrite-min-size
Specifies the size of the aof file that triggers rewrite. If the aof file is less than this value, automatic rewrite will not be triggered even if the increment ratio of the current file reaches the configuration value of auto-aof-rewrite-percentage. That is, rewrite will be triggered only if both configuration items are satisfied.
3. Questions that need to be clear.
1) if both RDB and AFO persistence methods are enabled, the AOF file will be loaded to rebuild the dataset when Redis Server starts, because AOF ensures that the data is relatively complete.
2) for the respective advantages and disadvantages of RDB and AOF and how to choose the appropriate persistence strategy, you can refer to here.
3) in short, if you can tolerate data loss, only RDB can be enabled; if you are sensitive to data, you can enable both RDB and AOF;. It is not recommended to enable only AOF (comment the save configuration item of the configuration file or execute save through redis-cli ""), because once the AOF file is corrupted or bug exists in the AOF parsing engine, the entire dataset cannot be rebuilt.
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.