首页 > 代码库 > redis的redis.conf文件详解
redis的redis.conf文件详解
是2.6.12版本的
1 redis.conf配置文件 2 3 # Redis configuration file example 4 5 # Note on units: when memory size is needed, it is possible to specifiy 6 # it in the usual form of 1k 5GB 4M and so forth: 7 # 8 # 1k => 1000 bytes 9 # 1kb => 1024 bytes 10 # 1m => 1000000 bytes 11 # 1mb => 1024*1024 bytes 12 # 1g => 1000000000 bytes 13 # 1gb => 1024*1024*1024 bytes 14 # 15 # units are case insensitive so 1GB 1Gb 1gB are all the same. 16 17 ################################## INCLUDES ################################### 18 19 # Include one or more other config files here. This is useful if you 20 # have a standard template that goes to all redis server but also need 21 # to customize a few per-server settings. Include files can include 22 # other files, so use this wisely. 23 # 24 # include /path/to/local.conf 25 # include /path/to/other.conf 26 指定包含其它的配置文件,可以在同一主机上多个Redis实例之间使用同一份配置文件,而同时各个实例又拥有自己的特定配置文件 27 28 ################################ GENERAL ##################################### 29 30 # By default Redis does not run as a daemon. Use ‘yes‘ if you need it. 31 # Note that Redis will write a pid file in /var/run/redis.pid when daemonized. 32 daemonize no 33 Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程 34 35 36 # When running daemonized, Redis writes a pid file in /var/run/redis.pid by 37 # default. You can specify a custom pid file location here. 38 pidfile /var/run/redis.pid 39 当Redis以守护进程方式运行时,Redis默认会把pid写入/var/run/redis.pid文件,可以通过pidfile指定 40 41 42 # Accept connections on the specified port, default is 6379. 43 # If port 0 is specified Redis will not listen on a TCP socket. 44 port 6379 45 指定Redis监听端口,默认端口为6379 46 47 48 # If you want you can bind a single interface, if the bind option is not 49 # specified all the interfaces will listen for incoming connections. 50 # 51 # bind 127.0.0.1 52 绑定的主机地址 53 54 55 # Specify the path for the unix socket that will be used to listen for 56 # incoming connections. There is no default, so Redis will not listen 57 # on a unix socket when not specified. 58 # 59 # unixsocket /tmp/redis.sock 60 # unixsocketperm 755 61 62 # Close the connection after a client is idle for N seconds (0 to disable) 63 timeout 0 64 当 客户端闲置多长时间后关闭连接,如果指定为0,表示关闭该功能 65 66 67 # Set server verbosity to ‘debug‘ 68 # it can be one of: 69 # debug (a lot of information, useful for development/testing) 70 # verbose (many rarely useful info, but not a mess like the debug level) 71 # notice (moderately verbose, what you want in production probably) 72 # warning (only very important / critical messages are logged) 73 loglevel verbose 74 指定日志记录级别,Redis总共支持四个级别:debug、verbose、notice、warning,默认为verbose 75 76 # Specify the log file name. Also ‘stdout‘ can be used to force 77 # Redis to log on the standard output. Note that if you use standard 78 # output for logging but daemonize, logs will be sent to /dev/null 79 logfile stdout 80 81 82 日志记录方式,默认为标准输出,如果配置Redis为守护进程方式运行,而这里又配置为日志记录方式为标准输出,则日志将会发送给/dev/null 83 # To enable logging to the system logger, just set ‘syslog-enabled‘ to yes, 84 # and optionally update the other syslog parameters to suit your needs. 85 # syslog-enabled no 86 87 # Specify the syslog identity. 88 # syslog-ident redis 89 90 # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7. 91 # syslog-facility local0 92 93 # Set the number of databases. The default database is DB 0, you can select 94 # a different one on a per-connection basis using SELECT <dbid> where 95 # dbid is a number between 0 and ‘databases‘-1 96 databases 16 97 98 99 设置数据库的数量,默认数据库为0,可以使用SELECT <dbid>命令在连接上指定数据库id100 ################################ SNAPSHOTTING #################################101 #102 # Save the DB on disk:103 #104 # save <seconds> <changes>105 #106 # Will save the DB if both the given number of seconds and the given107 # number of write operations against the DB occurred.108 #109 # In the example below the behaviour will be to save:110 # after 900 sec (15 min) if at least 1 key changed111 # after 300 sec (5 min) if at least 10 keys changed112 # after 60 sec if at least 10000 keys changed113 #114 # Note: you can disable saving at all commenting all the "save" lines.115 116 save 900 1117 save 300 10118 save 60 10000119 分别表示900秒(15分钟)内有1个更改,300秒(5分钟)内有10个更改以及60秒内有10000个更改。120 指定在多长时间内,有多少次更新操作,就将数据同步到数据文件,可以多个条件配合121 122 123 # Compress string objects using LZF when dump .rdb databases?124 # For default that‘s set to ‘yes‘ as it‘s almost always a win.125 # If you want to save some CPU in the saving child set it to ‘no‘ but126 # the dataset will likely be bigger if you have compressible values or keys.127 rdbcompression yes128 指定存储至本地数据库时是否压缩数据,默认为yes,Redis采用LZF压缩,如果为了节省CPU时间,可以关闭该选项,但会导致数据库文件变的巨大129 130 131 # The filename where to dump the DB132 dbfilename dump.rdb133 指定本地数据库文件名,默认值为dump.rdb134 135 136 # The working directory.137 #138 # The DB will be written inside this directory, with the filename specified139 # above using the ‘dbfilename‘ configuration directive.140 #141 # Also the Append Only File will be created inside this directory.142 #143 # Note that you must specify a directory here, not a file name.144 dir ./145 指定本地数据库存放目录146 147 148 149 ################################# REPLICATION #################################150 151 # Master-Slave replication(主从复制). Use slaveof to make a Redis instance a copy of152 # another Redis server. Note that the configuration is local to the slave153 # so for example it is possible to configure the slave to save the DB with a154 # different interval, or to listen to another port, and so on.155 #156 # slaveof <masterip> <masterport>157 slaveof <masterip> <masterport> 设置当本机为slav服务时,设置master服务的IP地址及端口,在Redis启动时,它会自动从master进行数据同步158 159 160 161 # If the master is password protected (using the "requirepass" configuration162 # directive below) it is possible to tell the slave to authenticate before163 # starting the replication synchronization process, otherwise the master will164 # refuse the slave request.165 #166 # masterauth <master-password>167 masterauth <master-password> 当master服务设置了密码保护时,slav服务连接master的密码168 169 170 # When a slave lost the connection with the master, or when the replication171 # is still in progress, the slave can act in two different ways:172 #173 # 1) if slave-serve-stale-data is set to ‘yes‘ (the default) the slave will174 # still reply to client requests, possibly with out of data data, or the175 # data set may just be empty if this is the first synchronization.176 #177 # 2) if slave-serve-stale data is set to ‘no‘ the slave will reply with178 # an error "SYNC with master in progress" to all the kind of commands179 # but to INFO and SLAVEOF.180 #181 slave-serve-stale-datayes182 183 184 185 # Slaves send PINGs to server in a predefined interval. It‘s possible to change186 # this interval with the repl_ping_slave_period option. The default value is 10187 # seconds.188 #189 # repl-ping-slave-period 10190 191 # The following option sets a timeout for both Bulk transfer I/O timeout and192 # master data or ping response timeout. The default value is 60 seconds.193 #194 # It is important to make sure that this value is greater than the value195 # specified for repl-ping-slave-period otherwise a timeout will be detected196 # every time there is low traffic between the master and the slave.197 #198 # repl-timeout 60199 200 ################################## SECURITY ###################################201 202 # Require clients to issue AUTH <PASSWORD> before processing any other203 # commands. This might be useful in environments in which you do not trust204 # others with access to the host running redis-server.205 #206 # This should stay commented out for backward compatibility and because most207 # people do not need auth (e.g. they run their own servers).208 #209 # Warning: since Redis is pretty fast an outside user can try up to210 # 150k passwords per second against a good box. This means that you should211 # use a very strong password otherwise it will be very easy to break.212 #213 # requirepass foobared214 requirepass foobared 设置Redis连接密码,如果配置了连接密码,客户端在连接Redis时需要通过AUTH <password>命令提供密码,默认关闭215 216 217 # Command renaming.218 #219 # It is possilbe to change the name of dangerous commands in a shared220 # environment. For instance the CONFIG command may be renamed into something221 # of hard to guess so that it will be still available for internal-use222 # tools but not available for general clients.223 #224 # Example:225 #226 # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52227 #228 # It is also possilbe to completely kill a command renaming it into229 # an empty string:230 #231 # rename-command CONFIG ""232 233 ################################### LIMITS ####################################234 235 # Set the max number of connected clients at the same time. By default there236 # is no limit, and it‘s up to the number of file descriptors the Redis process237 # is able to open. The special value ‘0‘ means no limits.238 # Once the limit is reached Redis will close all the new connections sending239 # an error ‘max number of clients reached‘.240 #241 # maxclients 128242 maxclients 128 设置同一时间最大客户端连接数,默认无限制,Redis可以同时打开的客户端连接数为Redis进程可以打开的最大文件描述符数,如果设置 maxclients 0,表示不作限制。当客户端连接数到达限制时,Redis会关闭新的连接并向客户端返回max number of clients reached错误信息243 244 245 246 # Don‘t use more memory than the specified amount of bytes.247 # When the memory limit is reached Redis will try to remove keys with an248 # EXPIRE set. It will try to start freeing keys that are going to expire249 # in little time and preserve keys with a longer time to live.250 # Redis will also try to remove objects from free lists if possible.251 #252 # If all this fails, Redis will start to reply with errors to commands253 # that will use more memory, like SET, LPUSH, and so on, and will continue254 # to reply to most read-only commands like GET.255 #256 # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a257 # ‘state‘ server or cache, not as a real DB. When Redis is used as a real258 # database the memory usage will grow over the weeks, it will be obvious if259 # it is going to use too much memory in the long run, and you‘ll have the time260 # to upgrade. With maxmemory after the limit is reached you‘ll start to get261 # errors for write operations, and this may even lead to DB inconsistency.262 #263 # maxmemory <bytes>264 maxmemory <bytes>指定Redis最大内存限制,Redis在启动时会把数据加载到内存中,达到最大内存后,Redis会先尝试清除已到期或即将到期的Key,当此方法处理 后,仍然到达最大内存设置,将无法再进行写入操作,但仍然可以进行读取操作。Redis新的vm机制,会把Key存放内存,Value会存放在swap区265 266 267 268 # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory269 # is reached? You can select among five behavior:270 #271 # volatile-lru -> remove the key with an expire set using an LRU algorithm272 # allkeys-lru -> remove any key accordingly to the LRU algorithm273 # volatile-random -> remove a random key with an expire set274 # allkeys->random -> remove a random key, any key275 # volatile-ttl -> remove the key with the nearest expire time (minor TTL)276 # noeviction -> don‘t expire at all, just return an error on write operations277 #278 # Note: with all the kind of policies, Redis will return an error on write279 # operations, when there are not suitable keys for eviction.280 #281 # At the date of writing this commands are: set setnx setex append282 # incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd283 # sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby284 # zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby285 # getset mset msetnx exec sort286 #287 # The default is:288 #289 # maxmemory-policy volatile-lru290 291 # LRU and minimal TTL algorithms are not precise algorithms but approximated292 # algorithms (in order to save memory), so you can select as well the sample293 # size to check. For instance for default Redis will check three keys and294 # pick the one that was used less recently, you can change the sample size295 # using the following configuration directive.296 #297 # maxmemory-samples 3298 299 ############################## APPEND ONLY MODE ###############################300 301 # By default Redis asynchronously dumps the dataset on disk. If you can live302 # with the idea that the latest records will be lost if something like a crash303 # happens this is the preferred way to run Redis. If instead you care a lot304 # about your data and don‘t want to that a single record can get lost you should305 # enable the append only mode: when this mode is enabled Redis will append306 # every write operation received in the file appendonly.aof. This file will307 # be read on startup in order to rebuild the full dataset in memory.308 #309 # Note that you can have both the async dumps and the append only file if you310 # like (you have to comment the "save" statements above to disable the dumps).311 # Still if append only mode is enabled Redis will load the data from the312 # log file at startup ignoring the dump.rdb file.313 #314 # IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append315 # log file in background when it gets too big.316 317 appendonly no318 appendonly no指定是否在每次更新操作后进行日志记录,Redis在默认情况下是异步的把数据写入磁盘,如果不开启,可能会在断电时导致一段时间内的数据丢失。因为 redis本身同步数据文件是按上面save条件来同步的,所以有的数据会在一段时间内只存在于内存中。默认为no319 320 321 322 # The name of the append only file (default: "appendonly.aof")323 # appendfilename appendonly.aof324 appendfilename appendonly.aof指定更新日志文件名,默认为appendonly.aof325 # The fsync() call tells the Operating System to actually write data on disk326 # instead to wait for more data in the output buffer. Some OS will really flush327 # data on disk, some other OS will just try to do it ASAP.328 #329 # Redis supports three different modes:330 #331 # no: don‘t fsync, just let the OS flush the data when it wants. Faster.332 # always: fsync after every write to the append only log . Slow, Safest.333 # everysec: fsync only if one second passed since the last fsync. Compromise.334 #335 # The default is "everysec" that‘s usually the right compromise between336 # speed and data safety. It‘s up to you to understand if you can relax this to337 # "no" that will will let the operating system flush the output buffer when338 # it wants, for better performances (but if you can live with the idea of339 # some data loss consider the default persistence mode that‘s snapshotting),340 # or on the contrary, use "always" that‘s very slow but a bit safer than341 # everysec.342 #343 # If unsure, use "everysec".344 345 # appendfsync always346 appendfsync everysec347 # appendfsync no348 指定更新日志条件,共有3个可选值:349 no:表示等操作系统进行数据缓存同步到磁盘(快)350 always:表示每次更新操作后手动调用fsync()将数据写到磁盘(慢,安全)351 everysec:表示每秒同步一次(折衷,默认值)352 353 354 355 # When the AOF fsync policy is set to always or everysec, and a background356 # saving process (a background save or AOF log background rewriting) is357 # performing a lot of I/O against the disk, in some Linux configurations358 # Redis may block too long on the fsync() call. Note that there is no fix for359 # this currently, as even performing fsync in a different thread will block360 # our synchronous write(2) call.361 #362 # In order to mitigate this problem it‘s possible to use the following option363 # that will prevent fsync() from being called in the main process while a364 # BGSAVE or BGREWRITEAOF is in progress.365 #366 # This means that while another child is saving the durability of Redis is367 # the same as "appendfsync none", that in pratical terms means that it is368 # possible to lost up to 30 seconds of log in the worst scenario (with the369 # default Linux settings).370 #371 # If you have latency problems turn this to "yes". Otherwise leave it as372 # "no" that is the safest pick from the point of view of durability.373 no-appendfsync-on-rewrite no374 375 # Automatic rewrite of the append only file.376 # Redis is able to automatically rewrite the log file implicitly calling377 # BGREWRITEAOF when the AOF log size will growth by the specified percentage.378 #379 # This is how it works: Redis remembers the size of the AOF file after the380 # latest rewrite (or if no rewrite happened since the restart, the size of381 # the AOF at startup is used).382 #383 # This base size is compared to the current size. If the current size is384 # bigger than the specified percentage, the rewrite is triggered. Also385 # you need to specify a minimal size for the AOF file to be rewritten, this386 # is useful to avoid rewriting the AOF file even if the percentage increase387 # is reached but it is still pretty small.388 #389 # Specify a precentage of zero in order to disable the automatic AOF390 # rewrite feature.391 392 auto-aof-rewrite-percentage 100393 auto-aof-rewrite-min-size 64mb394 395 ################################## SLOW LOG ###################################396 397 # The Redis Slow Log is a system to log queries that exceeded a specified398 # execution time. The execution time does not include the I/O operations399 # like talking with the client, sending the reply and so forth,400 # but just the time needed to actually execute the command (this is the only401 # stage of command execution where the thread is blocked and can not serve402 # other requests in the meantime).403 #404 # You can configure the slow log with two parameters: one tells Redis405 # what is the execution time, in microseconds, to exceed in order for the406 # command to get logged, and the other parameter is the length of the407 # slow log. When a new command is logged the oldest one is removed from the408 # queue of logged commands.409 410 # The following time is expressed in microseconds, so 1000000 is equivalent411 # to one second. Note that a negative number disables the slow log, while412 # a value of zero forces the logging of every command.413 slowlog-log-slower-than 10000414 415 # There is no limit to this length. Just be aware that it will consume memory.416 # You can reclaim memory used by the slow log with SLOWLOG RESET.417 slowlog-max-len 1024418 419 ################################ VIRTUAL MEMORY ###############################420 421 ### WARNING! Virtual Memory is deprecated in Redis 2.4422 ### The use of Virtual Memory is strongly discouraged.423 424 ### WARNING! Virtual Memory is deprecated in Redis 2.4425 ### The use of Virtual Memory is strongly discouraged.426 427 # Virtual Memory allows Redis to work with datasets bigger than the actual428 # amount of RAM needed to hold the whole dataset in memory.429 # In order to do so very used keys are taken in memory while the other keys430 # are swapped into a swap file, similarly to what operating systems do431 # with memory pages.432 #433 # To enable VM just set ‘vm-enabled‘ to yes, and set the following three434 # VM parameters accordingly to your needs.435 436 vm-enabled no437 指定是否启用虚拟内存机制,默认值为no,简单的介绍一下,VM机制将数据分页存放,由Redis将访问量较少的页即冷数据swap到磁盘上,访问多的页面由磁盘自动换出到内存中(在后面的文章我会仔细分析Redis的VM机制)438 439 440 441 442 # vm-enabled yes443 444 # This is the path of the Redis swap file. As you can guess, swap files445 # can‘t be shared by different Redis instances, so make sure to use a swap446 # file for every redis process you are running. Redis will complain if the447 # swap file is already in use.448 #449 # The best kind of storage for the Redis swap file (that‘s accessed at random)450 # is a Solid State Disk (SSD).451 #452 # *** WARNING *** if you are using a shared hosting the default of putting453 # the swap file under /tmp is not secure. Create a dir with access granted454 # only to Redis user and configure Redis to create the swap file there.455 vm-swap-file /tmp/redis.swap456 虚拟内存文件路径,默认值为/tmp/redis.swap,不可多个Redis实例共享457 458 459 460 # vm-max-memory configures the VM to use at max the specified amount of461 # RAM. Everything that deos not fit will be swapped on disk *if* possible, that462 # is, if there is still enough contiguous space in the swap file.463 #464 # With vm-max-memory 0 the system will swap everything it can. Not a good465 # default, just specify the max amount of RAM you can in bytes, but it‘s466 # better to leave some margin. For instance specify an amount of RAM467 # that‘s more or less between 60 and 80% of your free RAM.468 vm-max-memory 0469 将所有大于vm-max-memory的数据存入虚拟内存,无论vm-max-memory设置多小,所有索引数据都是内存存储的(Redis的索引数据 就是keys),也就是说,当vm-max-memory设置为0的时候,其实是所有value都存在于磁盘。默认值为0470 471 472 473 # Redis swap files is split into pages. An object can be saved using multiple474 # contiguous pages, but pages can‘t be shared between different objects.475 # So if your page is too big, small objects swapped out on disk will waste476 # a lot of space. If you page is too small, there is less space in the swap477 # file (assuming you configured the same number of total swap file pages).478 #479 # If you use a lot of small objects, use a page size of 64 or 32 bytes.480 # If you use a lot of big objects, use a bigger page size.481 # If unsure, use the default :)482 vm-page-size 32483 Redis swap文件分成了很多的page,一个对象可以保存在多个page上面,但一个page上不能被多个对象共享,vm-page-size是要根据存储的 数据大小来设定的,作者建议如果存储很多小对象,page大小最好设置为32或者64bytes;如果存储很大大对象,则可以使用更大的page,如果不 确定,就使用默认值484 485 486 487 # Number of total memory pages in the swap file.488 # Given that the page table (a bitmap of free/used pages) is taken in memory,489 # every 8 pages on disk will consume 1 byte of RAM.490 #491 # The total swap size is vm-page-size * vm-pages492 #493 # With the default of 32-bytes memory pages and 134217728 pages Redis will494 # use a 4 GB swap file, that will use 16 MB of RAM for the page table.495 #496 # It‘s better to use the smallest acceptable value for your application,497 # but the default is large in order to work in most conditions.498 vm-pages 134217728499 设置swap文件中的page数量,由于页表(一种表示页面空闲或使用的bitmap)是在放在内存中的,,在磁盘上每8个pages将消耗1byte的内存。500 501 502 503 # Max number of VM I/O threads running at the same time.504 # This threads are used to read/write data from/to swap file, since they505 # also encode and decode objects from disk to memory or the reverse, a bigger506 # number of threads can help with big objects even if they can‘t help with507 # I/O itself as the physical device may not be able to couple with many508 # reads/writes operations at the same time.509 #510 # The special value of 0 turn off threaded I/O and enables the blocking511 # Virtual Memory implementation.512 vm-max-threads 4513 设置访问swap文件的线程数,最好不要超过机器的核数,如果设置为0,那么所有对swap文件的操作都是串行的,可能会造成比较长时间的延迟。默认值为4514 515 516 517 ############################### ADVANCED CONFIG ###############################518 519 # Hashes are encoded in a special way (much more memory efficient) when they520 # have at max a given numer of elements, and the biggest element does not521 # exceed a given threshold. You can configure this limits with the following522 # configuration directives.523 hash-max-zipmap-entries 512524 hash-max-zipmap-value 64525 指定在超过一定的数量或者最大的元素超过某一临界值时,采用一种特殊的哈希算法526 527 528 529 # Similarly to hashes, small lists are also encoded in a special way in order530 # to save a lot of space. The special representation is only used when531 # you are under the following limits:532 list-max-ziplist-entries 512533 list-max-ziplist-value 64534 535 # Sets have a special encoding in just one case: when a set is composed536 # of just strings that happens to be integers in radix 10 in the range537 # of 64 bit signed integers.538 # The following configuration setting sets the limit in the size of the539 # set in order to use this special memory saving encoding.540 set-max-intset-entries 512541 542 # Similarly to hashes and lists, sorted sets are also specially encoded in543 # order to save a lot of space. This encoding is only used when the length and544 # elements of a sorted set are below the following limits:545 zset-max-ziplist-entries 128546 zset-max-ziplist-value 64547 548 # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in549 # order to help rehashing the main Redis hash table (the one mapping top-level550 # keys to values). The hash table implementation redis uses (see dict.c)551 # performs a lazy rehashing: the more operation you run into an hash table552 # that is rhashing, the more rehashing "steps" are performed, so if the553 # server is idle the rehashing is never complete and some more memory is used554 # by the hash table.555 #556 # The default is to use this millisecond 10 times every second in order to557 # active rehashing the main dictionaries, freeing memory when possible.558 #559 # If unsure:560 # use "activerehashing no" if you have hard latency requirements and it is561 # not a good thing in your environment that Redis can reply form time to time562 # to queries with 2 milliseconds delay.563 #564 # use "activerehashing yes" if you don‘t have such hard requirements but565 # want to free memory asap when possible.566 activerehashing yes567
redis的redis.conf文件详解
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。