redis.conf 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. # Redis配置文件样例
  2. # Note on units: when memory size is needed, it is possible to specifiy
  3. # it in the usual form of 1k 5GB 4M and so forth:
  4. #
  5. # 1k => 1000 bytes
  6. # 1kb => 1024 bytes
  7. # 1m => 1000000 bytes
  8. # 1mb => 1024*1024 bytes
  9. # 1g => 1000000000 bytes
  10. # 1gb => 1024*1024*1024 bytes
  11. #
  12. # units are case insensitive so 1GB 1Gb 1gB are all the same.
  13. # Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程
  14. # 启用守护进程后,Redis会把pid写到一个pidfile中,在/var/run/redis.pid
  15. daemonize no
  16. # 当Redis以守护进程方式运行时,Redis默认会把pid写入/var/run/redis.pid文件,可以通过pidfile指定
  17. pidfile /var/run/redis.pid
  18. # 指定Redis监听端口,默认端口为6379
  19. # 如果指定0端口,表示Redis不监听TCP连接
  20. port 6379
  21. # 绑定的主机地址
  22. # 你可以绑定单一接口,如果没有绑定,所有接口都会监听到来的连接
  23. # bind 127.0.0.1
  24. protected-mode no
  25. # Specify the path for the unix socket that will be used to listen for
  26. # incoming connections. There is no default, so Redis will not listen
  27. # on a unix socket when not specified.
  28. #
  29. # unixsocket /tmp/redis.sock
  30. # unixsocketperm 755
  31. # 当客户端闲置多长时间后关闭连接,如果指定为0,表示关闭该功能
  32. timeout 0
  33. # 指定日志记录级别,Redis总共支持四个级别:debug、verbose、notice、warning,默认为verbose
  34. # debug (很多信息, 对开发/测试比较有用)
  35. # verbose (many rarely useful info, but not a mess like the debug level)
  36. # notice (moderately verbose, what you want in production probably)
  37. # warning (only very important / critical messages are logged)
  38. loglevel verbose
  39. # 日志记录方式,默认为标准输出,如果配置为redis为守护进程方式运行,而这里又配置为标准输出,则日志将会发送给/dev/null
  40. # logfile /logs/redis.log
  41. # To enable logging to the system logger, just set 'syslog-enabled' to yes,
  42. # and optionally update the other syslog parameters to suit your needs.
  43. # syslog-enabled no
  44. # Specify the syslog identity.
  45. # syslog-ident redis
  46. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
  47. # syslog-facility local0
  48. # 设置数据库的数量,默认数据库为0,可以使用select <dbid>命令在连接上指定数据库id
  49. # dbid是从0到‘databases’-1的数目
  50. databases 16
  51. ################################ SNAPSHOTTING #################################
  52. # 指定在多长时间内,有多少次更新操作,就将数据同步到数据文件,可以多个条件配合
  53. # Save the DB on disk:
  54. #
  55. # save <seconds> <changes>
  56. #
  57. # Will save the DB if both the given number of seconds and the given
  58. # number of write operations against the DB occurred.
  59. #
  60. # 满足以下条件将会同步数据:
  61. # 900秒(15分钟)内有1个更改
  62. # 300秒(5分钟)内有10个更改
  63. # 60秒内有10000个更改
  64. # Note: 可以把所有“save”行注释掉,这样就取消同步操作了
  65. save 900 1
  66. save 300 10
  67. save 60 10000
  68. # 指定存储至本地数据库时是否压缩数据,默认为yes,Redis采用LZF压缩,如果为了节省CPU时间,可以关闭该选项,但会导致数据库文件变的巨大
  69. rdbcompression yes
  70. # 指定本地数据库文件名,默认值为dump.rdb
  71. dbfilename dump.rdb
  72. # 工作目录.
  73. # 指定本地数据库存放目录,文件名由上一个dbfilename配置项指定
  74. #
  75. # Also the Append Only File will be created inside this directory.
  76. #
  77. # 注意,这里只能指定一个目录,不能指定文件名
  78. dir ./
  79. ################################# REPLICATION #################################
  80. # 主从复制。使用slaveof从 Redis服务器复制一个Redis实例。注意,该配置仅限于当前slave有效
  81. # so for example it is possible to configure the slave to save the DB with a
  82. # different interval, or to listen to another port, and so on.
  83. # 设置当本机为slav服务时,设置master服务的ip地址及端口,在Redis启动时,它会自动从master进行数据同步
  84. # slaveof <masterip> <masterport>
  85. # 当master服务设置了密码保护时,slav服务连接master的密码
  86. # 下文的“requirepass”配置项可以指定密码
  87. # masterauth <master-password>
  88. # When a slave lost the connection with the master, or when the replication
  89. # is still in progress, the slave can act in two different ways:
  90. #
  91. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
  92. # still reply to client requests, possibly with out of data data, or the
  93. # data set may just be empty if this is the first synchronization.
  94. #
  95. # 2) if slave-serve-stale data is set to 'no' the slave will reply with
  96. # an error "SYNC with master in progress" to all the kind of commands
  97. # but to INFO and SLAVEOF.
  98. #
  99. slave-serve-stale-data yes
  100. # Slaves send PINGs to server in a predefined interval. It's possible to change
  101. # this interval with the repl_ping_slave_period option. The default value is 10
  102. # seconds.
  103. #
  104. # repl-ping-slave-period 10
  105. # The following option sets a timeout for both Bulk transfer I/O timeout and
  106. # master data or ping response timeout. The default value is 60 seconds.
  107. #
  108. # It is important to make sure that this value is greater than the value
  109. # specified for repl-ping-slave-period otherwise a timeout will be detected
  110. # every time there is low traffic between the master and the slave.
  111. #
  112. # repl-timeout 60
  113. ################################## SECURITY ###################################
  114. # Warning: since Redis is pretty fast an outside user can try up to
  115. # 150k passwords per second against a good box. This means that you should
  116. # use a very strong password otherwise it will be very easy to break.
  117. # 设置Redis连接密码,如果配置了连接密码,客户端在连接Redis时需要通过auth <password>命令提供密码,默认关闭
  118. requirepass 123456
  119. # Command renaming.
  120. #
  121. # It is possilbe to change the name of dangerous commands in a shared
  122. # environment. For instance the CONFIG command may be renamed into something
  123. # of hard to guess so that it will be still available for internal-use
  124. # tools but not available for general clients.
  125. #
  126. # Example:
  127. #
  128. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
  129. #
  130. # It is also possilbe to completely kill a command renaming it into
  131. # an empty string:
  132. #
  133. # rename-command CONFIG ""
  134. ################################### LIMITS ####################################
  135. # 设置同一时间最大客户端连接数,默认无限制,Redis可以同时打开的客户端连接数为Redis进程可以打开的最大文件描述符数,
  136. # 如果设置maxclients 0,表示不作限制。当客户端连接数到达限制时,Redis会关闭新的连接并向客户端返回max Number of clients reached错误信息
  137. # maxclients 128
  138. # Don't use more memory than the specified amount of bytes.
  139. # When the memory limit is reached Redis will try to remove keys with an
  140. # EXPIRE set. It will try to start freeing keys that are going to expire
  141. # in little time and preserve keys with a longer time to live.
  142. # Redis will also try to remove objects from free lists if possible.
  143. #
  144. # If all this fails, Redis will start to reply with errors to commands
  145. # that will use more memory, like SET, LPUSH, and so on, and will continue
  146. # to reply to most read-only commands like GET.
  147. #
  148. # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
  149. # 'state' server or cache, not as a real DB. When Redis is used as a real
  150. # database the memory usage will grow over the weeks, it will be obvious if
  151. # it is going to use too much memory in the long run, and you'll have the time
  152. # to upgrade. With maxmemory after the limit is reached you'll start to get
  153. # errors for write operations, and this may even lead to DB inconsistency.
  154. # 指定Redis最大内存限制,Redis在启动时会把数据加载到内存中,达到最大内存后,Redis会先尝试清除已到期或即将到期的Key,
  155. # 当此方法处理后,仍然到达最大内存设置,将无法再进行写入操作,但仍然可以进行读取操作。
  156. # Redis新的vm机制,会把Key存放内存,Value会存放在swap区
  157. # maxmemory <bytes>
  158. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
  159. # is reached? You can select among five behavior:
  160. #
  161. # volatile-lru -> remove the key with an expire set using an LRU algorithm
  162. # allkeys-lru -> remove any key accordingly to the LRU algorithm
  163. # volatile-random -> remove a random key with an expire set
  164. # allkeys->random -> remove a random key, any key
  165. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)
  166. # noeviction -> don't expire at all, just return an error on write operations
  167. #
  168. # Note: with all the kind of policies, Redis will return an error on write
  169. # operations, when there are not suitable keys for eviction.
  170. #
  171. # At the date of writing this commands are: set setnx setex append
  172. # incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
  173. # sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
  174. # zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
  175. # getset mset msetnx exec sort
  176. #
  177. # The default is:
  178. #
  179. # maxmemory-policy volatile-lru
  180. # LRU and minimal TTL algorithms are not precise algorithms but approximated
  181. # algorithms (in order to save memory), so you can select as well the sample
  182. # size to check. For instance for default Redis will check three keys and
  183. # pick the one that was used less recently, you can change the sample size
  184. # using the following configuration directive.
  185. #
  186. # maxmemory-samples 3
  187. ############################## APPEND ONLY MODE ###############################
  188. #
  189. # Note that you can have both the async dumps and the append only file if you
  190. # like (you have to comment the "save" statements above to disable the dumps).
  191. # Still if append only mode is enabled Redis will load the data from the
  192. # log file at startup ignoring the dump.rdb file.
  193. # 指定是否在每次更新操作后进行日志记录,Redis在默认情况下是异步的把数据写入磁盘,如果不开启,可能会在断电时导致一段时间内的数据丢失。
  194. # 因为redis本身同步数据文件是按上面save条件来同步的,所以有的数据会在一段时间内只存在于内存中。默认为no
  195. # IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append
  196. # log file in background when it gets too big.
  197. appendonly yes
  198. # 指定更新日志文件名,默认为appendonly.aof
  199. # appendfilename appendonly.aof
  200. # The fsync() call tells the Operating System to actually write data on disk
  201. # instead to wait for more data in the output buffer. Some OS will really flush
  202. # data on disk, some other OS will just try to do it ASAP.
  203. # 指定更新日志条件,共有3个可选值:
  204. # no:表示等操作系统进行数据缓存同步到磁盘(快)
  205. # always:表示每次更新操作后手动调用fsync()将数据写到磁盘(慢,安全)
  206. # everysec:表示每秒同步一次(折衷,默认值)
  207. appendfsync everysec
  208. # appendfsync no
  209. # When the AOF fsync policy is set to always or everysec, and a background
  210. # saving process (a background save or AOF log background rewriting) is
  211. # performing a lot of I/O against the disk, in some Linux configurations
  212. # Redis may block too long on the fsync() call. Note that there is no fix for
  213. # this currently, as even performing fsync in a different thread will block
  214. # our synchronous write(2) call.
  215. #
  216. # In order to mitigate this problem it's possible to use the following option
  217. # that will prevent fsync() from being called in the main process while a
  218. # BGSAVE or BGREWRITEAOF is in progress.
  219. #
  220. # This means that while another child is saving the durability of Redis is
  221. # the same as "appendfsync none", that in pratical terms means that it is
  222. # possible to lost up to 30 seconds of log in the worst scenario (with the
  223. # default Linux settings).
  224. #
  225. # If you have latency problems turn this to "yes". Otherwise leave it as
  226. # "no" that is the safest pick from the point of view of durability.
  227. no-appendfsync-on-rewrite no
  228. # Automatic rewrite of the append only file.
  229. # Redis is able to automatically rewrite the log file implicitly calling
  230. # BGREWRITEAOF when the AOF log size will growth by the specified percentage.
  231. #
  232. # This is how it works: Redis remembers the size of the AOF file after the
  233. # latest rewrite (or if no rewrite happened since the restart, the size of
  234. # the AOF at startup is used).
  235. #
  236. # This base size is compared to the current size. If the current size is
  237. # bigger than the specified percentage, the rewrite is triggered. Also
  238. # you need to specify a minimal size for the AOF file to be rewritten, this
  239. # is useful to avoid rewriting the AOF file even if the percentage increase
  240. # is reached but it is still pretty small.
  241. #
  242. # Specify a precentage of zero in order to disable the automatic AOF
  243. # rewrite feature.
  244. auto-aof-rewrite-percentage 100
  245. auto-aof-rewrite-min-size 64mb
  246. ################################## SLOW LOG ###################################
  247. # The Redis Slow Log is a system to log queries that exceeded a specified
  248. # execution time. The execution time does not include the I/O operations
  249. # like talking with the client, sending the reply and so forth,
  250. # but just the time needed to actually execute the command (this is the only
  251. # stage of command execution where the thread is blocked and can not serve
  252. # other requests in the meantime).
  253. #
  254. # You can configure the slow log with two parameters: one tells Redis
  255. # what is the execution time, in microseconds, to exceed in order for the
  256. # command to get logged, and the other parameter is the length of the
  257. # slow log. When a new command is logged the oldest one is removed from the
  258. # queue of logged commands.
  259. # The following time is expressed in microseconds, so 1000000 is equivalent
  260. # to one second. Note that a negative number disables the slow log, while
  261. # a value of zero forces the logging of every command.
  262. slowlog-log-slower-than 10000
  263. # There is no limit to this length. Just be aware that it will consume memory.
  264. # You can reclaim memory used by the slow log with SLOWLOG RESET.
  265. slowlog-max-len 1024
  266. ################################ VIRTUAL MEMORY ###############################
  267. ### WARNING! Virtual Memory is deprecated in Redis 2.4
  268. ### The use of Virtual Memory is strongly discouraged.
  269. ### WARNING! Virtual Memory is deprecated in Redis 2.4
  270. ### The use of Virtual Memory is strongly discouraged.
  271. # Virtual Memory allows Redis to work with datasets bigger than the actual
  272. # amount of RAM needed to hold the whole dataset in memory.
  273. # In order to do so very used keys are taken in memory while the other keys
  274. # are swapped into a swap file, similarly to what operating systems do
  275. # with memory pages.
  276. # 指定是否启用虚拟内存机制,默认值为no,
  277. # VM机制将数据分页存放,由Redis将访问量较少的页即冷数据swap到磁盘上,访问多的页面由磁盘自动换出到内存中
  278. # 把vm-enabled设置为yes,根据需要设置好接下来的三个VM参数,就可以启动VM了
  279. # vm-enabled no
  280. # vm-enabled yes
  281. # This is the path of the Redis swap file. As you can guess, swap files
  282. # can't be shared by different Redis instances, so make sure to use a swap
  283. # file for every redis process you are running. Redis will complain if the
  284. # swap file is already in use.
  285. #
  286. # Redis交换文件最好的存储是SSD(固态硬盘)
  287. # 虚拟内存文件路径,默认值为/tmp/redis.swap,不可多个Redis实例共享
  288. # *** WARNING *** if you are using a shared hosting the default of putting
  289. # the swap file under /tmp is not secure. Create a dir with access granted
  290. # only to Redis user and configure Redis to create the swap file there.
  291. # vm-swap-file /tmp/redis.swap
  292. # With vm-max-memory 0 the system will swap everything it can. Not a good
  293. # default, just specify the max amount of RAM you can in bytes, but it's
  294. # better to leave some margin. For instance specify an amount of RAM
  295. # that's more or less between 60 and 80% of your free RAM.
  296. # 将所有大于vm-max-memory的数据存入虚拟内存,无论vm-max-memory设置多少,所有索引数据都是内存存储的(Redis的索引数据就是keys)
  297. # 也就是说当vm-max-memory设置为0的时候,其实是所有value都存在于磁盘。默认值为0
  298. # vm-max-memory 0
  299. # Redis swap文件分成了很多的page,一个对象可以保存在多个page上面,但一个page上不能被多个对象共享,vm-page-size是要根据存储的数据大小来设定的。
  300. # 建议如果存储很多小对象,page大小最后设置为32或64bytes;如果存储很大的对象,则可以使用更大的page,如果不确定,就使用默认值
  301. # vm-page-size 32
  302. # 设置swap文件中的page数量由于页表(一种表示页面空闲或使用的bitmap)是存放在内存中的,在磁盘上每8个pages将消耗1byte的内存
  303. # swap空间总容量为 vm-page-size * vm-pages
  304. #
  305. # With the default of 32-bytes memory pages and 134217728 pages Redis will
  306. # use a 4 GB swap file, that will use 16 MB of RAM for the page table.
  307. #
  308. # It's better to use the smallest acceptable value for your application,
  309. # but the default is large in order to work in most conditions.
  310. # vm-pages 134217728
  311. # Max number of VM I/O threads running at the same time.
  312. # This threads are used to read/write data from/to swap file, since they
  313. # also encode and decode objects from disk to memory or the reverse, a bigger
  314. # number of threads can help with big objects even if they can't help with
  315. # I/O itself as the physical device may not be able to couple with many
  316. # reads/writes operations at the same time.
  317. # 设置访问swap文件的I/O线程数,最后不要超过机器的核数,如果设置为0,那么所有对swap文件的操作都是串行的,可能会造成比较长时间的延迟,默认值为4
  318. # vm-max-threads 4
  319. ############################### ADVANCED CONFIG ###############################
  320. # Hashes are encoded in a special way (much more memory efficient) when they
  321. # have at max a given numer of elements, and the biggest element does not
  322. # exceed a given threshold. You can configure this limits with the following
  323. # configuration directives.
  324. # 指定在超过一定的数量或者最大的元素超过某一临界值时,采用一种特殊的哈希算法
  325. # hash-max-zipmap-entries 512
  326. # hash-max-zipmap-value 64
  327. # Similarly to hashes, small lists are also encoded in a special way in order
  328. # to save a lot of space. The special representation is only used when
  329. # you are under the following limits:
  330. list-max-ziplist-entries 512
  331. list-max-ziplist-value 64
  332. # Sets have a special encoding in just one case: when a set is composed
  333. # of just strings that happens to be integers in radix 10 in the range
  334. # of 64 bit signed integers.
  335. # The following configuration setting sets the limit in the size of the
  336. # set in order to use this special memory saving encoding.
  337. set-max-intset-entries 512
  338. # Similarly to hashes and lists, sorted sets are also specially encoded in
  339. # order to save a lot of space. This encoding is only used when the length and
  340. # elements of a sorted set are below the following limits:
  341. zset-max-ziplist-entries 128
  342. zset-max-ziplist-value 64
  343. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
  344. # order to help rehashing the main Redis hash table (the one mapping top-level
  345. # keys to values). The hash table implementation redis uses (see dict.c)
  346. # performs a lazy rehashing: the more operation you run into an hash table
  347. # that is rhashing, the more rehashing "steps" are performed, so if the
  348. # server is idle the rehashing is never complete and some more memory is used
  349. # by the hash table.
  350. #
  351. # The default is to use this millisecond 10 times every second in order to
  352. # active rehashing the main dictionaries, freeing memory when possible.
  353. #
  354. # If unsure:
  355. # use "activerehashing no" if you have hard latency requirements and it is
  356. # not a good thing in your environment that Redis can reply form time to time
  357. # to queries with 2 milliseconds delay.
  358. # 指定是否激活重置哈希,默认为开启
  359. activerehashing yes
  360. ################################## INCLUDES ###################################
  361. # 指定包含其他的配置文件,可以在同一主机上多个Redis实例之间使用同一份配置文件,而同时各实例又拥有自己的特定配置文件
  362. # include /path/to/local.conf
  363. # include /path/to/other.conf