Look at Redis from the perspective of operations
Redis operation and maintenance instructions
Dbsize # Rewrite aOF # rewriteaof # rewrite RDP # rewrite RDP # rewrite RDP # Lastsave# bgsave # to check the last saved time background export RDP (carefully) flushdb # # to empty data to empty the current database select id switch database flushall # # to empty all database info service statistical information Redis. conf config get port config set port 6379Copy the code
Flushall or flushDB is accidentally used for aOF recovery and migration between RDB servers
Nosave: this command will not write to aOF. The default is save shutdown. Nosave: this command will not write to AOF. Aof # delete the flushall or flushDB directive from the flushDB database # use aOF to restore data in case both aOF and RDB exist./redis-server # restart serverCopy the code
Data migration of redis databases (moving data from one server to another)
- Redis data migration is implemented by copying the RDB file, enabling RDB in redis.conf, and specifying the RDB file
- Copying RDB files is problematic when the Redis server is running, so shut down the original server before copying RDB files
- Use the save command to manually write data to the RBD to avoid that some new data is not persisted to the RDB
Redis exception handling (such as downtime)
Scenario: When the master is down
- Config get/set gets/sets the runtime redis configuration
- Info Replication Displays information about the current Redis cluster
How does Slave1 become master when master goes down
# config set slave-only no # Disable the slave status of slave1 # config set slave-only no # Other slaves are redirected to the new Master Slaveof IP portCopy the code
The sentinel monitoring configuration automatically completes the sentinel.conf configuration
Start Redis sentinel mode: /redis-server sentinel.conf --sentinel # Reelect master sentinel monitor def_master when the number of master failures reaches 2 127.0.0.1 6379 2 #master sentinel auth-pass def_master 012_345^678-90 ## The interval at which master is considered "failed" by the current sentinel instance If there is no response or error code within the specified time, the sentinel will consider the master invalid (SDOWN, Milliseconds def_master 30000 ## default value for 30 seconds sentinel down-after-milliseconds def_master 30000 ## No indicates that the current Sentinel is an "observer" (only votes). Does not participate in failover), # yes sentinel can-failover def_master # Yes sentinel can-failover def_master sentinel parallel-syncs def_master 1Copy the code
Possible problems: Overriding the election of a master randomly elects one of the surviving clusters, which is not conducive to production. Redis. conf slave-priority 100 # Set the priority of a node to a higher priority