Redis provides two persistence options, the RDB and the AOF, respectively.
By default 60 seconds are flushed to disk once [save 60 10000 when there are 1w keys data is changed when the],redis data set is saved in a binary file called Dump.rdb, this policy is called a snapshot.
You can also manually invoke the Save or Bgsave command:
1
|
/usr/local/bin/redis-cli-h 127.0.0.1-p 6379-a pwd bgsave |
Snapshots are easy to recover and files are small, but the snapshot data may be incomplete if you experience downtime. You may need to enable another persistence mode aof, open [appendonly Yes] in the configuration file.
AOF rules for refreshing logs to disk:
Appendfsync always #always indicates that each write operation is synchronized, very slow and very secure.
Appendfsync everysec #everysec表示对写操作进行累积, synchronized once per second
The official recommendation of the everysec, security, is that the speed is not fast enough, if the machine is in trouble, it may lose 1 seconds of data.
You can also manually perform bgrewriteaof for aof backups:
1
|
/usr/local/bin/redis-cli-h 127.0.0.1-p 6379-a pwd bgrewriteaof |
We are now doing is a master (master) more from (Slave), the main library does not open aof persistence, just back up every day rdb[the official advice is to back up the Rdb file every hour, see your strategy], and on the library to open aof backup, The corresponding backup file is pushed to the backup server using a script.
When the Redis server is hung up, the restart will restore data to memory according to the following priority: If you configure AOF only, load aof file recovery data when restarting, if RBD and AOF are configured at the same time, boot is only load aof file recovery data; If only RBD is configured, startup is to speak load dump file recovery data.
The recovery should be noted that if the main library hangs can not directly restart the main library, otherwise it will directly overwrite the AoF file from the library, make sure that the files to be recovered correctly to start, otherwise it will flush out the original file.
Master-Slave Configuration example
# vim/etc/redis.conf
Daemonize Yes
Port 6379
/var/redis.pid
From server settings
# vim/etc/redis.conf
Daemonize Yes
Port 6300
Slaveof 192.168.1.100 6379
/var/redis.pid