当前位置:网站首页>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
边栏推荐
- LC interview question 02.07 Linked list intersection & lc142 Circular linked list II
- Unity C function notes
- sql中对集合进行非空校验
- Explain Bleu in machine translation task in detail
- 一、Go知识查缺补漏+实战课程笔记 | 青训营笔记
- 聊聊异步编程的 7 种实现方式
- 【云原生】内存数据库如何发挥内存优势
- Readonly read only
- MySQL service is missing from computer service
- Mobx knowledge point collection case (quick start)
猜你喜欢

计算机服务中缺失MySQL服务

Model application of time series analysis - stock price prediction

抽丝剥茧C语言(高阶)数据的储存+练习

1090: integer power (multi instance test)

After 95, the CV engineer posted the payroll and made up this. It's really fragrant

考研失败,卷不进大厂,感觉没戏了

Circulating tumor cells - here comes abnova's solution

URP - shaders and materials - light shader lit

I failed in the postgraduate entrance examination and couldn't get into the big factory. I feel like it's over

Nesting and splitting of components
随机推荐
Reflection (II)
Flexible layout (II)
抽絲剝繭C語言(高階)指針的進階
Abnova membrane protein lipoprotein technology and category display
Dynamics CRM server deployment - restore database prompt: the database is in use
FPGA course: application scenario of jesd204b (dry goods sharing)
Nesting and splitting of components
After 95, the CV engineer posted the payroll and made up this. It's really fragrant
Cloud backup project
詳解機器翻譯任務中的BLEU
Circulating tumor cells - here comes abnova's solution
Pass parent component to child component: props
toRefs API 与 toRef Api
How to * * labelimg
Implementing data dictionary with JSP custom tag
Communication of components
异步组件和Suspense(真实开发中)
三、高质量编程与性能调优实战 青训营笔记
sql中对集合进行非空校验
Composition API premise