Redis Learning Note 4-redis Configuration specific explanation

Source: Internet
Author: User
Tags allkeys password protection

When you start the Redis-server service directly in Redis, the default configuration file is used. The use of Redis-server xxx.conf enables the Redis service to be executed in accordance with the specified configuration file.

Redis's configuration file is/etc/redis/6379.conf according to the way Redis is followed in this Redis learning note. The following is a Chinese explanation of the Redis2.8.9 configuration file.

#daemonize No by default, Redis is not running in the background. Suppose you need to run in the background and change the value of the item to Yesdaemonize yes# when Redis is running in the background. Redis defaults to placing the PID file on the/var/run/redis.pid. You can configure to a different address.

# when running multiple Redis services, you need to specify a different PID file and portpidfile/var/run/redis_6379.pid# specify the port for Redis to run, which by default is 6379port 6379# in a highly concurrent environment. To avoid slow client connection problems, you need to set up a quick background log tcp-backlog 511# specifies that Redis only receives requests from that IP address, assuming that it is not set up, then all requests will be processed # bind 192.168.1.100 10.0.0.1# Bind 127.0.0.1# The time-out period, in seconds, when the client connection is set. When the client has not issued any instructions during this time, then closing the connection # 0 is to turn off this setting timeout 0# TCP keepalive# on Linux, specifying the value (in seconds) for the time to send the ACKs. Note that it takes twice the time to close the connection. The default feels 0.

Tcp-keepalive 0# Specify logging level, production environment recommended notice# Redis total support Four levels: Debug, verbose, notice, warning, default verbose# debug record very much Information. for development and test # Varbose practical information, unlike debug will record so many # notice common verbose, often used in production environment # warning only very important or serious information will be recorded to the log loglevel notice# Config log file address # Default value is stdout, standard output. If the background mode is output to/dev/null. logfile/var/log/redis/redis.log# number of available databases # The default value is 16, and the default database is 0. The database range is databases 16################################ snapshots between 0-(database-1) ################################## save data to disk, The format for example is as follows: # save <seconds> <changes># indicate how long it takes. How many update operations are available. Synchronize the data to the data file RDB. # is equivalent to a conditional trigger fetch snapshot. This can be used in multiple condition matching # For example, the default configuration file settings, set three conditions # Save 900 1 900 seconds of at least 1 keys are changed # Save 300 10 300 seconds at least 300 keys are changed # Save 60 10000 60 seconds at least 10,000 keys are changed # Save 10# save 60 10000# Background Store error stop write. Stop-writes-on-bgsave-error yes# when storing to a local database (persisted to an RDB file) whether the data is compressed, the default is that yesrdbcompression yes# Rdb file is a direct idol Chcksumrdbchecksum yes# Local Persistent database file name. The default value is Dump.rdbdbfilename dump.rdb# the path to the file placement of the working folder # Database mirroring backup. #The path here is configured separately from the file name because Redis is in the backup. The state of the current database is written to a temporary file, and the backup is complete. # Replace the temporary file with the file specified above, and the temporary file and the backup file configured above will be placed in the specified path. # AOF files will also be stored in this folder below # Note that here you must develop a folder instead of a file dir/var/lib/redis-server/################################# copy ############# ##################### master-slave replication. Set the database as the slave database for the other database. # Set the IP address and port of the master service when the Slav service is set, at Redis boot time. It will proactively synchronize data from master # slaveof <masterip><masterport># when the master service has password protection (password made with Requirepass # Slave Service Connection Master password# Masterauth <master-password># When the connection from the library to the host is lost or the replication is in progress, there are two ways to run from the hangar: # 1) Assuming slave-serve-st Ale-data is set to Yes (the default setting), and the library continues to respond to client requests # 2) Assuming that slave-serve-stale-data refers to No. Out of the INFO and SLAVOF commands no matter what the request will return a # error "SYNC with Master in progress" Slave-serve-stale-data yes# Configure slave instance to accept write.

Write slave is useful for storing ephemeral data (which can be removed very easily after synchronizing with master data), but without configuration, client write may send a problem.

# after Redis2.6, the default slave is Read-onlyslaveread-only yes# from the library will send PINGs to the main library at a time interval. The ability to set this time interval through repl-ping-slave-period, default is 10 seconds # Repl-ping-slave-period 10# repl-timeout set the main library bulk transfer data time or ping reply interval, the default value is 60 Seconds # Make sure that Repl-timeout is greater than repl-ping-slave-period# repl-timeout 60# after the slave socket SYNC is disabled tcp_nodelay# assume select "Yes", Redis will send data to slave using a smaller number of TCP packets and less bandwidth. However, this can result in a delay in sending data to the slave side, assuming that the default configuration of the Linux kernel will reach 40 milliseconds. # Suppose you choose "No". The delay in sending the data to the slave side is reduced. But a lot of other bandwidth will be used for replication. Repl-disable-tcp-nodelay no# Set the background log size for replication.

# The larger the background log that is copied, the longer it takes for slave to disconnect and later possibly run partial replication. # The background log is allocated only once when there is at least one slave connection.

# repl-backlog-size 1mb# after master is no longer connected to slave. The background log will be released. The following configuration defines the time (in seconds) that is required to be released after the last slave disconnect. # 0 means never release the background log # Repl-backlog-ttl 3600# assuming that master no longer works, then in more than one slave, select a slave with the lowest priority value to master, and a priority value of 0 to not be promoted to mast Er. Slave-priority 100# assumes less than N slave connections and has a delay of <=m seconds. The master can be configured to stop accepting write operations. # For example, a minimum of 3 slave connections is required. and delay the configuration of <=10 seconds: # min-slaves-to-write 3# Min-slaves-max-lag 10# set 0 to Disabled # default Min-slaves-to-write is 0 (disabled), min-slaves- Max-lag for 10################################## Safety #################################### Set up a client connection for any password that you need to use before any other designation.

# Warning: Because Redis is quite fast, an external user can make a 150K password attempt in a second under a better server, which means you need to specify very powerful password to prevent brute force. Requirepass foobared# command renamed. # You can rename a relatively critical command in a shared environment. For example, the name of CONFIG is a character that is not easy to push. # example: # Rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52# false Imagine delete a command, rename it to a null character "" Can, for example, the following: # Rename-co Mmand CONFIG "" ################################### constrained ################################### #设置同一时间最大client连接数, default unrestricted, #Redis the number of client connections that can be opened at the same time is the maximum number of file descriptive descriptors that the Redis process can open. #假设设置 maxclients 0, indicating no restrictions. #当client连接数到达限制时, Redis closes the new connection and returns the max number of clients reached error message # MaxClients 10000# to the client to specify the Redis maximum memory limit. Redis will load data into memory at startup, and Redis will attempt to purge expired key# according to the purge policy if Redis does not provide enough space after policy cleanup. Or if the policy is set to "noeviction", commands that use a lot of other space will get an error, such as set, Lpush, and so on. But still able to read operation # Note: Redis's new VM mechanism will store the Key in memory. Value is stored in the Swap area # This option is useful for LRU policies. # MaxMemory's settings are better suited for using Redis as a cache of similar memcached. Instead of being a true DB.

# when using Redis as a real database, memory usage would be a very big overhead # maxmemory <bytes># What data does Redis choose to delete when the memory reaches its maximum value? There are five ways to choose # Volatile-lru, using the LRU algorithm to remove key (LRU: Recently used Least recentlyused) # Allkeys-lru with the LRU algorithm to remove whatever key# volatile-random, remove a random key# with set expiration time Allkeys->random, remove a randomkey, any key# Volatile-ttl Remove Expiring key (minor TTL) # noeviction, no matter what can, just return a write error # Note: For the above policy. Assuming no proper key can be removed, Redis returns an error when writing # default is: volatile-lru# maxmemory-policy VOLATILE-LRU # LRU and minimal TTL algorithms are not accurate Method. But the relatively accurate algorithm (in order to save memory), arbitrary you can choose sample size to detect.

# Redis Default Gray Select 3 samples to detect. You can set it through Maxmemory-samples # maxmemory-samples 3############################## aof################################ By default, Redis backs up database mirroring to disk asynchronously in the background, but the backup is time-consuming. and backups are not very frequent. Assuming a situation such as power cuts, unplug, etc., it will result in a larger range of data loss. # so Redis provides a second, more efficient way to database backup and disaster recovery.

# After you turn on append only mode, Redis appends every write request you receive to the Appendonly.aof file, and when Redis starts again, it resumes its previous state from the file.

# But this will cause the appendonly.aof file to be too large. So Redis also supported the BGREWRITEAOF directive, and appendonly.aof again. # You can turn on the same time asynchronous dumps and aofappendonly no# AOF file name (default: "Appendonly.aof") # Appendfilename appendonly.aof# R Edis supports three different strategies for synchronizing AOF files: # No: No synchronization. System to operate. faster.# Always:always indicates that each write operation is synchronized. Slow, safest.# everysec: Indicates that the write operation is cumulative and synchronized once per second. compromise.# default is "Everysec". It's best to compromise on speed and safety.

# Let's say you want Redis to run more efficiently. You can also set the "no" to let the operating system decide when to run # or instead to make the data more secure you can also set it to "always" # assuming you're unsure, use "everysec". # Appendfsync Alwaysappendfsync everysec# Appendfsync no# AOF Policy is set to always or everysec. The background processing process (background save or AOF log rewrite) will run a large number of I/O operations # Blocks long Fsync () requests in some Linux configurations.

Note that there is no fix now, even if Fsync is working on another thread # to mitigate this problem, you can set the following number of parameters No-appendfsync-on-rewriteno-appendfsync-on-rewrite no# AOF Self-Rewriting # when the AOF file grows to a certain size, Redis can call bgrewriteaof to rewrite the log file # It works: Redis remembers the size of the file after the last log (assuming it hasn't been rewritten since the boot, the day size is on Machine) # The base size is comparable to today's size.

Assuming that today's size is larger than the base size, the rewrite feature will start # at the same time need to specify a minimum size for AOF overrides, this is used to prevent even though the file is very small but the growth is very large also to rewrite the AOF file condition # Set percentage to 0 to turn off this feature Auto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mb################################ LUASCRIPTING ####### ####################### a Lua script has a maximum run time of 5000 milliseconds (5 seconds), assuming a 0 or negative number represents an infinite run time. Lua-time-limit 5000############################### #LOW log################################# Redis Slow LOG Record commands that exceed a specific run time. Runtime does not include I/O calculations such as connecting the client, returning results, etc., is only the command run time # can be set by two parameters slow log: One is to tell Redis how much time to run more than the number of minutes Slowlog-log-slower-than (subtle), # Another one is the length of the slow log.

When a new command is logged, the oldest command will be removed from the queue # The time is in subtle units, so 1000000 represents one second. Note Specifying a negative number turns off slow logging, and setting to 0 forces each command to log Slowlog-log-slower-than 10000# has no limit on the length of the log. Just be aware that it consumes memory # ability to reclaim memory consumed by slow logs by Slowlog RESET # recommend using the default value of 128, when the slow log exceeds 128, the first record to enter the queue will be kicked out Slowlog-max-len 128############### ################# Event Notification ############################## When an event occurs, Redis is able to notify the Pub/sub client. # You can select the type of event that Redis wants to notify in the following table. The event type is identified by a single character: the # K Keyspace event, and the # E KeyEvent event is advertised as a [email protected]<db>_ prefix]. # G Common event (unspecified type) as [email protected]<db>_ prefix], like DEL, EXPIRE, RENAME, ... # $ String Command # s Set Command # H Hash Command # Z ordered set command # x expiration event (generated each time key expires) # E Clear event (generated when key is cleared in memory) # A G$lshzxe's nickname, so "AKE" means all events # no Tify-keyspace-events with a string that consists of 0 to multiple characters. An empty string means that the notification is disabled.

# Example: Enable list and common events: # notify-keyspace-events elg# The default notification is disabled because the user usually does not need to change the feature. And this feature can have a performance loss. Note assume that you do not specify at least one of the K or E. No matter what event is sent. Notify-keyspace-events "" ############################## Advanced Configuration ################################ when hash Contains more than the specified number of elements and the largest element does not exceed the critical, the # hash will be stored in a special encoding method (greatly reducing memory usage). Here you can set the two critical values # Redis Hash corresponding value inside is actually a HashMap. There are actually 2 different implementations of this. # The members of this Hash are relatively young Redis saves memory by using a similar one-dimensional array for compact storage. Instead of using a real HASHMAP structure, the corresponding Valueredisobject encoding is zipmap,# when the number of members increases, it will take its own initiative to turn into a real HashMap, at this time encoding for HT. Hash-max-zipmap-entries 512hash-max-zipmap-value 64 # As with Hash, multiple small lists are encoded in a specific way to save space.

# The list data type node value size is less than how many bytes will be used in a compact storage format. List-max-ziplist-entries 512list-max-ziplist-value 64# Set data type internal data assumptions are all numeric and include how many nodes below are stored in a compact format. Set-max-intset-entries 512# and Hashe and list, the ordered set is stored in the specified length in the specified encoding to save space # Zsort data type node value size less than how many bytes will be used in compact storage format.

Zset-max-ziplist-entries 128zset-max-ziplist-value 64# Redis will use 1 milliseconds of CPU time every 100 milliseconds to hash the Redis hash table again to reduce memory Use # When you have very strict real-time requirements in your usage scenario, you cannot accept Redis's occasional 2 millisecond delay for requests, and configure this as No. # Assuming that there is no such strict real-time requirements, can be set to Yes, so as to free up memory activerehashing yes# client's output buffer limit, for some reason the client reads data from the server is not fast enough, # Can be used to force disconnection (a common reason is that the speed at which an advertisement/subscription client consumes messages cannot catch up with the production of them). # can be set up in three different client ways: # normal client# slave, slave and MONITOR client# pubsub subscribe to at least one pubsub channel or pattern of client# each client-output-buffer-limit syntax: # client-output-buffer-limit <class>

# Increasing this value will use a lot of other CPUs when Redis spare, but at the same time when multiple keys expire at the same time will make Redis more responsive, and timeouts can be handled more precisely. # range is between 1 and 500, but a value of more than 100 is usually not a good idea. # Most users should use this preset value of 10. There is a need to increase the maximum to 100 only in the case of very low latency. Hz 10 # When a child node overrides the AOF file, assume that the following options are enabled, the file is synchronized for each 32M data generated.

Aof-rewrite-incremental-fsync Yes



Redis Learning Note 4-redis Configuration specific explanation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.