In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The usual design approach is:
The replication mechanism is used to compensate for the shortcomings of aof and snapshot performance, and the data can be persisted.
That is, RDB and AOF on master are not enabled to ensure master's read and write performance.
On the slave, RDB and AOF are enabled at the same time for persistence to ensure data security.
If the data is to be persisted and you want to ensure stability, it is recommended to leave half of the physical memory.
Because during snapshot, the child process that forks out to dump consumes the same memory as the parent process,
True copy-on-write, the impact on performance and memory consumption are relatively large.
Environment Description:
master: 192.168.2.100 Do not open RDB and AOF
slave: 192.168.2.200 Open RDB and AOF
Configuration information:
master:
# vim etc/redis.conf
#save 600 5 //disable RDB
appendonly no //disable AOF
requirepass 123456 //Specify authentication password
slave:
# vim etc/redis.conf
save 600 5 //Open RDB
dbfilename "dump_6379.rdb" //RDB file
dir "/usr/local/redis-3.0.6-6379" //RDB file path
appendonly yes //Open AOF
appendfilename "appendonly.aof" //Specify an AOF file
appendfsync everysec //Force writes to disk once per second
no-appendfsync-on-rewrite no //command appends are not performed during log rewriting
auto-aof-rewrite-percentage 100 //overwrite when current AOF exceeds previous AOF size by 100%
auto-aof-rewrite-min-size 64mb //log rewrite minimum
slaveof 192.168.2.100 6379 //Specify main library IP and port
masterauth 123456 //Specify the login password for the master library
Start redis:
master:# redis-server etc/redis.conf
slave:# redis-server etc/redis.conf
Master creates key:
# redis-cli -a 123456
127.0.0.1: 6379> info replication //Check whether the master-slave relationship is correct
127.0.0.1: 6379> keys * //At this time, there is no RDB file in the master installation directory.
(empty list or set)
127.0.0.1:6379> set name zhagnsan //Create 3 keys
OK
127.0.0.1:6379> set age 26
OK
127.0.0.1:6379> set home beijing
OK
slave check synchronization:
# redis-cli
127.0.0.1: 6379> keys * //data synchronized
1) "age"
2) "home"
3) "name"
Simulate master fault:
# ps -ef |grep redis
root 126472 1 0 21:58 ? 00:00:02 redis-server *:6379
root 127714 2844 0 22:29 pts/0 00:00:00 grep --color=auto redis
# kill -9 126472
# rm -rf dump_6379.rdb
slave View master-slave status:
# redis-cli
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:192.168.2.100
master_port:6379
master_link_status:down //We see that master is no longer accessible, slave is normal
master_last_io_seconds_ago:-1
... ...
Disaster Recovery:
1. Cancel the synchronization status of slave
Avoid restarting the master without completing the data recovery, resulting in overwriting the data on the slave and eventually losing the data.
127.0.0.1: 6379> SLAVEOF no one //dynamically modify the configuration file to set slavof to no
OK
127.0.0.1: 6379> info repolarization//View master-slave information, no longer available
127.0.0.1:6379>
2. Start redis of master and confirm that the data does not exist (this step can be ignored, I just want to confirm that there is no data)
# redis-server etc/redis.conf
# redis-cli -a 123456
127.0.0.1:6379> keys *
(empty list or set)
# ps -ef |grep redis
root 128031 1 0 22:45 ? 00:00:00 redis-server *:6379
root 128050 2844 0 22:46 pts/0 00:00:00 grep --color=auto redis
# kill -9 128031 //abnormal close redis again
# rm -rf dump_6379.rdb //Delete RDB file again
3. Copy RDB files and AOF files to master
# scp dump_6379.rdb 192.168.2.100:/usr/local/redis-3.0.6-6379/
# scp appendonly.aof 192.168.2.100:/usr/local/redis-3.0.6-6379/
4. Master opens RDB, opens AOF
# vim etc/redis.conf
save 600 5 //Open RDB
dbfilename "dump_6379.rdb" //RDB file
dir "/usr/local/redis-3.0.6-6379" //RDB file path
appendonly yes //Open AOF
appendfilename "appendonly.aof" //Specify an AOF file
... ...
5. Master starts redis and checks the database. The data has been recovered.
# redis-server etc/redis.conf
# redis-cli -a 123456
127.0.0.1:6379> keys *
1) "home"
2) "name"
3) "age"
6. After master data recovery, RDB and AOF need to be turned off to ensure their own reading and writing performance.
However, RDB files and AOF files should be retained (deleted after data cannot be recovered)
Although RDB files and AOF files exist, they do not increase in size, only the AOF files of salve increase.
# kill [redis PID] //close redis
# vim etc/redis.conf //Close RDB and AOF
#save 600 5
appendonly no
# redis-server etc/redis.conf //start redis
# redis-cli -a 123456
127.0.0.1: 6379> keys * //Turn off RDB and AOF functions, the data in the library still exists
1) "home"
2) "name"
3) "age"
7. Slave opens synchronization state
127.0.0.1:6379> SLAVEOF 192.168.2.100 6379 //Start synchronization
OK
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:192.168.2.100
master_port:6379
master_link_status:up //master can be accessed normally
master_last_io_seconds_ago:5
master_sync_in_progress:0
... ...
8. Master creates key
127.0.0.1: 6379> set abc 123 //Add a new key
OK
127.0.0.1:6379> keys *
1) "abc"
2) "home"
3) "name"
4) "age"
9. slave View synchronization
127.0.0.1:6379> keys *
1) "abc"
2) "age"
3) "home"
4) "name"
Summary:
During this recovery, we used both AOF and RDB files, so which file did the recovery take place?
1. If only RDB is configured, the RDB file is loaded at startup;
2. If only AOF is configured, the AOF file is loaded at startup;
If RDB and AOF are configured at the same time, AOF files are used because AOF has higher priority than RDB.
Furthermore, AOF files have higher data integrity than RDB files because RDBs are maintained according to a periodic policy.
If a failure occurs before the next cycle, data from the previous cycle to the point of failure will be lost.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.