当前位置:网站首页>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
边栏推荐
- Advanced practice of C language (high level) pointer
- Fullgc problem analysis and solution summary
- 抽絲剝繭C語言(高階)指針的進階
- Example of Pushlet using handle of Pushlet
- 非父子组件的通信
- 考研失败,卷不进大厂,感觉没戏了
- Role of virtual machine
- English translation is too difficult? I wrote two translation scripts with crawler in a rage
- JS small exercise ---- time sharing reminder and greeting, form password display hidden effect, text box focus event, closing advertisement
- At the age of 20, I got the ByteDance offer on four sides, and I still can't believe it
猜你喜欢
1、 Go knowledge check and remedy + practical course notes youth training camp notes
Abnova circulating tumor DNA whole blood isolation, genomic DNA extraction and analysis
Music | cat and mouse -- classic not only plot
父组件传递给子组件:Props
毕设-基于SSM大学生兼职平台系统
MIPS uclibc cross compile ffmpeg, support g711a encoding and decoding
Kuboard can't send email and nail alarm problem is solved
考研失败,卷不进大厂,感觉没戏了
Flexible layout (I)
URP - shaders and materials - light shader lit
随机推荐
Unity C function notes
四、高性能 Go 语言发行版优化与落地实践 青训营笔记
普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
About binary cannot express decimals accurately
[semantic segmentation] - multi-scale attention
抽丝剥茧C语言(高阶)指针进阶练习
OOM(内存溢出)造成原因及解决方案
Communication of components
Blue Bridge Cup Birthday candles (violence)
Precise space-time travel flow regulation system - ultra-high precision positioning system based on UWB
1、 Go knowledge check and remedy + practical course notes youth training camp notes
Nesting and splitting of components
Deep learning Flower Book + machine learning watermelon book electronic version I found
計算機服務中缺失MySQL服務
深度学习花书+机器学习西瓜书电子版我找到了
Network foundation - header, encapsulation and unpacking
PostgreSQL source code (60) transaction system summary
MIPS uclibc cross compile ffmpeg, support g711a encoding and decoding
LC interview question 02.07 Linked list intersection & lc142 Circular linked list II
点亮显示屏的几个重要步骤