当前位置:网站首页>Redis data migration
Redis data migration
2022-07-07 07:29:00 【Interesting soul_ A secular heart】
Realization way 1: utilize redis Master slave replication features
Install the same version of redis , Synchronize the configuration file to the new server . Add the following information
replicaof 192.168.31.216 6379
Then use the client tools to view keys Whether synchronization is complete
Finally, the backup service redis Set the server as the master server
command
// Link client
redis-cli
// View the current master-slave information
info replication
// Set the current slave server as the master server
slaveof no one
// View the master-slave information of the server after the setting is successful
info replication
The following illustration appears , Server setup succeeded
Realization way 2 Use persistent file recovery
redis Support two ways of persistence , One is snapshot (snapshotting), Also known as RDB The way ; The other is to append files (append-only file), Also known as AOF The way .RDB The way is redis Default persistence method .
RDB The way
RDB The method is to write a snapshot of the data in memory in a binary way with the name dump.rdb In the file of . We are right. Redis Set it up , Let it automatically save the dataset periodically according to the settings . modify redis.conf file , as follows
######################### SNAPSHOTTING ################################
#Save the DB on disk:
…
#In the example below the behaviour will be to save:
#after 900 sec (15 min) if at least 1 key changed
#after 300 sec (5 min) if at least 10 keys changed
#after 60 sec if at least 10000 keys changed
#Note: you can disable saving completely by commenting out all “save” lines.
#It is also possible to remove all the previously configured save
#points by adding a save directive with a single empty string argument
#llike in the following example:
#save “”
#900 If there is more than 1 individual key If it is modified, the snapshot will be saved
save 900 1
#300 If there is more than 10 individual key If it is modified, the snapshot will be saved
save 300 10
#60 If there is more than 1000 individual key If it is modified, the snapshot will be saved
save 60 10000
dump.rdb Files are generated by default in %REDIS_HOME%etc Under the table of contents ( Such as /usr/local/redis/etc/), You can modify redis.conf In the document dir Appoint dump.rdb The path to save
#The working directory.
#The DB will be written inside this directory, with the filename specified
#above using the ‘dbfilename’ configuration directive.
#The Append Only File will also be created inside this directory.
#Note that you must specify a directory here, not a file name.
dir ./
AOF The way
RDB The way is to persist data periodically , If it is not time for persistence ,Redis Cause a breakdown for some reason , Then the server will lose the most recent writes 、 And the data that hasn't been saved to the snapshot . So from redis 1.1 It's starting to introduce AOF The way ,AOF Persistent records all write commands executed by the server , And when the server starts , Restore the dataset by reexecuting these commands . AOF All commands in the file are as follows Redis The format of the agreement to save , The new command is appended to the end of the file .
AOF There is still the possibility of losing data , Because the write command may not be written to the disk immediately after receiving the write command , So we can modify redis.conf, To configure redis call write Function to write the command to the file . as follows
#######################APPEND ONLY MODE #############################
…
AOF and RDB persistence can be enabled at the same time without problems.
If the AOF is enabled on startup Redis will load the AOF, that is the file
with the better durability guarantees.
Please check http://redis.io/topics/persistence for more information.
# Enable AOF The way
appendonly yes
# Every time a new order is added to AOF Execute the document once fsync : Very slow , It's also very safe
appendfsync always
# Per second fsync once : Fast enough ( And use RDB Persistence is almost ), And it will only be lost in case of failure 1 Seconds of data
appendfsync everysec
# never fsync : Give the data to the operating system to process . faster , It's also a safer option
appendfsync no
From the top three AOF Persistence timing , In order not to lose data ,appendfsync always Is the safest
- Redis The mechanism of recovery
If you just configure AOF , Load on restart AOF File recovery data ;
If it is configured at the same time RDB and AOF , Start is load only AOF File recovery data ;
If you just configure RDB, Start is to load dump File recovery data .
2. from aof Recovering data in
1 Note the following configuration
appendonly yes
dir /home/redis/data_6379/
2 Copy AOF File to Redis Data directory for
cp appendonly.aof /home/redis/data_6379/
3 start-up redis-server
redis-server redis_6379.conf
3. from RDB File recovery data
1 Note the following configuration
appendonly no
dir /home/redis/data_6379/
2 Copy RDB File to Redis Data directory for
cp dump.db /home/redis/data_6379/
3 start-up redis-server
redis-server redis_6379.conf
边栏推荐
- 记一个并发规则验证实现
- 【leetcode】1020. Number of enclaves
- 弹性布局(二)
- Model application of time series analysis - stock price prediction
- Implementation of AVL tree
- Causes and solutions of oom (memory overflow)
- Modify the jupyter notebook file path
- Stack Title: nesting depth of valid parentheses
- 组件的通信
- SQLMAP使用教程(四)实战技巧三之绕过防火墙
猜你喜欢
随机推荐
Kuboard can't send email and nail alarm problem is solved
C language (high-level) data storage + Practice
2、 Concurrent and test notes youth training camp notes
JS small exercise
Detailed explanation of neo4j installation process
Sqlmap tutorial (IV) practical skills three: bypass the firewall
Docker compose start redis cluster
1089: highest order of factorial
Bindingexception exception (error reporting) processing
Advanced practice of C language (high level) pointer
普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
关于二进制无法精确表示小数
Abnova circulating tumor DNA whole blood isolation, genomic DNA extraction and analysis
点亮显示屏的几个重要步骤
Fast quantitative, abbkine protein quantitative kit BCA method is coming!
Tujia, muniao, meituan... Home stay summer war will start
弹性布局(一)
1、 Go knowledge check and remedy + practical course notes youth training camp notes
$parent (get parent component) and $root (get root component)
详解机器翻译任务中的BLEU