Redis默认配置文件redis.conf详解

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