Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

NoSQL-redis backup / master-slave

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Redis persistence-two ways

Redis provides two ways of persistence, namely RDB (Redis DataBase) and AOF (Append Only File).

Official advice: open both ways and back up at the same time. For those with low durability, you can choose snapshot RDB.

RDB: at different points in time, the data stored in redis is snapshots and stored on media such as disks.

Advantages: backup file size is small, recovery speed is fast, and the io child process does not affect the parent process.

Disadvantages: more data will be lost during the failure, and when the dataset is large, the client response will be delayed due to the slow fork process.

Configuration: save 6001, default is dump.rdb (CONFIG GET save & & CONFIG GET dir.)

AOF: is to record all the write instructions executed by redis, and then repeat these write instructions from front to back the next time redis is restarted, and you can achieve data recovery, similar to mysql's binlog. Find cached instruction records according to fsync policy

Advantages: data integrity is good, it will be rewritten automatically when it is too large (change 100write to 1 set), and it is easy to read by redis protocol

Disadvantages: large file size, slow recovery, slow speed due to fsync policy

Configuration: appendonly yes, default file name appendonly.aof (CONFIG GET appendonly)

Restore: for example, if flushall is executed, delete this entry from the backup file and restart it.

Note: rewrite, Redis 2.2 requires manual execution of BGREWRITEAOF commands; 2.4 can automatically trigger AOF rewriting.

Error in AOF file: (redis refuses to load aof file when restart)

A. Back up existing aof files

B, # redis-check-aof-- fix command line executes to repair the existing aof file

C. Compare the difference between the two aof files, restart the server and load the repaired aof backup file.

Two backup strategies are used at the same time. In the case of redis restart, the default aof takes precedence because of high data integrity.

Turn off using two backup strategies, and redis becomes an in-memory database, just like memcache.

Master-slave backup:

Structure and principle: one master can be more than one slave, and one master can also be equipped with multiple slaves.

1. After connecting to the master server, send the sync instruction

2. After receiving the sync instruction, the master starts to execute bgsave and writes the command to the buffer

3. After the end of the bgsave, the master sends the saved .rdb snapshot file to all slaves, during which the write operation continues to be recorded and can be verified by telnet.

4. Load a new snapshot from discarding the old snapshot. When finished, the master continues to send write instructions for the buffer to perform incremental backups.

Configuration: the settings from the server are as follows (of course, you can also modify it within redis, but it is recommended to modify the configuration file)

Port 6380

Slaveof 192.168.1.1 6379 / / configure the primary IP and port

Masterauth / / configure the master's password

Slave-read-only yes / / from read-only to read-only by default after 2.4,

Repl-ping-slave-period 10 / / sets the frequency at which slave initiates ping to master, once every 10s

For more detailed configuration, see the redis section.

Synchronization Policy:

The strategy is that incremental synchronization is attempted first, and if unsuccessful, full synchronization from the slave is required, followed by incremental synchronization.

Master-slave switching

1. Switch manually

Redis-cli-n 6379 shutdown / / turn off the master

Redis-cli-p 6380 slaveof NO ONE / / will be set as the slave master, and whether the set ddd aaa test is successful or not

Cp-f / redis2/dump.rdb / redis/ copy the dump from the slave to the master after the master restore

Redis-server / redis/master.conf / / launch master (to ensure that slave save settings are in effect)

Redis-cli-p 6380 slaveof 192.168.10.1 6379 / / will switch from to slave, that is, ok

2. Automatically switch sentinel

Do not understand for the time being, refer to http://www.cnblogs.com/Xrinehart/p/3502198.html

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report