Three------redis.conf configuration definitions for Redis installation and use

Source: Internet
Author: User
Tags allkeys redis cluster

The Redis configuration file is divided into chunks of space, namely:

1. Universal (General)

2. Snapshots (snapshotting)

3. Replication (Replication)

4. Safety (Security)

5. Restrictions (Limits)

6. Append mode (append only)

7.LUA script (Lua scripting)

8.Redis cluster (Redis cluster)

9. Slow logs (slow log)

10. Delay Monitoring (Latency monitor)

11. Notification of events (event notification)

12 configuration (Advanced config)


Note: Includes configuration: When the machine has not only 1 Redis instances, you can implement a "personalization" configuration for each Redis instance, at which point the common configuration of these instances can be written to redis.conf, and the personalized configuration is written to the file specified by the Include configuration path.


1. General:

############################  general  ################################ #daemonize  no                      # #是否以后台daemon方式运行 (default is NO) pidfile /var/run/redis/redis.pid     ## PID File Location port 6379                          # #监听端口tcp-backlog 511             # #客户端连接队列值,  in a high-concurrency environment, to avoid slow client connection problems, you need to set up a high-speed background log bind  127.0.0.1                 # #指定redis所响应的连接请求 (Default in response to connection requests for all NICs on this computer) timeout 0                                  # #请Request Timeout (0 means never close) tcp-keepalive 0                    # #TCP存活检测 (in seconds, 0 means no detection) loglevel notice            # #log信息级别 (four levels, i.e. debug, verbose, notice, warning) logfile /var/log/ redis/redis.log       # #log文件位置, if set to [logfile  ""] empty string, Redis will output the log to standard output , is written to/dev/null in databases 16     # #开启数据库数量 (the default database is a database numbered 0, you can use Select <dbid > to select the appropriate database)


2. Snapshot (snapshotting)----primarily related to Redis's RDB persistence-dependent configuration

Save *: How often the snapshot is saved, the first * indicates how long, and the second * indicates how many times the write operation was performed. When a certain number of writes are performed in a certain amount of time, snapshots are automatically saved and multiple conditions can be set. If you want to disable the RDB persistence policy, do not set any save instructions, or set [save]

##########################  snapshotting  ############################ #save  900  1           # #每15分钟且至少有1个key改变, it triggers a persistent save 300  10          # #每5分钟且至少有10个key改变, it triggers a persistent save 60  10000        # #每60秒至少有10000个key改变, Triggers a persistent stop-writes-on-bgsave-error yes        ## When Redis persists data to disk in the event of a failure, the default Redis will stop accepting all write requests rdbcompression yes               # #是否使用压缩rdbchecksum  yes                 # #是否使用CRC64算法来进行数据校验dbfilename  dump.rdb            # #设置数据快照文件名 (just file name, excluding directory) dir /var/lib/redis/            # #设置数据快照的Save Directory (this is the directory) 


3. Replication (Replication)

############################### REPLICATION ##########################

The Slaveof configuration item controls one Redis as the slave server for another redis, locating the location of the master Redis by specifying the IP and port

# slaveof <masterip> <masterport>


If the master Redis setting verifies the password (using the Requirepass setting), you need to set the checksum password using Masterauth in the configuration from Redis, or the master Redis will deny access requests from Redis

# Masterauth <master-password>


Redis has two processing options for external access requests when it loses its connection to the primary Redis, or when master-slave synchronization is in progress:

Option 1: Set to Yes (default), the Redis continues to respond to client read-write requests

Option 2: Set to No, the request from Redis returns "SYNC with Master in Progress" (Exception: When the client sends an info request and a slaveof request, it is processed from Redis)

Slave-serve-stale-data Yes slave-read-only Yes # #设置从redis只读


Replication synchronization Policy: disk or socket

The new data should be fully synchronized when it comes back online from Redis or master Redis. A new Rdb file needs to be dump out and then propagated from the master Redis to Redis. There are two types of situations:

1. Hard disk based (disk-backed): Master Redis creates a new process dump RDB, which is then passed from the parent process (that is, the main process) increment to the Redis

2. Socket-based (diskless): Master Redis creates a new process direct dump RDB to the socket from Redis, not through the main process, without the hard drive

If the Rdb file is created after it has been created, it can serve more from Redis at the same time, such as socket-based, new after joining from Redis, such as exceeding Repl-diskless-sync-delay setting, when using diskless, After the master Redis waits for the number of seconds set by the Repl-diskless-sync-delay, if there is no new join from Redis, it will be transmitted directly and then queued for later. (Default with disk-based)

Repl-diskless-sync Norepl-diskless-sync-delay 5 # #每五秒传输一次 (need to turn on diskless) # Repl-ping-slave-period 10 # #设置从redis向主redis发出PING包的周期 (default 10 seconds)


During master-slave synchronization, a timeout may occur in these cases:

1. In terms of Redis, when there is a large IO transmission.

2. From a redis point of view, when data transfer or ping, the master Redis timeout

3. From the point of view of Master Redis, when replying to ping from Redis, timeout from Redis

The user can set the time-out period, but make sure that this time limit is greater than the Repl-ping-slave-period value, or each time the master Redis is considered to be out of Redis.

# Repl-timeout 60


Whether to disable Tcp_nodelay when setting master-slave synchronization. If Tcp_nodelay is turned on, the primary Redis will use fewer TCP packets and less bandwidth to transfer data from Redis, but may increase synchronization latency (40ms). If Tcp_nodelay is turned off, the delay time of data synchronization will decrease, but it will consume more bandwidth.

Repl-disable-tcp-nodelay No


Sets the synchronization queue length. The queue Length (backlog) is a buffer in the primary redis that is used by the master Redis to cache data that should be sent from Redis during disconnection from Redis. This way, when reconnecting from Redis, you do not have to re-synchronize the data completely, just synchronize this part of the incremental data to

# repl-backlog-size 1MB


Set the length of time that the primary redis cleanup buffer queue waits (set to 0 to never clean up, 1 hours by default)

# Repl-backlog-ttl 3600slave-priority # #设置从redis优先级, the smaller the number, the higher the priority (default 100)


If the master Redis discovers that more than M connections from Redis are delayed more than n seconds, then the master Redis stops accepting foreign write requests

# Min-slaves-to-write 3# Min-slaves-max-lag 10

If there is greater than or equal to 3 connections from Redis with a delay greater than 10 seconds, then the master Redis will no longer accept external write requests. If one of the two configurations is set to 0, this feature will be turned off


4. Safety (Security)

############################# SECURITY ################################## #设置redis客户端在向redis-server before sending a request, password authentication is performed first. # requirepass foobared # #设置密码为 "foobared" # Rename-command CONFIG b840fc02d524045429941 ... # #对redis指令进行更名 # ren Ame-command CONFIG "" # #禁用CONFIG命令


5. Restrictions (Limits)

############################### LIMITS ################################# maxclients 10000 # #设置redis可以同时与多少个客户端进行连接 ( Default is 10,000 clients) # MaxMemory <bytes>

Sets the amount of memory that Redis can use. Once the memory usage limit is reached, Redis will attempt to remove the internal data, and the removal rule can be specified by Maxmemory-policy. If Redis cannot remove data from memory based on removal rules, or if we set "do not allow removal", Redis returns an error message for those instructions that require memory

If your redis is a master Redis, you will need to set aside some memory space in the system for the synchronization queue cache when setting the memory usage limit, which is not to be considered unless you set the "Do not remove" condition.

For memory-removal rules, Redis provides up to 6 removal rules. They are:

1. VOLATILE-LRU: Use the LRU algorithm to remove keys from an outdated collection

2. ALLKEYS-LRU: Using the LRU algorithm to remove key

3. Volatile-random: Remove the random key from the expired collection

4. Allkeys-random: Remove the Random key

5. Volatile-ttl: Remove the key with the lowest TTL value, which is the key that has only recently expired.

6. Noeviction: Do not remove. For write operations, only error messages are returned. (Default rule)

Regardless of which removal rule is used, REDIS returns an error message for a write request if no appropriate key can be removed.

# maxmemory-policy Noeviction # #不进行移除 # maxmemory-samples 5 # #设置LRU算法的样本数


6. Append mode (append only)

########################## APPEND only MODE ########################## #appendonly on # #打开AOF功能app Endfilename "Appendonly.aof" # #设置AOF文件的名称


AOF persistence Policy, Fsync () call to tell the operating system to immediately write cached instructions to disk, Redis supports three different modes:

1. Always: Each write request is forced to call Fsync, which in this mode, Redis is relatively slow, but the data is the safest

2. Everysec: Call once per second Fsync

3. On: Do not call Fsync wait for the system to synchronize itself [Fsync means to log the write instruction in the cache to disk]

Appendfsync Everysec # #每秒调用一次fsync

When Bgsave or bgwriteaof is running, Fsync () calls in the main process are blocked.  This means that when another process is refactoring the AoF file, the Redis persistence function is invalidated, as if "Appendsync none" was set. If Redis sometimes delays the problem, set the option to Yes. Otherwise, keep No because this is the safest option to ensure data integrity.

No-appendfsync-on-rewrite No


Allows Redis to automatically rewrite aof. When aof grows to a certain size, redis implicitly calls bgrewriteaof to rewrite the log file to reduce the file volume. Redis works this way: Redis records the size of the aof when it was last rewritten. If Redis has not been rewritten since startup, the size of the AoF file will be used as the base value at startup. The benchmark value is compared to the current aof size. If the current aof size exceeds the set growth ratio, the override is triggered. It is also necessary to set a minimum size in order to prevent the override from being triggered at aof hours. If you set Auto-aof-rewrite-percentage to 0, this override function is turned off.

Auto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated Yes # #当aof文件被损坏时, Redis will return an error and exit


7. Lua script (LUA scripting)

############################ LUA SCRIPTING ######################## #lua-time-limit # #设置lua脚本最大运行时间 (default milliseconds, Set to 0 or negative, no error or no time limit)


8. Redis cluster (Redis cluster)

############################ REDIS CLUSTER ########################### cluster-enabled Yes # #开启redis集群 # C Luster-config-file nodes-6379.conf # #集群配置文件 (Start auto build) # Cluster-node-timeout 15000 # #节点互联超时的阀值 # Cluster-slave-vali Dity-factor # #slave节点检测因素, start failover The timeout period is determined by the product of factor and timeout # cluster-migration-barrier 1 # # Set Master to trigger the migration process only if the number of slave is associated # cluster-require-full-coverage Yes # #集群各节点在检测到至少一个hash槽位遗漏的情况下将停止处理查询请求. If the cluster node is down (for example, some hash slots are not allocated) it will cause the entire cluster to be unavailable until all slots are allocated and will automatically revert to the available state.


9. Slow logs (slow log)

############################### SLOW LOG ############################## #redis慢日志是指一个系统进行日志查询超过了指定时长. This length does not include IO operations, such as interacting with the client, sending the response content, and so on, including only the time when the query command was actually executed. For slow logging, you can set two parameters, one is the execution duration, the unit is microseconds, and the other is the length of the slow log. When a new command is written to the log, the oldest one is removed from the command log queue. Slowlog-log-slower-than 10000 # #设置执行时长为10000微秒 (in microseconds, negative numbers disable slow logging, and 0 means force logging of each command) Slowlog-max-len # #设置慢日志最大长度


10. Delay Monitoring (Latency monitor)

############################# LATENCY MONITOR ################### #latency-monitor-threshold 0 # # Use latency to print the time-consuming chart of a Redis instance when running a command, logging only actions greater than or equal to the set value (0 means turn off monitoring)


11. Event notification----Notifies the client of the occurrence of certain events

########################## EVENT NOTIFICATION ###################### #notify-keyspace-events "" # #通知pub/sub client about key null Changes (default off)


12 configuration (Advanced config)

############################# Advanced CONFIG ######################### #有关哈希数据结构的配置项hash-max-ziplist-entries 512hash-max-ziplist-value 64# #有关列表数据结构的配置项list-max-ziplist-entries 512list-max-ziplist-value 64## Configuration items for collection data Structures set-max-intset-entries 512# #有关有序集合数据结构的配置项zset-max-ziplist-entries 128zset-max-ziplist-value 64## Configuration items for Hyperloglog byte limit hll-sparse-max-bytes 3000# #关于是否需要再哈希的配置项activerehashing yes## About the control of client output buffering client-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64MB 60client-output-buffer-limit pubsub 32mb 8mb 60# #有关频率的配置项hz 10# #有关重写aof的配置项aof-rewrite-incremental-fsync Yes



This article is from the Notepad blog, so be sure to keep this source http://wangzhijian.blog.51cto.com/6427016/1734868

Three------redis.conf configuration definitions for Redis installation and use

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.