Common configuration instructions
redis.conf The configuration items are described as follows :
1. Redis The default is not to run as a daemon , This configuration item can be modified , Use yes Enable daemons
daemonize no
2. When Redis Run as a daemon ,Redis By default the pid write in /var/run/redis.pid file , Can pass pidfile Appoint
pidfile /var/run/redis.pid
3. Appoint Redis Listening port , The default port is 6379, In one of his blog posts, the author explains why 6379 As default port , because 6379 On the phone buttons MERZ The corresponding number , and MERZ From the Italian singer Alessia Merz Name
port 6379
4. The bound host address
bind 127.0.0.1
5. Close the connection after how long the client is idle , If specified as 0, Indicates that the feature is turned off
timeout 300
6. Specifies the logging level ,Redis There are four levels supported :debug、verbose、notice、warning, The default is verbose
loglevel verbose
7. Logging mode , The default is standard output , If configured Redis Run for daemon mode , This is configured for logging as standard output , The log will be sent to /dev/null
logfile stdout
8. Set the number of databases , The default database is 0, have access to SELECT <dbid> The command specifies the database on the connection id
databases 16
9. Specify how long , How many update operations are there , Synchronize the data to the data file , Multiple conditions can be used
save <seconds> <changes>
Redis Three conditions are provided in the default configuration file :
save 900 1
save 300 10
save 60 10000
respectively 900 second (15 minute ) There are 1 A change ,300 second (5 minute ) There are 10 Changes and 60 In seconds 10000 A change .
10. Specifies whether data is compressed when stored to a local database , The default is yes,Redis use LZF Compress , If in order to save money CPU Time , This option can be turned off , But it can make the database files huge
rdbcompression yes
11. Specifies the local database file name , The default value is dump.rdb
dbfilename dump.rdb
12. Specifies the local database hosting directory
dir ./
13. Set when the native is slav The service , Set up master Service IP Address and port , stay Redis Startup time , It will automatically follow master Data synchronization
slaveof <masterip> <masterport>
14. When master When the service is password protected ,slav Service connection master Password
masterauth <master-password>
15. Set up Redis Connect the password , If the connection password is configured , The client is connecting Redis Need to go through AUTH <password> Command provide password , Off by default
requirepass foobared
16. Sets the maximum number of client connections at one time , Default limit ,Redis The number of client connections that can be opened simultaneously is Redis The maximum number of file descriptors that a process can open , If you set maxclients 0, No restrictions . When the number of client connections reaches the limit ,Redis The new connection is closed and returned to the client max number of clients reached error message
maxclients 128
17. Appoint Redis Maximum memory limit ,Redis Data is loaded into memory at startup , After reaching the maximum memory ,Redis It will first try to clear those that are due or are about to expire Key, When this method is handled after , Still reaches the maximum memory setting , Will no longer be able to write , But you can still do a read .Redis new vm Mechanism , Will be able to Key Storage memory ,Value Will be stored in a swap District
maxmemory <bytes>
18. Specifies whether to log after each update operation ,Redis By default, data is written asynchronously to disk , If you don’t turn it on , Data may be lost for a period of time during a power outage . because redis The itself synchronization data file is pressed above save Condition to synchronize , So some data will only exist in memory for a while . The default is no
appendonly no
19. Specifies the file name of the update log , The default is appendonly.aof
appendfilename appendonly.aof
20. Specifies an update log condition , share 3 Optional values :
no: Means that the operating system synchronizes the data cache to disk ( fast )
always: Represents a manual call after each update operation fsync() Write data to disk ( slow , Security )
everysec: That means once per second ( compromise , The default value is )
appendfsync everysec
21. Specifies whether the virtual memory mechanism is enabled , The default value is no, A brief introduction ,VM The mechanism stores data in pages , from Redis Cold data for less visited pages swap To disk , Pages with multiple accesses are automatically swapped out from disk to memory ( I will analyze it carefully in the following articles Redis Of VM Mechanism )
vm-enabled no
22. Virtual memory file path , The default value is /tmp/redis.swap, Not more than one Redis The instance Shared
vm-swap-file /tmp/redis.swap
23. I’m going to make everything greater than vm-max-memory Is stored in virtual memory , No matter what vm-max-memory Set up small , All index data is stored in memory (Redis Index data of Namely keys), in other words , When vm-max-memory Set to 0 When , It’s all value Both exist on disk . The default value is 0
vm-max-memory 0
24. Redis swap The file is divided into many parts page, An object can be stored in more than one page above , But a page Can’t be Shared by multiple objects ,vm-page-size It’s based on storage The data size is set , The authors suggest storing many small objects ,page The size is best set to 32 perhaps 64bytes; If you store large objects , You can use a larger one page, If you don’t determine , Just use the default values
vm-page-size 32
25. Set up swap In the document page Number , Because the page table ( One that indicates that a page is free or in use bitmap) It’s in memory ,, Each on disk 8 individual pages Will consume 1byte Of memory .
vm-pages 134217728
26. Set access swap Number of threads in the file , It is best not to exceed the audit of the machine , If set to 0, So all right swap The operation of the file is serial , May cause a relatively long delay . The default value is 4
vm-max-threads 4
27. Set when to reply to the client , Whether to combine smaller packages into a single package , On by default
glueoutputbuf yes
28. Specifies when a certain number or maximum of elements exceeds a certain threshold , A special hash algorithm is used
hash-max-zipmap-entries 64
hash-max-zipmap-value 512
29. Specifies whether to activate the reset hash , On by default
activerehashing yes
30. Specifies that additional configuration files are included , More than one can be on the same host Redis The same configuration file is used between instances , At the same time, each instance has its own specific configuration file
include /path/to/local.conf