redis.conf配置文件詳細講解(三)

7.      安全設置說明html

######## SECURITY[l1] ###################################node

 

# Requireclients to issue AUTH <PASSWORD> before processing any otherlinux

# commands.  This might be useful in environments in whichyou do not trustweb

# others with access to the host runningredis-server.[l2] redis

#算法

# Thisshould stay commented out for backward compatibility and because most數據庫

# people do not need auth (e.g. they runtheir own servers).[l3] express

#promise

# Warning:since Redis is pretty fast an outside user can try up to緩存

# 150k passwords per second against agood box. This means that you should

# use a very strong password otherwise itwill be very easy to break.[l4] 

#

# requirepass foobared

 

# Commandrenaming.[l5] 

#

# Itis possible to change the name of dangerous commands in a shared

# environment. For instance the CONFIGcommand may be renamed into something

# hard to guess so that it will still beavailable for internal-use tools

# but not available for general clients.[l6] 

#

# Example:

#

# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52

#

#It is also possible to completely kill a command by renaming it into

# an empty string:

#

# rename-command CONFIG ""[l7] 

#

#Please note that changing the name of commands that are logged into the

# AOF file or transmitted to slaves maycause problems.[l8] 

8.      限制設置說明

#######LIMITS #[l9] ###################################

 

# Setthe max number of connected clients at the same time. By default

# this limit is set to 10000 clients,however if the Redis server is not

# able to configure the process filelimit to allow for the specified limit

# the max number of allowed clients is setto the current file limit

# minus 32 (as Redis reserves a few filedescriptors for internal uses).[l10] 

#

#Once the limit is reached Redis will close all the new connections sending

# an error 'max number of clientsreached'.[l11] 

#

# maxclients 10000

 

# Don'tuse more memory than the specified amount of bytes.

# When the memory limit is reached Rediswill try to remove keys

# according to the eviction policyselected (see maxmemory-policy).[l12] 

#

# IfRedis can't remove keys according to the policy, or if the policy is

# set to 'noeviction', Redis will startto reply with errors to commands

# that would use more memory, like SET,LPUSH, and so on, and will continue

# to reply to read-only commands likeGET.[l13] 

#

# Thisoption is usually useful when using Redis as an LRU cache, or to set

# a hard memory limit for an instance(using the 'noeviction' policy).[l14] 

#

#WARNING: If you have slaves attached to an instance with maxmemory on,

# the size of the output buffers neededto feed the slaves are subtracted

# from the used memory count, so thatnetwork problems / resyncs will

# not trigger a loop where keys areevicted, and in turn the output

# buffer of slaves is full with DELs ofkeys evicted triggering the deletion

# of more keys, and so forth until thedatabase is completely emptied.[l15] 

#

# Inshort... if you have slaves attached it is suggested that you set a lower

# limit for maxmemory so that there issome free RAM on the system for slave

# output buffers (but this is not neededif the policy is 'noeviction').[l16] 

#

# maxmemory <bytes>

 

# MAXMEMORYPOLICY: how Redis will select what to remove when maxmemory

# is reached. You can select among fivebehaviors:[l17] 

#

#volatile-lru -> remove the key with an expire set using an LRU algorithm

# allkeys-lru -> remove any keyaccording to the LRU algorithm

# volatile-random -> remove a randomkey with an expire set[l18] 

#allkeys-random -> remove a random key, any key

# volatile-ttl -> remove the key withthe nearest expire time (minor TTL)

# noeviction -> don't expire at all,just return an error on write operations[l19] 

#

# Note:with any of the above policies, Redis will return an error on write

#      operations, when there are no suitable keys for eviction.[l20] 

#

#       At the date of writing these commands are:set setnx setex append

#      incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd

#      sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby

#      zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby

#      getset mset msetnx exec sort[l21] 

#

# The default is:

#

# maxmemory-policy noeviction

 

#LRU and minimal TTL algorithms are not precise algorithms but approximated

# algorithms (in order to save memory),so you can tune it for speed or

# accuracy. For default Redis will checkfive keys and pick the one that was

# used less recently, you can change thesample size using the following

# configuration directive.[l22] 

#

# Thedefault of 5 produces good enough results. 10 Approximates very closely

# true LRU but costs a bit more CPU. 3 isvery fast but not very accurate.[l23] 

#

# maxmemory-samples 5

9.      只增方式配置說明

###### APPENDONLY MODE[l24] ###############################

 

#By default Redis asynchronously dumps the dataset on disk. This mode is

# good enough in many applications, butan issue with the Redis process or

# a power outage may result into a fewminutes of writes lost (depending on

# the configured save points).[l25] 

#

#The Append Only File is an alternative persistence mode that provides

# much better durability. For instanceusing the default data fsync policy

# (see later in the config file) Rediscan lose just one second of writes in a

# dramatic event like a server poweroutage, or a single write if something

# wrong with the Redis process itselfhappens, but the operating system is

# still running correctly.[l26] 

#

# AOFand RDB persistence can be enabled at the same time without problems.

# If the AOF is enabled on startup Rediswill load the AOF, that is the file

# with the better durability guarantees.[l27] 

#

# Pleasecheck http://redis.io/topics/persistence for more information[l28] .

 

appendonly no

 

# Thename of the append only file (default: "appendonly.aof")[l29] 

 

appendfilename "appendonly.aof"

 

# Thefsync() call tells the Operating System to actually write data on disk

# instead of waiting for more data in theoutput buffer. Some OS will really flush

# data on disk, some other OS will justtry to do it ASAP.[l30] 

#

# Redissupports three different modes:[l31] 

#

#no: don't fsync, just let the OS flush the data when it wants. Faster.

# always: fsync after every write to theappend only log. Slow, Safest.

# everysec: fsync only one time everysecond. Compromise.[l32] 

#

# Thedefault is "everysec", as that's usually the right compromise between

# speed and data safety. It's up to youto understand if you can relax this to

# "no" that will let theoperating system flush the output buffer when

# it wants, for better performances (butif you can live with the idea of

# some data loss consider the defaultpersistence mode that's snapshotting),

# or on the contrary, use"always" that's very slow but a bit safer than

# everysec.[l33] 

#

#More details please check the following article:

#http://antirez.com/post/redis-persistence-demystified.html[l34] 

#

#If unsure, use "everysec".[l35] 

 

# appendfsync always

appendfsync everysec

# appendfsync no

 

# Whenthe AOF fsync policy is set to always or everysec, and a background

# saving process (a background save orAOF log background rewriting) is

# performing a lot of I/O against thedisk, in some Linux configurations

# Redis may block too long on the fsync()call. Note that there is no fix for

# this currently, as even performingfsync in a different thread will block

# our synchronous write(2) call.[l36] 

#

#In order to mitigate this problem it's possible to use the following option

# that will prevent fsync() from beingcalled in the main process while a

# BGSAVE or BGREWRITEAOF is in progress.[l37] 

#

#This means that while another child is saving, the durability of Redis is

# the same as "appendfsyncnone". In practical terms, this means that it is

# possible to lose up to 30 seconds oflog in the worst scenario (with the

# default Linux settings).[l38] 

#

#If you have latency problems turn this to "yes". Otherwise leave itas

# "no" that is the safest pickfrom the point of view of durability.[l39] 

 

no-appendfsync-on-rewrite no

 

# Automaticrewrite of the append only file.[l40] 

# Redisis able to automatically rewrite the log file implicitly calling

# BGREWRITEAOF when the AOF log sizegrows by the specified percentage.[l41] 

#

# Thisis how it works: Redis remembers the size of the AOF file after the

# latest rewrite (if no rewrite hashappened since the restart, the size of

# the AOF at startup is used).[l42] 

#

#This base size is compared to the current size. If the current size is

# bigger than the specified percentage,the rewrite is triggered. Also

# you need to specify a minimal size forthe AOF file to be rewritten, this

# is useful to avoid rewriting the AOFfile even if the percentage increase

# is reached but it is still prettysmall.[l43] 

#

#Specify a percentage of zero in order to disable the automatic AOF

# rewrite feature.[l44] 

 

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

 

# AnAOF file may be found to be truncated at the end during the Redis

# startup process, when the AOF data getsloaded back into memory.

# This may happen when the system whereRedis is running

# crashes, especially when an ext4filesystem is mounted without the

# data=ordered option (however this can'thappen when Redis itself

# crashes or aborts but the operatingsystem still works correctly).[l45] 

#

# Rediscan either exit with an error when this happens, or load as much

# data as possible (the default now) andstart if the AOF file is found

# to be truncated at the end. Thefollowing option controls this behavior.[l46] 

#

# Ifaof-load-truncated is set to yes, a truncated AOF file is loaded and

# the Redis server starts emitting a logto inform the user of the event.

# Otherwise if the option is set to no,the server aborts with an error

# and refuses to start. When the optionis set to no, the user requires

# to fix the AOF file using the"redis-check-aof" utility before to restart

# the server.[l47] 

#

#Note that if the AOF file will be found to be corrupted in the middle

# the server will still exit with anerror. This option only applies when

# Redis will try to read more data fromthe AOF file but not enough bytes

# will be found.[l48] 

aof-load-truncated yes

10.   LUA腳本設置說明

######LUA SCRIPTING[l49]   ###############################

 

# Maxexecution time of a Lua script in milliseconds.[l50] 

#

#If the maximum execution time is reached Redis will log that a script is

# still in execution after the maximumallowed time and will start to

# reply to queries with an error.[l51] 

#

# Whena long running script exceeds the maximum execution time only the

# SCRIPT KILL and SHUTDOWN NOSAVEcommands are available. The first can be

# used to stop a script that did not yetcalled write commands. The second

# is the only way to shut down the serverin the case a write command was

# already issued by the script but theuser doesn't want to wait for the natural

# termination of the script.[l52] 

#

# Setit to 0 or a negative value for unlimited execution without warnings.[l53] 

lua-time-limit 5000

11.   Redis集羣設置說明

######REDIS CLUSTER[l54]   ###############################

#

# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#WARNING EXPERIMENTAL: Redis Cluster is considered to be stable code, however

# in order to mark it as"mature" we need to wait for a non trivial percentage

# of users to deploy it in production.[l55] 

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#

#Normal Redis instances can't be part of a Redis Cluster; only nodes that are

# started as cluster nodes can. In orderto start a Redis instance as a

# cluster node enable the cluster supportuncommenting the following:[l56] 

#

# cluster-enabled yes

 

# Everycluster node has a cluster configuration file. This file is not

# intended to be edited by hand. It iscreated and updated by Redis nodes.

# Every Redis Cluster node requires adifferent cluster configuration file.

# Make sure that instances running in thesame system do not have

# overlapping cluster configuration filenames.[l57] 

#

# cluster-config-file nodes-6379.conf

 

#Cluster node timeout is the amount of milliseconds a node must be unreachable

# for it to be considered in failurestate.[l58] 

#Most other internal time limits are multiple of the node timeout.[l59] 

#

# cluster-node-timeout 15000

 

# Aslave of a failing master will avoid to start a failover if its data

# looks too old.[l60] 

#

#There is no simple way for a slave to actually have a exact measure of

# its "data age", so thefollowing two checks are performed:[l61] 

#

# 1)If there are multiple slaves able to failover, they exchange messages

#   in order to try to give an advantage to the slave with the best

#   replication offset (more data from the master processed).

#   Slaves will try to get their rank by offset, and apply to the start

#   of the failover a delay proportional to their rank.[l62] 

#

# 2)Every single slave computes the time of the last interaction with

#   its master. This can be the last ping or command received (if the master

#   is still in the "connected" state), or the time that elapsedsince the

#   disconnection with the master (if the replication link is currentlydown).

#   If the last interaction is too old, the slave will not try to failover

#   at all.[l63] 

#

# Thepoint "2" can be tuned by user. Specifically a slave will not perform

# the failover if, since the lastinteraction with the master, the time

# elapsed is greater than:[l64] 

#

#   (node-timeout *slave-validity-factor) + repl-ping-slave-period

#

# Sofor example if node-timeout is 30 seconds, and the slave-validity-factor

# is 10, and assuming a default repl-ping-slave-periodof 10 seconds, the

# slave will not try to failover if itwas not able to talk with the master

# for longer than 310 seconds.[l65] 

#

# Alarge slave-validity-factor may allow slaves with too old data to failover

# a master, while a too small value mayprevent the cluster from being able to

# elect a slave at all.[l66] 

#

#For maximum availability, it is possible to set the slave-validity-factor

# to a value of 0, which means, thatslaves will always try to failover the

# master regardless of the last time theyinteracted with the master.

# (However they'll always try to apply adelay proportional to their

# offset rank).[l67] 

#

# Zerois the only value able to guarantee that when all the partitions heal

# the cluster will always be able tocontinue.[l68] 

#

# cluster-slave-validity-factor 10

 

# Clusterslaves are able to migrate to orphaned masters, that are masters

# that are left without working slaves.This improves the cluster ability

# to resist to failures as otherwise anorphaned master can't be failed over

# in case of failure if it has no workingslaves.[l69] 

#

# Slavesmigrate to orphaned masters only if there are still at least a

# given number of other working slavesfor their old master. This number

# is the "migration barrier". Amigration barrier of 1 means that a slave

# will migrate only if there is at least1 other working slave for its master

# and so forth. It usually reflects thenumber of slaves you want for every

# master in your cluster.[l70] 

#

# Defaultis 1 (slaves migrate only if their masters remain with at least

# one slave). To disable migration justset it to a very large value.

# A value of 0 can be set but is usefulonly for debugging and dangerous

# in production.[l71] 

#

# cluster-migration-barrier 1

 

#By default Redis Cluster nodes stop accepting queries if they detect there

# is at least an hash slot uncovered (noavailable node is serving it).

# This way if the cluster is partiallydown (for example a range of hash slots

# are no longer covered) all the clusterbecomes, eventually, unavailable.

# It automatically returns available assoon as all the slots are covered again.[l72] 

#

#However sometimes you want the subset of the cluster which is working,

# to continue to accept queries for thepart of the key space that is still

# covered. In order to do so, just setthe cluster-require-full-coverage

# option to no.[l73] 

#

# cluster-require-full-coverage yes

 

#In order to setup your cluster make sure to read the documentation

# available at http://redis.io web site.[l74] 

12.   slowlog設置說明

######### SLOWLOG [l75] ###################################

 

# TheRedis Slow Log is a system to log queries that exceeded a specified

# execution time. The execution time doesnot include the I/O operations

# like talking with the client, sendingthe reply and so forth,

# but just the time needed to actuallyexecute the command (this is the only

# stage of command execution where thethread is blocked and can not serve

# other requests in the meantime).[l76] 

#

# Youcan configure the slow log with two parameters: one tells Redis

# what is the execution time, inmicroseconds, to exceed in order for the

# command to get logged, and the otherparameter is the length of the

# slow log. When a new command is loggedthe oldest one is removed from the

# queue of logged commands.[l77] 

 

# Thefollowing time is expressed in microseconds, so 1000000 is equivalent

# to one second. Note that a negativenumber disables the slow log, while

# a value of zero forces the logging ofevery command.[l78] 

slowlog-log-slower-than 10000

 

#There is no limit to this length. Just be aware that it will consume memory.

# You can reclaim memory used by the slowlog with SLOWLOG RESET.[l79] 

slowlog-max-len 128

 

###### LATENCYMONITOR[l80] ##############################

#The Redis latency monitoring subsystem samples different operations

# at runtime in order to collect datarelated to possible sources of

# latency of a Redis instance.[l81] 

#

# Viathe LATENCY command this information is available to the user that can

# print graphs and obtain reports.[l82] 

#

#The system only logs operations that were performed in a time equal or

# greater than the amount of millisecondsspecified via the

# latency-monitor-threshold configurationdirective. When its value is set

# to zero, the latency monitor is turnedoff.[l83] 

#

# Bydefault latency monitoring is disabled since it is mostly not needed

# if you don't have latency issues, andcollecting data has a performance

# impact, that while very small, can bemeasured under big load. Latency

# monitoring can easily be enabled atruntime using the command

# "CONFIG SETlatency-monitor-threshold <milliseconds>" if needed.[l84] 

latency-monitor-threshold 0

13.   事件通知設置說明

##### EVENTNOTIFICATION [l85] ##############################

 

# Rediscan notify Pub/Sub clients about events happening in the key space.

# This feature is documented athttp://redis.io/topics/notifications[l86] 

#

#For instance if keyspace events notification is enabled, and a client

# performs a DEL operation on key"foo" stored in the Database 0, two

# messages will be published via Pub/Sub:[l87] 

#

# PUBLISH __keyspace@0__:foo del

# PUBLISH __keyevent@0__:del foo

#

# Itis possible to select the events that Redis will notify among a set

# of classes. Every class is identifiedby a single character:[l88] 

#

#  K     Keyspace events, published with__keyspace@<db>__ prefix.[l89] 

#  E     Keyevent events, published with__keyevent@<db>__ prefix.[l90] 

#  g     Generic commands (non-type specific) like DEL,EXPIRE, RENAME, ...[l91] 

#  $     String commands[l92] 

#  l     List commands[l93] 

#  s     Set commands[l94] 

#  h     Hash commands[l95] 

#  z     Sorted set commands[l96] 

#  x     Expired events (events generated every time akey expires)[l97] 

#  e     Evicted events (events generated when a key isevicted for maxmemory)[l98] 

#  A     Alias for g$lshzxe, so that the "AKE"string means all the events[l99] .

#

The "notify-keyspace-events"takes as argument a string that is composed

# of zero or multiple characters. The empty string means thatnotifications

# are disabled.

#[l100] 

#  Example: to enable list and generic events,from the point of view of the

#           event name, use:[l101] 

#

#  notify-keyspace-events Elg

#

Example 2: to get the stream of the expiredkeys subscribing to channel

#             name __keyevent@0__:expired use:[l102] 

#

#  notify-keyspace-events Ex

#

By default all notifications are disabledbecause most users don't need

# this feature and the feature has some overhead. Note that if you don't

# specify at least one of K or E, no events will be delivered.[l103] 

notify-keyspace-events ""

14.   高級配置設置說明

###### ADVANCEDCONFIG [l104] ###############################

 

#Hashes are encoded using a memory efficient data structure when they have a

# small number of entries, and thebiggest entry does not exceed a given

# threshold. These thresholds can beconfigured using the following directives.[l105] 

hash-max-ziplist-entries 512

hash-max-ziplist-value 64

 

#Lists are also encoded in a special way to save a lot of space.

# The number of entries allowed perinternal list node can be specified

# as a fixed maximum size or a maximumnumber of elements.

# For a fixed maximum size, use -5through -1, meaning:[l106] 

#-5: max size: 64 Kb  <-- notrecommended for normal workloads

# -4: max size: 32 Kb  <-- not recommended

# -3: max size: 16 Kb  <-- probably not recommended

# -2: max size: 8 Kb   <-- good

# -1: max size: 4 Kb   <-- good[l107] 

# Positivenumbers mean store up to _exactly_ that number of elements

# per list node.[l108] 

# Thehighest performing option is usually -2 (8 Kb size) or -1 (4 Kb size),

# but if your use case is unique, adjustthe settings as necessary.[l109] 

list-max-ziplist-size -2

 

#Lists may also be compressed.[l110] 

#Compress depth is the number of quicklist ziplist nodes from *each* side of

# the list to *exclude* fromcompression.  The head and tail of thelist

# are always uncompressed for fast push/popoperations.  Settings are:[l111] 

#0: disable all list compression

# 1: depth 1 means "don't startcompressing until after 1 node into the list,

#   going from either the head or tail"

#   So: [head]->node->node->...->node->[tail]

#   [head], [tail] will always be uncompressed; inner nodes will compress.[l112] 

# 2:[head]->[next]->node->node->...->node->[prev]->[tail]

#   2 here means: don't compress head or head->next or tail->prev ortail,

#   but compress all nodes between them.

# 3: [head]->[next]->[next]->node->node->...->node->[prev]->[prev]->[tail]

# etc.[l113] 

list-compress-depth 0

 

#Sets have a special encoding in just one case: when a set is composed

# of just strings that happen to beintegers in radix 10 in the range

# of 64 bit signed integers.[l114] 

# Thefollowing configuration setting sets the limit in the size of the

# set in order to use this special memorysaving encoding.[l115] 

set-max-intset-entries 512

 

# Similarlyto hashes and lists, sorted sets are also specially encoded in

# order to save a lot of space. Thisencoding is only used when the length and

# elements of a sorted set are below thefollowing limits:[l116] 

zset-max-ziplist-entries 128

zset-max-ziplist-value 64

 

# HyperLogLogsparse representation bytes limit. The limit includes the

# 16 bytes header. When an HyperLogLogusing the sparse representation crosses

# this limit, it is converted into thedense representation.[l117] 

#

# Avalue greater than 16000 is totally useless, since at that point the

# dense representation is more memoryefficient.[l118] 

#

# Thesuggested value is ~ 3000 in order to have the benefits of

# the space efficient encoding withoutslowing down too much PFADD,

# which is O(N) with the sparse encoding.The value can be raised to

# ~ 10000 when CPU is not a concern, butspace is, and the data set is

# composed of many HyperLogLogs withcardinality in the 0 - 15000 range.[l119] 

hll-sparse-max-bytes 3000

 

#Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in

# order to help rehashing the main Redishash table (the one mapping top-level

# keys to values). The hash tableimplementation Redis uses (see dict.c)

# performs a lazy rehashing: the moreoperation you run into a hash table

# that is rehashing, the more rehashing"steps" are performed, so if the

# server is idle the rehashing is nevercomplete and some more memory is used

# by the hash table.[l120] 

#

# Thedefault is to use this millisecond 10 times every second in order to

# actively rehash the main dictionaries,freeing memory when possible.[l121] 

#

# If unsure:

#use "activerehashing no" if you have hard latency requirements and itis

# not a good thing in your environmentthat Redis can reply from time to time

# to queries with 2 milliseconds delay.[l122] 

#

# use"activerehashing yes" if you don't have such hard requirements but

# want to free memory asap when possible.[l123] 

activerehashing yes

 

# Theclient output buffer limits can be used to force disconnection of clients

# that are not reading data from theserver fast enough for some reason (a

# common reason is that a Pub/Sub clientcan't consume messages as fast as the

# publisher can produce them).[l124] 

#

# Thelimit can be set differently for the three different classes of clients:[l125] 

#

#normal -> normal clients including MONITOR clients

# slave -> slave clients

# pubsub -> clients subscribed to atleast one pubsub channel or pattern[l126] 

#

# Thesyntax of every client-output-buffer-limit directive is the following:[l127] 

#

# client-output-buffer-limit<class> <hard limit> <soft limit> <soft seconds>[l128] 

#

#A client is immediately disconnected once the hard limit is reached, or if

# the soft limit is reached and remainsreached for the specified number of

# seconds (continuously).[l129] 

# Sofor instance if the hard limit is 32 megabytes and the soft limit is

# 16 megabytes / 10 seconds, the clientwill get disconnected immediately

# if the size of the output buffers reach32 megabytes, but will also get

# disconnected if the client reaches 16megabytes and continuously overcomes

# the limit for 10 seconds.[l130] 

#

# Bydefault normal clients are not limited because they don't receive data

# without asking (in a push way), butjust after a request, so only

# asynchronous clients may create ascenario where data is requested faster

# than it can read.[l131] 

#

#Instead there is a default limit for pubsub and slave clients, since

# subscribers and slaves receive data ina push fashion.[l132] 

#

#Both the hard or the soft limit can be disabled by setting them to zero.[l133] 

client-output-buffer-limit normal 0 0 0

client-output-buffer-limit slave 256mb 64mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

 

# Rediscalls an internal function to perform many background tasks, like

# closing connections of clients intimeout, purging expired keys that are

# never requested, and so forth.[l134] 

#

#Not all tasks are performed with the same frequency, but Redis checks for

# tasks to perform according to thespecified "hz" value.[l135] 

#

# Bydefault "hz" is set to 10. Raising the value will use more CPU when

# Redis is idle, but at the same timewill make Redis more responsive when

# there are many keys expiring at thesame time, and timeouts may be

# handled with more precision.[l136] 

#

# Therange is between 1 and 500, however a value over 100 is usually not

# a good idea. Most users should use thedefault of 10 and raise this up to

# 100 only in environments where very lowlatency is required.[l137] 

hz 10

 

#When a child rewrites the AOF file, if the following option is enabled

# the file will be fsync-ed every 32 MBof data generated. This is useful

# in order to commit the file to the diskmore incrementally and avoid

# big latency spikes.[l138] 

aof-rewrite-incremental-fsync yes

 


 [l1]安全設置

 [l2]要求客戶端在處理任何其餘命令以前發出AUTH <PASSWORD>這在您不信任其餘人訪問運行redis-server的主機的環境中可能頗有用

 [l3]這應該保持註釋掉向後兼容性,由於大多數人不須要身份驗證(例如他們運行本身的服務器)。

 [l4]警告:因爲Redis是至關快的外部用戶能夠嘗試高達每秒15萬個密碼對。這意味着你應該使用很是強的密碼,不然將很容易破解

 [l5]命令更名

 [l6]能夠在共享環境中更改危險命令的名稱。 例如,CONFIG命令能夠重命名爲難以猜想的東西,以便它仍然可用於內部使用工具,但不能用於通常客戶端

 [l7]也能夠經過將命令重命名爲空字符串來徹底限制命令:
重命名命令CONFIG「」

 [l8]請注意,更改登陸到AOF文件或發送到從站的命令的名稱可能會致使問題。

 [l9]限制設置

 [l10]同時設置鏈接的客戶端的最大數量。 默認狀況下,此限制設置爲10000個客戶端,可是若是Redis服務器沒法配置進程文件限制以容許指定的限制,則容許的客戶端的最大數量設置爲當前文件限制減32(由於Redis保留少數用於內部使用的文件描述符)

 [l11]一旦達到限制,Redis將關閉全部發送錯誤「達到最大客戶端數」的新鏈接。

 [l12]不要使用比指定的字節數更多的內存。 當達到內存限制時,Redis將嘗試根據選擇的逐出策略刪除密鑰(請參閱maxmemory-policy

 [l13]若是Redis沒法根據策略刪除密鑰,或者若是策略設置爲「noeviction」,Redis將開始對將使用更多內存(如SETLPUSH等)的命令進行回覆,並將繼續以回覆只讀命令(如GET

 [l14]當使用Redis做爲LRU緩存時,或者爲實例設置硬內存限制(使用'noeviction'策略)時,此選項一般頗有用。

 [l15]警告:若是您的從屬設備鏈接到具備maxmemory的實例,則從使用的內存計數中減去饋送從屬設備所需的輸出緩衝區的大小,以便網絡問題/從新同步不會觸發按鍵被逐出的循環,以及從屬設備的輸出緩衝器充滿DEL的鍵被逐出觸發刪除更多的鍵,等等,直到數據庫被徹底清空

 [l16]簡而言之...若是你有奴隸附加,建議你設置maxmemory的下限,以便系統上有一些空閒的RAM用於從輸出緩衝區(但若是策略是noeviction,則不須要)。

 [l17]MAXMEMORY POLICYRedis將如何選擇在達到maxmemory時要刪除的內容。您能夠選擇五種行爲:

 [l18]volatile-lru - >使用LRU算法刪除具備過時集的密鑰
allkeys-lru - >根據LRU算法刪除任何密鑰
volatile-random - >刪除帶有過時集的隨機密鑰

 [l19]allkeys-random - >刪除隨機密鑰,任意密鑰
 volatile-ttl - >刪除具備最近過時時間的密鑰(次TTL
 noeviction - >不要過時,只是在寫操做時返回一個錯誤

 [l20]注意:使用上述任何策略,當沒有合適的驅逐鍵時,Redis將在寫操做時返回一個錯誤。

 [l21]在寫這些命令時:setsetnx setex append incr decr rpush lpush rpushx lpushx linsert lset rpoplpushsadd sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrbyzunionstore zinterstore hset hsetnx hmset hincrby incrby decrby getset msetmsetnx exec sort

 [l22]LRU和最小TTL算法不是精確算法,而是近似算法(以便節省內存),所以您能夠調整它的速度或精度。默認狀況下,Redis將檢查五個鍵,並選擇最近使用的鍵,可使用如下配置指令更改樣本大小

 [l23]默認值爲5產生足夠好的結果。 10近似很是接近真實的LRU,但成本更多的CPU 3是很是快,但不是很準確

 [l24]僅追加方式配置

 [l25]默認狀況下,Redis異步地轉儲磁盤上的數據集。 這種模式對許多應用程序已經足夠了,可是若是斷電或者redis進程除問題就會致使一段時間內的更新數據丟失(取決於配置項)

 [l26]這種只增文件是可選的可以提供更好的體驗的數據持久化策略。舉個例子,若是使用默認的配置數據fsync策略,在服務器意外斷電的狀況下redis只會丟失一秒鐘內的更新數據,或者當redis進程出問題但操做系統運轉正常時,redis只會丟失一個數據更新操做

 [l27]AOFRDB持久性能夠同時啓用而且無衝突。若是AOF開啓,啓動redis時會加載aof文件,這些文件可以提供更好的保證。

 [l28]請查看http://redis.io/topics/persistence以獲取更多信息

 [l29]只增文件的名稱(默認值:「appendonly.aof」)

 [l30]調用fsync()函數會通知操做系統真正將數據寫入磁盤,而不是等待緩衝區中更多數據。有些操做系統會將數據輸出到磁盤,有些操做系統知識ASAP

 [l31]Redis支持三種不一樣的方式

 [l32]No:不調用,當操做系統要輸出數據時只等待操做系統來清空緩衝區。很快

Always:每次更新數據都寫入僅增文件。慢,可是最安全

Ererysec:每秒調用一次。折中

 [l33]默認是每秒中一次,由於它每每是在速度和數據安全二者之間的折中選擇。若是你能夠接受讓操做系統去自動清空緩存,你能夠降這項配置下降到no(若是你能夠接受一段時間的數據丟失,默認的rdb就足夠了),這徹底取決與你。若是你想要一個更好的體驗或者從相反的角度,使用always,這樣會很慢,可是比everysec安全些。

 [l34]請在下面的文章中獲取更多細節知識:

http://antirez.com/post/redis-persistence-demystified.html

 [l35]若是你不是很清楚這三項之間的區別,或者不知道哪一種適合你的機器,就用默認吧。

 [l36]AOF策略設置爲always或者everysec的時候,後臺的保存進程會進行不少磁盤I/O操做,在某些linux結構中redis會在調用sync()方法時阻塞很長時間,記住,如今尚未辦法解決這個問題,及時在不一樣進程中進行調用也會block

 [l37]使用以下配置可能會緩解這個問題,這樣會在存儲大數據或者BGREWRITEAOF的時候不會在主進程中調用fsync()方法。

 [l38]這表示,若是另一個子進程在保存操做,redis的表現如同配置爲appendfsync no。在實際應用中,這表示在最壞的情境下(使用linux默認配置)可能會丟失30秒日誌

 [l39]若是你有特殊的狀況能夠配置爲yes。可是配置問爲no是最爲安全的選擇。

 [l40]自動重寫只增文件

 [l41]Redis能夠自動盲從的調用BGREWRITEAOF來重寫日誌,若是日誌文件增加了指定的百分比。

 [l42]它是這樣工做的:每次rewriteredis會記錄日誌文件的大小(若是重啓後沒有重寫後的大小,就默認用日誌文件大小)

 [l43]這個基準日志大小和當前日誌大小作比較。若是當前大小比指定的百分比大,重寫機制就會被觸發。同時,你也要指定一個重寫下線,用來增加百分比,可是日誌文件還很小的狀況下。

 [l44]指定百分比爲0能夠註釋自動重寫日誌文件功能。

 [l45]AIF數據被加載回內存時,可能會發現AIF文件在Redis啓動過程結束時被截斷。這可能發生在當Redis運行的系統崩潰時,特別是當ext4文件系統沒有data = ordered選項時(可是當Redis自己崩潰或停止,但操做系統仍然正常工做時)

 [l46]Redis能夠在發生這種狀況時退出錯誤,或者加載儘量多的數據(如今是默認值),若是發現AOF文件在末尾被截斷,則啓動。如下選項控制此行爲

 [l47]若是aof-load-truncated設置爲yes,將加載截斷的AOF文件,Redis服務器開始發出日誌以通知用戶該事件。 不然,若是該選項設置爲no,服務器將停止並出現錯誤,並拒絕啓動。 當該選項設置爲no時,用戶須要在從新啓動服務器以前使用「redis-check-aof」實用程序修復AOF文件

 [l48]請注意,若是AOF文件將被髮如今中間被損壞,服務器仍將退出並出現錯誤。 此選項僅在Redis嘗試從AOF文件讀取更多數據但找不到足夠的字節時適用

 [l49]LUA腳本設置

 [l50]Lua腳本的最大執行時間(以毫秒爲單位)。

 [l51]若是達到最大執行時間,Redis將記錄一個腳本在最大容許時間以後仍在執行,並將開始回覆具備錯誤的查詢。

 [l52]當長時間運行的腳本超過最大執行時間時,只有SCRIPT KILLSHUTDOWN NOSAVE命令可用。第一個可用於中止還沒有調用寫入命令的腳本。第二種是在腳本已經發出寫入命令但用戶不想等待腳本天然終止的狀況下關閉服務器的惟一方法

 [l53]將其設置爲0或負值,無限制執行,不帶警告。

 [l54]Redis集羣設置

 [l55]警告實驗:Redis羣集被認爲是穩定的代碼,可是爲了將其標記爲「成熟」,咱們須要等待很是小百分比的用戶將其部署到生產環境中。

 [l56]正常Redis實例不能是Redis羣集的一部分; 只有做爲集羣節點啓動的節點才能夠。爲了將Redis實例做爲羣集節點啓動,請啓用羣集支持,取消註釋如下內容

 [l57]每一個集羣節點都有一個集羣配置文件。 此文件不能手動編輯。 它由Redis節點建立和更新。 每一個Redis羣集節點都須要一個不一樣的羣集配置文件。 確保在同一系統中運行的實例不具備重疊的羣集配置文件名

 [l58]集羣節點超時是節點必須沒法訪問的毫秒數,以便將其視爲處於故障狀態。

 [l59]大多數其餘內部時間限制是節點超時的倍數。

 [l60]若是故障主控的從屬數據看起來太舊,則它將避免啓動故障轉移。

 [l61]沒有簡單的方法使從機實際上具備其「數據時間」的精確測量,所以執行如下兩個檢查:

 [l62]1)若是有多個從設備可以故障切換,它們交換消息,以便嘗試給從設備提供具備最佳複製偏移(來自主設備處理的更多數據)的優勢。從設備將嘗試經過偏移得到它們的排名,並應用於故障轉移的開始與它們的排名成比例的延遲

 [l63]2)每一個單獨的從機計算與其主機的最後一次交互的時間。這能夠是接收到的最後一個ping或命令(若是主設備仍處於「已鏈接」狀態),或自從與主設備斷開鏈接後所通過的時間(若是複製連接當前已關閉)。若是最後一次交互太舊,從設備將不會嘗試進行故障切換

 [l64]點「2」能夠由用戶調諧。 特別地,從主機將不執行故障轉移,由於自從與主機的最後交互,通過的時間大於

 [l65]所以,例如,若是node-timeout30秒,從屬有效因子爲10,而且假定默認的replet-slave-slave-period10秒,則若是slave不能通話,則slave不會嘗試進行故障轉移 與主站的時間超過310

 [l66]大的從有效性因子能夠容許具備太舊數據的從設備故障轉移主設備,而過小的值可能阻止集羣可以選擇全部的從設備。

 [l67]爲了實現最大可用性,能夠將從屬有效因子設置爲0,這意味着從屬設備將始終嘗試故障轉移主設備,而無論他們最後一次與主設備進行交互的時間。(可是,他們老是試圖應用與它們的偏移等級成比例的延遲)

 [l68]零是惟一可以保證當全部分區修復集羣時老是可以繼續的值。

 [l69]羣集從設備可以遷移到孤立主設備,即沒有工做從設備的主設備。 這提升了集羣抵禦故障的能力,不然孤立主機在沒有工做從機的狀況下沒法故障轉移

 [l70]只有當至少有必定數量的其餘工做從設備用於它們的舊主設備時,從設備才遷移到孤立主設備。這個數字是「遷移障礙」。遷移障礙爲1意味着只有當主設備至少有1個其餘工做從設備時,從設備纔會遷移。它一般反映您但願羣集中每一個主機的從站數

 [l71]默認值爲1(從機只在主機保留至少一個從機時遷移)。 要禁用遷移,只需將其設置爲很是大的值。 值爲0能夠設置,但僅用於調試和生產中的危險

 [l72]默認狀況下,若是Redis集羣節點檢測到至少有一個散列槽未覆蓋(沒有可用節點正在爲其提供服務),則它們將中止接受查詢。這樣,若是集羣部分關閉(例如,一系列散列槽再也不被覆蓋),則全部集羣變得最終不可用。一旦全部插槽再次覆蓋,它將自動返回可用

 [l73]可是有時候你想要的集羣的子集是工做,繼續接受仍然覆蓋的部分關鍵空間的查詢。爲此,只需將cluster-require-full-coverage選項設置爲no

 [l74]爲了設置您的羣集,請務必閱讀http://redis.io網站上提供的文檔。

 [l75]Slow log設置

 [l76]Redis Slow Log是一種用於記錄超過指定執行時間的查詢的系統。執行時間不包括I / O操做,例如與客戶端通訊,發送答覆等等,而只是實際執行命令所需的時間(這是命令執行的惟一階段,其中線程被阻止,而且能夠在此期間不提供其餘請求)

 [l77]您可使用兩個參數配置慢日誌:一個告訴Redis爲了使命令被記錄而超過的執行時間(以微秒爲單位),另外一個參數是慢日誌的長度。當記錄新的命令時,最舊的命令從記錄的命令隊列中刪除

 [l78]如下時間以微秒錶示,所以1000000等效於一秒。 請注意,負數禁用緩慢日誌,而值爲零強制記錄每一個命令

 [l79]這個長度沒有限制。 只是要注意它會消耗內存。 您可使用SLOWLOGRESET來回收慢日誌使用的內存

 [l80]延遲監視器設置

 [l81]Redis延遲監視子系統在運行時對不一樣的操做進行採樣,以便收集與Redis實例的可能的延遲源相關的數據。

 [l82]經過LATENCY命令,此信息可供用戶打印圖形並獲取報告。

 [l83]系統僅記錄在等於或大於經過latency-monitor-threshold配置指令指定的毫秒數的時間內執行的操做。 當其值設置爲零時,延遲監視器關閉

 [l84]默認狀況下,延遲監控被禁用,由於若是您沒有延遲問題,則大多不須要延遲監控,而且收集數據對性能的影響很小,能夠在大負載下測量。若是須要,能夠在運行時使用命令「CONFIG SET latency-monitor-threshold <milliseconds>」輕鬆啓用延遲監視

 [l85]事件通知設置

 [l86]Redis能夠通知發佈/訂閱客戶端關鍵空間中發生的事件。此功能在http://redis.io/topics/notifications中有記錄

 [l87]例如,若是啓用了鍵空間事件通知,而且客戶端對存儲在數據庫0中的鍵「foo」執行DEL操做,則將經過發佈/訂閱發佈兩個消息:

 [l88]能夠選擇Redis在一組類中通知的事件。 每一個類由單個字符標識

 [l89]鍵空間事件,使用__keyspace @ <db> __前綴發佈。

 [l90]Keyevent事件,使用__keyevent@ <db> __前綴發佈。

 [l91]通用命令(非特定類型),如DELEXPIRERENAME...

 [l92]字符串命令

 [l93]列出命令

 [l94]設置命令

 [l95]哈希命令

 [l96]排序集命令

 [l97]過時事件(每次密鑰過時時生成的事件)

 [l98]驅逐事件(當爲maxmemory驅逐某個鍵時生成的事件)

 [l99]g $ lshzxe的別名,所以「AKE」字符串表示全部事件。

 [l100]notify-keyspace-events」接受由零個或多個字符組成的字符串做爲參數。 空字符串表示禁用通知

 [l101]示例:要啓用列表和通用事件,從事件名稱的角度,使用:

 [l102]示例2:獲取過時密鑰流訂閱頻道名稱__keyevent@ 0 __expired use

 [l103]默認狀況下,全部通知都被禁用,由於大多數用戶不須要此功能,該功能有一些開銷。請注意,若是您未指定KE中的至少一個,則不會傳送任何事件

 [l104]高級配置設置

 [l105]當哈希值具備少許條目且最大條目不超過給定閾值時,使用存儲器有效數據結構來對哈希進行編碼。這些閾值可使用如下指令進行配置

 [l106]列表也以特殊方式編碼以節省大量空間。 每一個內部列表節點容許的條目數能夠指定爲固定的最大大小或最大數量的元素。對於固定的最大大小,請使用-5-1,表示

 [l107]-5:最大大小:64 Kb < - 不推薦用於正常工做負載
-4:最大尺寸:32 Kb < - 不推薦
-3:最大尺寸:16 Kb < - 可能不推薦
-2:最大尺寸:8Kb < -
-1:最大尺寸:4 Kb < -

 [l108]正數表示每一個列表節點存儲的元素數量正好相等。

 [l109]最高性能選項一般爲-28 Kb大小)或-14 Kb大小),但若是您的用例是惟一的,請根據須要調整設置。

 [l110]列表也能夠被壓縮。

 [l111]壓縮深度是從列表的每一個*側到*排除*從壓縮的快速清單ziplist節點的數量。 列表的頭部和尾部老是未壓縮的,用於快速推送/彈出操做。 設置包括:

 [l112]0:禁用全部列表壓縮
1:深度1意味着「不要開始壓縮,直到1個節點進入列表,從頭或尾」去:[head] - > node-> node - > ...-> node - > [tail ][head][tail]將始終未壓縮; 內部節點將壓縮。

 [l113]2[head] - > [next] - > node-> node-> ...-> node->[prev] - > [tail] 2這裏的意思是:不壓縮headhead-> nexttail - > prevtail,但壓縮它們之間的全部節點。
3[head] - > [next] - > [next] - > node-> node->...-> node-> [prev]

 [l114]集合在一種狀況下有一個特殊的編碼:當一個集合由恰好是在64位有符號整數範圍內的基數爲10的整數的字符串組成時。

 [l115]如下配置設置設置集合大小的限制,以便使用此特殊內存保存編碼。

 [l116]與散列和列表相似,排序集也是專門編碼的,以節省大量空間。 此編碼僅在已排序集合的長度和元素低於如下限制時使用:

 [l117]HyperLogLog稀疏表示字節限制。該限制包括16字節報頭。當使用稀疏表示的HyperLogLog超過此限制時,它將轉換爲密集表示

 [l118]大於16000的值是徹底無用的,由於在那一點上,密集表示是更有效的存儲器。

 [l119]建議的值爲3000,以便具備空間有效編碼的優勢,而不減慢過多的PFADD,這是具備稀疏編碼的ON)。CPU不是一個問題,但空間是,而且數據集由許多HyperLogLogs組成的基數在0 - 15000範圍內的值,能夠提升到10000

 [l120]主動從新散列每100毫秒的CPU時間使用1毫秒,以幫助從新散列主Redis散列表(一個映射頂層鍵值)。 Redis使用(見dict.c)執行的哈希表實現執行一個延遲從新哈希:更多的操做運行到哈希表是從新哈希,執行更多的從新哈希「步驟」,因此若是服務器空閒,從新哈希不會完成和一些更多的內存被哈希表使用

 [l121]默認是每秒使用這個毫秒10次,以便主動從新搜索主要的字典,儘量釋放內存

 [l122]若是您有硬延遲要求,而且在您的環境中Redis能夠不時地回覆2毫秒延遲的查詢不是一件好事,請使用「activerehashing no」。

 [l123]使用「activerehashing是」,若是你沒有這麼硬的要求,但想盡量釋放內存。

 [l124]客戶端輸出緩衝區限制能夠用於強制斷開鏈接不正確地從服務器讀取數據的客戶端(一個常見的緣由是發佈/訂閱客戶端不能像發佈者那樣生成消息那麼快)

 [l125]能夠爲三個不一樣類別的客戶端設置不一樣的限制:

 [l126]正常 - >正常客戶端,包括MONITOR客戶端
從站 - >從站客戶端
pubsub - >客戶端訂閱至少一個pubsub通道或模式

 [l127]每一個client-output-buffer-limit僞指令的語法以下:

 [l128]客戶端輸出緩衝區限制<class> <硬限制> <軟限制> <軟秒>

 [l129]一旦達到硬限制,或者達到軟限制並保持達到指定的秒數(持續),客戶端將當即斷開。

 [l130]所以,例如,若是硬限制爲32兆字節,軟限制爲16兆字節/ 10秒,則若是輸出緩衝區的大小達到32兆字節,客戶端將當即斷開鏈接,但若是客戶端達到16兆字節,則客戶端也將斷開鏈接,連續超過10秒的限制

 [l131]默認狀況下,正常客戶端不受限制,由於它們不接收數據而不詢問(以推送方式),而是僅在請求以後,所以只有異步客戶端能夠建立其中數據被請求比其能夠讀取更快的場景。

 [l132]相反,對於pubsub和從屬客戶端,存在默認限制,由於訂閱者和從屬以推送方式接收數據。

 [l133]經過將它們設置爲零,能夠禁用硬限制或軟限制。

 [l134]Redis調用內部函數來執行許多後臺任務,例如在超時時間關閉客戶端鏈接,清除從未請求的過時密鑰等。

 [l135]並不是全部任務都以相同的頻率執行,但Redis根據指定的「hz」值檢查要執行的任務。

 [l136]

 [l137]範圍在1500之間,可是超過100的值一般不是一個好主意。 大多數用戶應使用默認值10,而且只在須要很是低延遲的環境中將其提升到100

 [l138]當子代重寫AOF文件時,若是啓用如下選項,則文件將每生成32 MB數據進行fsync-ed這是有用的,以便更加漸進地提交文件到磁盤,並避免大的延遲高峯