1. redis配置文件redis.conf参数说明 (2013-01-09 21:20:40)转载▼
  2. 标签: redis配置 redis.conf 配置说明 杂谈 分类: nosql
  3. # By default Redis does not run as a daemon. Use 'yes' if you need it.
  4. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
  5. #Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程
  6. daemonize no
  7.  
  8. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
  9. # default. You can specify a custom pid file location here.
  10. #当 Redis 以守护进程的方式运行的时候,Redis 默认会把 pid 文件放在/var/run/redis.pid
  11. #可配置到其他地址,当运行多个 redis 服务时,需要指定不同的 pid 文件和端口
  12. pidfile /var/run/redis.pid
  13.  
  14. # Accept connections on the specified port, default is 6379.
  15. # If port 0 is specified Redis will not listen on a TCP socket.
  16. #端口
  17. port 6379
  18.  
  19. # If you want you can bind a single interface, if the bind option is not
  20. # specified all the interfaces will listen for incoming connections.
  21. #指定Redis可接收请求的IP地址,不设置将处理所有请求,建议生产环境中设置
  22. # bind 127.0.0.1
  23.  
  24. # Close the connection after a client is idle for N seconds (0 to disable)
  25. #客户端连接的超时时间,单位为秒,超时后会关闭连接
  26. timeout 0
  27.  
  28. # Set server verbosity to 'debug'
  29. # it can be one of:
  30. # debug (a lot of information, useful for development/testing)
  31. # verbose (many rarely useful info, but not a mess like the debug level)
  32. # notice (moderately verbose, what you want in production probably)
  33. # warning (only very important / critical messages are logged)
  34. #日志记录等级,4个可选值
  35. loglevel notice
  36.  
  37. # Specify the log file name. Also 'stdout' can be used to force
  38. # Redis to log on the standard output. Note that if you use standard
  39. # output for logging but daemonize, logs will be sent to /dev/null
  40. #配置 log 文件地址,默认打印在命令行终端的窗口上,也可设为/dev/null屏蔽日志、
  41. logfile stdout
  42.  
  43. # Set the number of databases. The default database is DB 0, you can select
  44. # a different one on a per-connection basis using SELECT where
  45. # dbid is a number between 0 and 'databases'-1
  46. #设置数据库的个数,可以使用 SELECT 命令来切换数据库。
  47. databases 16
  48.  
  49. #
  50. # Save the DB on disk:
  51. #
  52. # save
  53. #
  54. # Will save the DB if both the given number of seconds and the given
  55. # number of write operations against the DB occurred.
  56. #
  57. # In the example below the behaviour will be to save:
  58. # after 900 sec (15 min) if at least 1 key changed
  59. # after 300 sec (5 min) if at least 10 keys changed
  60. # after 60 sec if at least 10000 keys changed
  61. #
  62. # Note: you can disable saving at all commenting all the "save" lines.
  63. #设置 Redis 进行数据库镜像的频率。保存数据到disk的策略
  64. #900秒之内有1个keys发生变化时
  65. #30秒之内有10个keys发生变化时
  66. #60秒之内有10000个keys发生变化时
  67. save 900 1
  68. save 300 10
  69. save 60 10000
  70.  
  71. # Compress string objects using LZF when dump .rdb databases?
  72. # For default that's set to 'yes' as it's almost always a win.
  73. # If you want to save some CPU in the saving child set it to 'no' but
  74. # the dataset will likely be bigger if you have compressible values or keys.
  75. #在进行镜像备份时,是否进行压缩
  76. rdbcompression yes
  77.  
  78. # The filename where to dump the DB
  79. #镜像备份文件的文件名
  80. dbfilename dump.rdb
  81.  
  82. # The working directory.
  83. #
  84. # The DB will be written inside this directory, with the filename specified
  85. # above using the 'dbfilename' configuration directive.
  86. #
  87. # Also the Append Only File will be created inside this directory.
  88. #
  89. # Note that you must specify a directory here, not a file name.
  90. #数据库镜像备份的文件放置的路径
  91. #路径跟文件名分开配置是因为 Redis 备份时,先会将当前数据库的状态写入到一个临时文件
  92. #等备份完成时,再把该临时文件替换为上面所指定的文件
  93. #而临时文件和上面所配置的备份文件都会放在这个指定的路径当中
  94. #默认值为 ./
  95. dir /var/lib/redis/
  96.  
  97. # Master-Slave replication. Use slaveof to make a Redis instance a copy of
  98. # another Redis server. Note that the configuration is local to the slave
  99. # so for example it is possible to configure the slave to save the DB with a
  100. # different interval, or to listen to another port, and so on.
  101. #设置该数据库为其他数据库的从数据库
  102. #slaveof <masterip> <masterport> 当本机为从服务时,设置主服务的IP及端口
  103. # slaveof
  104.  
  105. # If the master is password protected (using the "requirepass" configuration
  106. # directive below) it is possible to tell the slave to authenticate before
  107. # starting the replication synchronization process, otherwise the master will
  108. # refuse the slave request.
  109. #指定与主数据库连接时需要的密码验证
  110. #masterauth <master-password> 当本机为从服务时,设置主服务的连接密码
  111. # masterauth
  112.  
  113. # When a slave lost the connection with the master, or when the replication
  114. # is still in progress, the slave can act in two different ways:
  115. #
  116. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
  117. # still reply to client requests, possibly with out of data data, or the
  118. # data set may just be empty if this is the first synchronization.
  119. #
  120. # 2) if slave-serve-stale data is set to 'no' the slave will reply with
  121. # an error "SYNC with master in progress" to all the kind of commands
  122. # but to INFO and SLAVEOF.
  123. #当slave丢失与master的连接时,或slave仍然在于master进行数据同步时(未与master保持一致)
  124. #slave可有两种方式来响应客户端请求:
  125. #1)如果 slave-serve-stale-data 设置成 'yes'(默认),slave仍会响应客户端请求,此时可能会有问题
  126. #2)如果 slave-serve-stale-data 设置成 'no',slave会返回"SYNC with master in progress"错误信息,但 INFO 和SLAVEOF命令除外。
  127. slave-serve-stale-data yes
  128.  
  129. # Require clients to issue AUTH before processing any other
  130. # commands. This might be useful in environments in which you do not trust
  131. # others with access to the host running redis-server.
  132. #
  133. # This should stay commented out for backward compatibility and because most
  134. # people do not need auth (e.g. they run their own servers).
  135. #
  136. # Warning: since Redis is pretty fast an outside user can try up to
  137. # 150k passwords per second against a good box. This means that you should
  138. # use a very strong password otherwise it will be very easy to break.
  139. #设置客户端连接后进行任何其他指定前需要使用的密码
  140. #redis速度相当快,一个外部用户在一秒钟进行150K次密码尝试,需指定强大的密码来防止暴力破解
  141. # requirepass foobared
  142.  
  143. # Set the max number of connected clients at the same time. By default there
  144. # is no limit, and it's up to the number of file descriptors the Redis process
  145. # is able to open. The special value '0' means no limits.
  146. # Once the limit is reached Redis will close all the new connections sending
  147. # an error 'max number of clients reached'.
  148. #限制同时连接的客户数量。
  149. #当连接数超过这个值时,redis 将不再接收其他连接请求,客户端尝试连接时将收到 error 信息
  150. # maxclients 128
  151.  
  152. # Don't use more memory than the specified amount of bytes.
  153. # When the memory limit is reached Redis will try to remove keys
  154. # accordingly to the eviction policy selected (see maxmemmory-policy).
  155. #
  156. # If Redis can't remove keys according to the policy, or if the policy is
  157. # set to 'noeviction', Redis will start to reply with errors to commands
  158. # that would use more memory, like SET, LPUSH, and so on, and will continue
  159. # to reply to read-only commands like GET.
  160. #
  161. # This option is usually useful when using Redis as an LRU cache, or to set
  162. # an hard memory limit for an instance (using the 'noeviction' policy).
  163. #
  164. # WARNING: If you have slaves attached to an instance with maxmemory on,
  165. # the size of the output buffers needed to feed the slaves are subtracted
  166. # from the used memory count, so that network problems / resyncs will
  167. # not trigger a loop where keys are evicted, and in turn the output
  168. # buffer of slaves is full with DELs of keys evicted triggering the deletion
  169. # of more keys, and so forth until the database is completely emptied.
  170. #
  171. # In short... if you have slaves attached it is suggested that you set a lower
  172. # limit for maxmemory so that there is some free RAM on the system for slave
  173. # output buffers (but this is not needed if the policy is 'noeviction').
  174. #设置redis能够使用的最大内存。
  175. #达到最大内存设置后,Redis会先尝试清除已到期或即将到期的Key(设置过expire信息的key)
  176. #在删除时,按照过期时间进行删除,最早将要被过期的key将最先被删除
  177. #如果已到期或即将到期的key删光,仍进行set操作,那么将返回错误
  178. #此时redis将不再接收写请求,只接收get请求。
  179. #maxmemory的设置比较适合于把redis当作于类似memcached 的缓存来使用
  180. # maxmemory <bytes>
  181.  
  182. # By default Redis asynchronously dumps the dataset on disk. If you can live
  183. # with the idea that the latest records will be lost if something like a crash
  184. # happens this is the preferred way to run Redis. If instead you care a lot
  185. # about your data and don't want to that a single record can get lost you should
  186. # enable the append only mode: when this mode is enabled Redis will append
  187. # every write operation received in the file appendonly.aof. This file will
  188. # be read on startup in order to rebuild the full dataset in memory.
  189. #
  190. # Note that you can have both the async dumps and the append only file if you
  191. # like (you have to comment the "save" statements above to disable the dumps).
  192. # Still if append only mode is enabled Redis will load the data from the
  193. # log file at startup ignoring the dump.rdb file.
  194. #
  195. # IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append
  196. # log file in background when it gets too big.
  197. #redis 默认每次更新操作后会在后台异步的把数据库镜像备份到磁盘,但该备份非常耗时,且备份不宜太频繁
  198. #redis 同步数据文件是按上面save条件来同步的
  199. #如果发生诸如拉闸限电、拔插头等状况,那么将造成比较大范围的数据丢失
  200. #所以redis提供了另外一种更加高效的数据库备份及灾难恢复方式
  201. #开启append only 模式后,redis 将每一次写操作请求都追加到appendonly.aof 文件中
  202. #redis重新启动时,会从该文件恢复出之前的状态。
  203. #但可能会造成 appendonly.aof 文件过大,所以redis支持BGREWRITEAOF 指令,对appendonly.aof重新整理
  204. appendonly no
  205.  
  206. # The name of the append only file (default: "appendonly.aof")
  207. ##更新日志文件名,默认值为appendonly.aof
  208. # appendfilename appendonly.aof
  209.  
  210. # The fsync() call tells the Operating System to actually write data on disk
  211. # instead to wait for more data in the output buffer. Some OS will really flush
  212. # data on disk, some other OS will just try to do it ASAP.
  213. #
  214. # Redis supports three different modes:
  215. #
  216. # no: don't fsync, just let the OS flush the data when it wants. Faster.
  217. # always: fsync after every write to the append only log . Slow, Safest.
  218. # everysec: fsync only if one second passed since the last fsync. Compromise.
  219. #
  220. # The default is "everysec" that's usually the right compromise between
  221. # speed and data safety. It's up to you to understand if you can relax this to
  222. # "no" that will will let the operating system flush the output buffer when
  223. # it wants, for better performances (but if you can live with the idea of
  224. # some data loss consider the default persistence mode that's snapshotting),
  225. # or on the contrary, use "always" that's very slow but a bit safer than
  226. # everysec.
  227. #
  228. # If unsure, use "everysec".
  229. #设置对 appendonly.aof 文件进行同步的频率
  230. #always 表示每次有写操作都进行同步,everysec 表示对写操作进行累积,每秒同步一次。
  231. #no表示等操作系统进行数据缓存同步到磁盘,都进行同步,everysec 表示对写操作进行累积,每秒同步一次
  232. # appendfsync always
  233. appendfsync everysec
  234. # appendfsync no
  235.  
  236. # Virtual Memory allows Redis to work with datasets bigger than the actual
  237. # amount of RAM needed to hold the whole dataset in memory.
  238. # In order to do so very used keys are taken in memory while the other keys
  239. # are swapped into a swap file, similarly to what operating systems do
  240. # with memory pages.
  241. #
  242. # To enable VM just set 'vm-enabled' to yes, and set the following three
  243. # VM parameters accordingly to your needs.
  244. #是否开启虚拟内存支持。
  245. #redis 是一个内存数据库,当内存满时,无法接收新的写请求,所以在redis2.0后,提供了虚拟内存的支持
  246. #但需要注意的,redis 所有的key都会放在内存中,在内存不够时,只把value 值放入交换区
  247. #虽使用虚拟内存,但性能基本不受影响,需要注意的是要把vm-max-memory设置到足够来放下所有的key
  248. vm-enabled no
  249. # vm-enabled yes
  250.  
  251. # This is the path of the Redis swap file. As you can guess, swap files
  252. # can't be shared by different Redis instances, so make sure to use a swap
  253. # file for every redis process you are running. Redis will complain if the
  254. # swap file is already in use.
  255. #
  256. # The best kind of storage for the Redis swap file (that's accessed at random)
  257. # is a Solid State Disk (SSD).
  258. #
  259. # *** WARNING *** if you are using a shared hosting the default of putting
  260. # the swap file under /tmp is not secure. Create a dir with access granted
  261. # only to Redis user and configure Redis to create the swap file there.
  262. #设置虚拟内存的交换文件路径,不可多个Redis实例共享
  263. vm-swap-file /tmp/redis.swap
  264.  
  265. # vm-max-memory configures the VM to use at max the specified amount of
  266. # RAM. Everything that deos not fit will be swapped on disk *if* possible, that
  267. # is, if there is still enough contiguous space in the swap file.
  268. #
  269. # With vm-max-memory 0 the system will swap everything it can. Not a good
  270. # default, just specify the max amount of RAM you can in bytes, but it's
  271. # better to leave some margin. For instance specify an amount of RAM
  272. # that's more or less between 60 and 80% of your free RAM.
  273. #设置开启虚拟内存后,redis将使用的最大物理内存大小。
  274. #默认为0,redis将把他所有能放到交换文件的都放到交换文件中,以尽量少的使用物理内存
  275. #即当vm-max-memory设置为0的时候,其实是所有value都存在于磁盘
  276. #在生产环境下,需要根据实际情况设置该值,最好不要使用默认的 0
  277. vm-max-memory 0
  278.  
  279. # Redis swap files is split into pages. An object can be saved using multiple
  280. # contiguous pages, but pages can't be shared between different objects.
  281. # So if your page is too big, small objects swapped out on disk will waste
  282. # a lot of space. If you page is too small, there is less space in the swap
  283. # file (assuming you configured the same number of total swap file pages).
  284. #
  285. # If you use a lot of small objects, use a page size of 64 or 32 bytes.
  286. # If you use a lot of big objects, use a bigger page size.
  287. # If unsure, use the default :)
  288. #设置虚拟内存的页大小
  289. 如果 value 值比较大,如要在 value 中放置博客、新闻之类的所有文章内容,就设大一点
  290. vm-page-size 32
  291.  
  292. # Number of total memory pages in the swap file.
  293. # Given that the page table (a bitmap of free/used pages) is taken in memory,
  294. # every 8 pages on disk will consume 1 byte of RAM.
  295. #
  296. # The total swap size is vm-page-size * vm-pages
  297. #
  298. # With the default of 32-bytes memory pages and 134217728 pages Redis will
  299. # use a 4 GB swap file, that will use 16 MB of RAM for the page table.
  300. #
  301. # It's better to use the smallest acceptable value for your application,
  302. # but the default is large in order to work in most conditions.
  303. #设置交换文件的总的 page 数量
  304. #注意page table信息是放在物理内存中,每8个page 就会占据RAM中的 1 个 byte
  305. #总的虚拟内存大小 = vm-page-size * vm-pages
  306. vm-pages 134217728
  307.  
  308. # Max number of VM I/O threads running at the same time.
  309. # This threads are used to read/write data from/to swap file, since they
  310. # also encode and decode objects from disk to memory or the reverse, a bigger
  311. # number of threads can help with big objects even if they can't help with
  312. # I/O itself as the physical device may not be able to couple with many
  313. # reads/writes operations at the same time.
  314. #
  315. # The special value of 0 turn off threaded I/O and enables the blocking
  316. # Virtual Memory implementation.
  317. #设置 VM IO 同时使用的线程数量。
  318. vm-max-threads 4
  319.  
  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. #redis 2.0后引入了 hash 数据结构。
  325. #hash 中包含超过指定元素个数并且最大的元素当没有超过临界时,hash 将以zipmap来存储
  326. #zipmap又称为 small hash,可大大减少内存的使用
  327. hash-max-zipmap-entries 512
  328. hash-max-zipmap-value 64
  329.  
  330. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
  331. # order to help rehashing the main Redis hash table (the one mapping top-level
  332. # keys to values). The hash table implementation redis uses (see dict.c)
  333. # performs a lazy rehashing: the more operation you run into an hash table
  334. # that is rhashing, the more rehashing "steps" are performed, so if the
  335. # server is idle the rehashing is never complete and some more memory is used
  336. # by the hash table.
  337. #
  338. # The default is to use this millisecond 10 times every second in order to
  339. # active rehashing the main dictionaries, freeing memory when possible.
  340. #
  341. # If unsure:
  342. # use "activerehashing no" if you have hard latency requirements and it is
  343. # not a good thing in your environment that Redis can reply form time to time
  344. # to queries with 2 milliseconds delay.
  345. #
  346. # use "activerehashing yes" if you don't have such hard requirements but
  347. # want to free memory asap when possible.
  348. #是否重置Hash表
  349. #设置成yes后redis将每100毫秒使用1毫秒CPU时间来对redis的hash表重新hash,可降低内存的使用
  350. #当使用场景有较为严格的实时性需求,不能接受Redis时不时的对请求有2毫秒的延迟的话,把这项配置为no。
  351. #如果没有这么严格的实时性要求,可以设置为 yes,以便能够尽可能快的释放内存
  352. activerehashing yes
  353.  
  354. Redis官方文档对VM的使用提出了一些建议:
  355. key很小而value很大时,使用VM的效果会比较好.因为这样节约的内存比较大
  356. key不小时,可以考虑使用一些非常方法将很大的key变成很大的value,如可将key,value组合成一个新的value
  357. 最好使用linux ext3 等对稀疏文件支持比较好的文件系统保存你的swap文件
  358. vm-max-threads参数可设置访问swap文件的线程数,最好不要超过机器的核数;设置为0则所有对swap文件的操作都是串行的,可能会造成比较长时间的延迟,但是对数据完整性有很好的保证
  359. redis数据存储
  360. redis的存储分为内存存储、磁盘存储和log文件三部分,配置文件中有三个参数对其进行配置。
  361. save seconds updatessave配置,指出在多长时间内,有多少次更新操作,就将数据同步到数据文件。可多个条件配合,默认配置了三个条件。
  362. appendonly yes/no appendonly配置,指出是否在每次更新操作后进行日志记录,如果不开启,可能会在断电时导致一段时间内的数据丢失。因为redis本身同步数据文件是按上面的save条件来同步的,所以有的数据会在一段时间内只存在于内存中。
  363. appendfsync no/always/everysec appendfsync配置,no表示等操作系统进行数据缓存同步到磁盘,always表示每次更新操作后手动调用fsync()将数据写到磁盘,everysec表示每秒同步一次。

redis配置文件redis.conf参数说明的更多相关文章

  1. Redis 配置文件 Redis.conf 参数说明

    Redis 配置文件 Redis.conf 参数说明 参数名 参数说明 参数实例 daemonize 是否以后台守护进程运行,默认为 no, 取值 yes, no   daemonize no     ...

  2. Redis 配置文件 redis.conf 项目详解

    Redis.conf 配置文件详解 # [Redis](http://yijiebuyi.com/category/redis.html) 配置文件 # 当配置中需要配置内存大小时,可以使用 1k, ...

  3. Redis配置文件redis.conf详解

    一.Redis配置文件redis.conf详解 # Note on units: when memory size is needed, it is possible to specifiy # it ...

  4. Redis配置文件 redis.conf 解读(一)

    # Redis configuration file example# redis配置文件模板# Note on units: when memory size is needed, it is po ...

  5. redis配置文件redis.conf翻译、解释以及常用注意事项(持续更新中...)

    # Redis configuration file example. #Redis 配置文件的示例 #如何利用配置文件启动Redis # Note that in order to read the ...

  6. [转]redis配置文件redis.conf的详细说明

    转自: http://www.sufeinet.com/thread-8047-1-1.html # Redis 配置文件 # 当配置中需要配置内存大小时,可以使用 1k, 5GB, 4M 等类似的格 ...

  7. [redis] redis配置文件redis.conf的详细说明

    # Redis 配置文件 # 当配置中需要配置内存大小时,可以使用 1k, 5GB, 4M 等类似的格式,其转换方式如下(不区分大小写) # # 1k => bytes # 1kb => ...

  8. redis配置文件redis.conf的参数说明

    打开redis.conf文件: # By default Redis does not run as a daemon. Use 'yes' if you need it. # Note that R ...

  9. redis配置文件redis.conf中文版

    转账自:http://www.jb51.net/article/50605.htm # Redis示例配置文件 # 注意单位问题:当需要设置内存大小的时候,可以使用类似1k.5GB.4M这样的常见格式 ...

随机推荐

  1. ecshop登录

    邮箱登录 a.找到function login(){} ,增加一个邮箱判断is_mail()  , b.如果通过,增读取出username , c.再通过默认的login功能 1.需要修改文件incl ...

  2. testNg vs junit 4.X @Test

    http://www.ibm.com/developerworks/cn/java/j-cq08296/ 一个简单的测试用例 初看起来,JUnit 4 和 TestNG 中实现的测试非常相似.为了更好 ...

  3. CSV文件的读取 导出

    CSV文件是 逗号分隔值文件 内容基本是这么存的... 姓名,年龄,性别/r/n王有才,,男/r/n王二妞,,女 一行值内用逗号 , 分开  行与行之间用  /r/n  分隔 说白了,他其实是一个字符 ...

  4. 并发下常见的加锁及锁的PHP具体实现代码(转)

    在最近的项目中有这样的场景 1.生成文件的时候,由于多用户都有权限进行生成,防止并发下,导致生成的结果出现错误,需要对生成的过程进行加锁,只容许一个用户在一个时间内进行操作,这个时候就需要用到锁了,将 ...

  5. Idea修改js和jsp不用重启

  6. 清除SQL server2008 记住的用户名和密码

    删除以下文件即可: C:\Users\%username%\AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell\SqlStud ...

  7. MySQL5.7 Replication主从复制配置教程

    最近配置mysql5.7主从复制的时候碰到了些问题,老老实实按老版本的步骤配置会有错误,后来自己查看了官方文档,才解决了问题,在这里总结一下5.7的配置步骤, 大体步骤跟老版本的还是一样的,只是有一些 ...

  8. Mysql分表和分区的区别、分库分表介绍与区别

    分表和分区的区别: 一,什么是mysql分表,分区 什么是分表,从表面意思上看呢,就是把一张表分成N多个小表,具体请看:mysql分表的3种方法 什么是分区,分区呢就是把一张表的数据分成N多个区块,这 ...

  9. SQL 查询总结

    参考资料: SELECT 查询语句格式与简单查询 SQL中distinct的用法 SQL 查询总结

  10. 【8-16】Android学习笔记01

    Android目录树 Activity 生命周期 创建一个 Activity 在 android 中创建一个 Activity 要编写一个继承自 android.app.Activity的 Java ...