Redis configuration file ES1en. conf configuration details

  • 2020-06-07 05:33:01
  • OfStack

The redis. conf configuration item is described below

redis profile details


# vi redis.conf

daemonize yes # Whether the next stage process is running 

pidfile /var/run/redis/redis-server.pid  #pid File location 

port 6379# Listen on port 

bind 127.0.0.1  # Bind the address, if the external network needs to connect, set 0.0.0.0

timeout 300   # Connection timeout, per second 

loglevel notice # Log levels, respectively: 

# debug  : Suitable for development and testing 

# verbose  : More details 

# notice  : Suitable for production environment 

# warning  : Only record warning or error messages 

logfile /var/log/redis/redis-server.log  # Log file location 

syslog-enabled no  # Whether to output logs to system logs 

databases 16# Set the number of databases. The default database is 0



###############  snapshot  ###############



save 900 1  # in 900s ( 15m ) After that, at least 1 a key When a change occurs, a snapshot 

save 300 10  # in 300s ( 5m ) After that, at least 10 a key When a change occurs, a snapshot 

save 60 10000 # in 60s ( 1m ) After that, at least 1000 a key When a change occurs, a snapshot 

rdbcompression yes  #dump Whether to compress the data 

dir /var/lib/redis  # Database ( dump.rdb ) File storage directory 



###############  A master-slave replication  ###############



slaveof <masterip> <masterport> # Master-slave replication used for native machines redis As a slave To connect to the main redis

masterauth <master-password>  # when master Set password authentication, slave Specify with this option master The authentication code 

slave-serve-stale-data yes   # when slave with master Between the connection disconnects or slave Is working with master When doing data synchronization, if there is slave Request when set to yes When, slave Still responding to the request, at this point there may be a problem if set no When, slave Returns the "SYNC with master in progress" Error message. but INFO and SLAVEOF Except for orders. 



###############  security  ###############



requirepass foobared  # configuration redis Connection authentication password 



###############  limit  ###############



maxclients 128# Set the maximum number of connections, 0 To not limit 

maxmemory <bytes># Memory cleanup strategy, if this value is reached, the following actions are taken: 

# volatile-lru  : The default policy for setting expiration time only key for LRU Algorithm to delete 

# allkeys-lru  : Delete those that are not often used key

# volatile-random  : Randomly delete those that are about to expire key

# allkeys-random  : Random deletion 1 a key

# volatile-ttl  : Delete those that are about to expire key

# noeviction  : Does not expire, write operation returns an error 

maxmemory-policy volatile-lru# If it reaches maxmemory Value, using this policy 

maxmemory-samples 3  # Default random selection 3 a key , weeded out the least frequently used 



###############  Attach mode  ###############



appendonly no  #AOF Persistent, whether to log the update operation, default redis Is asynchronous (snapshot) to write data to the local disk 

appendfilename appendonly.aof # Specifies the update log file name 

# AOF persistence 3 Kind of synchronization strategy: 

# appendfsync always  # It is written every time data changes appendonly.aof

# appendfsync everysec # By default, sync per second 1 Time to appendonly.aof

# appendfsync no    # Out of sync, data is not persisted 

no-appendfsync-on-rewrite no  # when AOF When the log file is about to grow to a specified percentage, redis By calling the BGREWRITEAOF Whether to overwrite automatically AOF Log files. 



###############  Virtual memory  ###############



vm-enabled no   # Whether to enable the virtual memory mechanism, the virtual memory machine to store the data paging, rarely accessed pages into swap On, the memory usage is much, had better close virtual memory 

vm-swap-file /var/lib/redis/redis.swap  # Virtual memory file location 

vm-max-memory 0  #redis Maximum memory limit used, protection redis Excessive use of physical memory does not affect performance 

vm-page-size 32  # The size of each page is 32 byte 

vm-pages 134217728 # Set up the swap Number of pages in the file 

vm-max-threads 4  # access swap Number of threads in the file 



###############  Advanced configuration  ###############



hash-max-zipmap-entries 512  # When the total number of elements (entries) in the hash table does not exceed the set number, linear compact format storage is used to save space 

hash-max-zipmap-value 64   # Each of these in the hash table value Linear compact format storage is used to save space when the length is not more than a few bytes 

list-max-ziplist-entries 512 #list The number of data types below the nodes will be in a depointers compact storage format 

list-max-ziplist-value 64  #list Data type node values smaller than the number of bytes are in a compact storage format 

set-max-intset-entries 512  #set Data type Internal data is stored in a compact format if it is all numeric and how many nodes it contains 

activerehashing yes    # Whether to activate the reset hash 

Conclusion:

1. redis provides several persistence mechanisms:

a). RDB persistence

How it works: Snapshots (dump) from redis to dump.rdb files are taken at intervals

Pros: Easy backup and restore. RDB is more efficient than AOF in starting persistence through subprocesses

Cons: Server failure can lose data for several minutes

b). AOF persistence

How it works: Record all update operations in the form of a log to the AOF log file, which is read when the redis service restarts to rebuild the database to ensure data integrity after startup.

Advantages: AOF provides two synchronization mechanisms, one is fsync always which synchronizes to the log file every time there is a data change and the other is fsync everysec which synchronizes to the log file once per second for maximum data integrity.

Cons: Log files are much larger than the RDB snapshot file

AOF log rewrite feature:

When the AOF log file is too large, redis automatically overwrites the AOF log. append mode keeps writing updates to the old log file and creates a new log file to append subsequent records.

c). Use both AOF and RDB

For scenarios with high data security, use both AOF and RDB, which can degrade performance.

d). No persistence

Disable redis service persistence.

2. After the error of AOF log file, repair method:

The redis-ES77en-ES78en --fix appendonly. aof #--fix parameter is to repair the log file without checking the log

3. Switch from RDB to AOF persistence without restarting redis:


redis-cli> CONFIG SET appendonly yes   # To enable the AOF
redis-cli> CONFIG SET save ""     # Shut down RDB

The redis configuration file details the redis base configuration items that are commonly used, and redis1 is used to understand them


Related articles: