当前位置:   article > 正文

一、redis 初识-3.redis配置_err unsupported config parameter: activedefrag

err unsupported config parameter: activedefrag

本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/38

Redis 的配置文件位于 Redis 安装目录下,文件名为 redis.conf(Windows 名为 redis.windows.conf)。

可以通过 CONFIG 命令查看或设置配置项。

Redis CONFIG 命令格式:

redis 127.0.0.1:6379> CONFIG GET CONFIG_SETTING_NAME

举例:

  1. 127.0.0.1:6379> config get port
  2. 1) "port"
  3. 2) "6379"

获取redis的所有配置

  1. 127.0.0.1:6379> config get "*"
  2. 1) "dbfilename"
  3. 2) "dump.rdb"
  4. 3) "requirepass"
  5. 4) ""
  6. 5) "masterauth"
  7. 6) ""
  8. 7) "cluster-announce-ip"
  9. 8) ""
  10. 9) "unixsocket"
  11. 10) ""
  12. 11) "logfile"
  13. 12) ""
  14. 13) "pidfile"
  15. 14) ""
  16. 15) "slave-announce-ip"
  17. 16) ""
  18. 17) "replica-announce-ip"
  19. 18) ""
  20. 19) "maxmemory"
  21. 20) "0"
  22. 21) "proto-max-bulk-len"
  23. 22) "536870912"
  24. 23) "client-query-buffer-limit"
  25. 24) "1073741824"
  26. 25) "maxmemory-samples"
  27. 26) "5"
  28. 27) "lfu-log-factor"
  29. 28) "10"
  30. 29) "lfu-decay-time"
  31. 30) "1"
  32. 31) "timeout"
  33. 32) "0"
  34. 33) "active-defrag-threshold-lower"
  35. 34) "10"
  36. 35) "active-defrag-threshold-upper"
  37. 36) "100"
  38. 37) "active-defrag-ignore-bytes"
  39. 38) "104857600"
  40. 39) "active-defrag-cycle-min"
  41. 40) "5"
  42. 41) "active-defrag-cycle-max"
  43. 42) "75"
  44. 43) "active-defrag-max-scan-fields"
  45. 44) "1000"
  46. 45) "auto-aof-rewrite-percentage"
  47. 46) "100"
  48. 47) "auto-aof-rewrite-min-size"
  49. 48) "67108864"
  50. 49) "hash-max-ziplist-entries"
  51. 50) "512"
  52. 51) "hash-max-ziplist-value"
  53. 52) "64"
  54. 53) "stream-node-max-bytes"
  55. 54) "4096"
  56. 55) "stream-node-max-entries"
  57. 56) "100"
  58. 57) "list-max-ziplist-size"
  59. 58) "-2"
  60. 59) "list-compress-depth"
  61. 60) "0"
  62. 61) "set-max-intset-entries"
  63. 62) "512"
  64. 63) "zset-max-ziplist-entries"
  65. 64) "128"
  66. 65) "zset-max-ziplist-value"
  67. 66) "64"
  68. 67) "hll-sparse-max-bytes"
  69. 68) "3000"
  70. 69) "lua-time-limit"
  71. 70) "5000"
  72. 71) "slowlog-log-slower-than"
  73. 72) "10000"
  74. 73) "latency-monitor-threshold"
  75. 74) "0"
  76. 75) "slowlog-max-len"
  77. 76) "128"
  78. 77) "port"
  79. 78) "6379"
  80. 79) "cluster-announce-port"
  81. 80) "0"
  82. 81) "cluster-announce-bus-port"
  83. 82) "0"
  84. 83) "tcp-backlog"
  85. 84) "511"
  86. 85) "databases"
  87. 86) "16"
  88. 87) "repl-ping-slave-period"
  89. 88) "10"
  90. 89) "repl-ping-replica-period"
  91. 90) "10"
  92. 91) "repl-timeout"
  93. 92) "60"
  94. 93) "repl-backlog-size"
  95. 94) "1048576"
  96. 95) "repl-backlog-ttl"
  97. 96) "3600"
  98. 97) "maxclients"
  99. 98) "10000"
  100. 99) "watchdog-period"
  101. 100) "0"
  102. 101) "slave-priority"
  103. 102) "100"
  104. 103) "replica-priority"
  105. 104) "100"
  106. 105) "slave-announce-port"
  107. 106) "0"
  108. 107) "replica-announce-port"
  109. 108) "0"
  110. 109) "min-slaves-to-write"
  111. 110) "0"
  112. 111) "min-replicas-to-write"
  113. 112) "0"
  114. 113) "min-slaves-max-lag"
  115. 114) "10"
  116. 115) "min-replicas-max-lag"
  117. 116) "10"
  118. 117) "hz"
  119. 118) "10"
  120. 119) "cluster-node-timeout"
  121. 120) "15000"
  122. 121) "cluster-migration-barrier"
  123. 122) "1"
  124. 123) "cluster-slave-validity-factor"
  125. 124) "10"
  126. 125) "cluster-replica-validity-factor"
  127. 126) "10"
  128. 127) "repl-diskless-sync-delay"
  129. 128) "5"
  130. 129) "tcp-keepalive"
  131. 130) "300"
  132. 131) "cluster-require-full-coverage"
  133. 132) "yes"
  134. 133) "cluster-slave-no-failover"
  135. 134) "no"
  136. 135) "cluster-replica-no-failover"
  137. 136) "no"
  138. 137) "no-appendfsync-on-rewrite"
  139. 138) "no"
  140. 139) "slave-serve-stale-data"
  141. 140) "yes"
  142. 141) "replica-serve-stale-data"
  143. 142) "yes"
  144. 143) "slave-read-only"
  145. 144) "yes"
  146. 145) "replica-read-only"
  147. 146) "yes"
  148. 147) "slave-ignore-maxmemory"
  149. 148) "yes"
  150. 149) "replica-ignore-maxmemory"
  151. 150) "yes"
  152. 151) "stop-writes-on-bgsave-error"
  153. 152) "yes"
  154. 153) "daemonize"
  155. 154) "no"
  156. 155) "rdbcompression"
  157. 156) "yes"
  158. 157) "rdbchecksum"
  159. 158) "yes"
  160. 159) "activerehashing"
  161. 160) "yes"
  162. 161) "activedefrag"
  163. 162) "no"
  164. 163) "protected-mode"
  165. 164) "yes"
  166. 165) "repl-disable-tcp-nodelay"
  167. 166) "no"
  168. 167) "repl-diskless-sync"
  169. 168) "no"
  170. 169) "aof-rewrite-incremental-fsync"
  171. 170) "yes"
  172. 171) "rdb-save-incremental-fsync"
  173. 172) "yes"
  174. 173) "aof-load-truncated"
  175. 174) "yes"
  176. 175) "aof-use-rdb-preamble"
  177. 176) "yes"
  178. 177) "lazyfree-lazy-eviction"
  179. 178) "no"
  180. 179) "lazyfree-lazy-expire"
  181. 180) "no"
  182. 181) "lazyfree-lazy-server-del"
  183. 182) "no"
  184. 183) "slave-lazy-flush"
  185. 184) "no"
  186. 185) "replica-lazy-flush"
  187. 186) "no"
  188. 187) "dynamic-hz"
  189. 188) "yes"
  190. 189) "maxmemory-policy"
  191. 190) "noeviction"
  192. 191) "loglevel"
  193. 192) "notice"
  194. 193) "supervised"
  195. 194) "no"
  196. 195) "appendfsync"
  197. 196) "everysec"
  198. 197) "appendonly"
  199. 198) "no"
  200. 199) "dir"
  201. 200) "C:\\MyProgram\\Redis-x64-5.0.10"
  202. 201) "save"
  203. 202) "3600 1 300 100 60 10000"
  204. 203) "client-output-buffer-limit"
  205. 204) "normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60"
  206. 205) "unixsocketperm"
  207. 206) "0"
  208. 207) "slaveof"
  209. 208) ""
  210. 209) "notify-keyspace-events"
  211. 210) ""
  212. 211) "bind"
  213. 212) ""

redis配置调整

有两种方式:

  1. 方式一:修改redis.conf文件
  2. 方式二:通过config set 命令

CONFIG SET 格式

redis 127.0.0.1:6379> CONFIG SET CONFIG_SETTING_NAME NEW_CONFIG_VALUE

举例

  1. 127.0.0.1:6379> config set appendonly yes
  2. OK

注意:并不是所有的参数都支持config set 命令,否则会报错:(error) ERR Unsupported CONFIG parameter: bind

为了让redis配置永久生效且有效,我们推荐修改redis.conf文件来调整

redis.conf文件中的参数说明:

  1. ##redis配置详解
  2. # Redis configuration file example.
  3. #
  4. # Note that in order to read the configuration file, Redis must be
  5. # started with the file path as first argument:
  6. #
  7. # ./redis-server /path/to/redis.conf
  8. # Note on units: when memory size is needed, it is possible to specify
  9. # it in the usual form of 1k 5GB 4M and so forth:
  10. #
  11. # 1k => 1000 bytes
  12. # 1kb => 1024 bytes
  13. # 1m => 1000000 bytes
  14. # 1mb => 1024*1024 bytes
  15. # 1g => 1000000000 bytes
  16. # 1gb => 1024*1024*1024 bytes
  17. #
  18. # units are case insensitive so 1GB 1Gb 1gB are all the same.
  19. ################################## INCLUDES ###################################
  20. ################################## 包含 ###################################
  21. # Include one or more other config files here. This is useful if you
  22. # have a standard template that goes to all Redis servers but also need
  23. # to customize a few per-server settings. Include files can include
  24. # other files, so use this wisely.
  25. #
  26. # Notice option "include" won't be rewritten by command "CONFIG REWRITE"
  27. # from admin or Redis Sentinel. Since Redis always uses the last processed
  28. # line as value of a configuration directive, you'd better put includes
  29. # at the beginning of this file to avoid overwriting config change at runtime.
  30. #
  31. # If instead you are interested in using includes to override configuration
  32. # options, it is better to use include as the last line.
  33. #
  34. # 假如说你有一个可用于所有的 redis server 的标准配置模板,
  35. # 但针对某些 server 又需要一些个性化的设置,
  36. # 你可以使用 include 来包含一些其他的配置文件,这对你来说是非常有用的。
  37. #
  38. # 但是要注意哦,include 是不能被 config rewrite 命令改写的
  39. # 由于 redis 总是以最后的加工线作为一个配置指令值,所以你最好是把 include 放在这个文件的最前面,
  40. # 以避免在运行时覆盖配置的改变,相反,你就把它放在后面
  41. # include /path/to/local.conf
  42. # include /path/to/other.conf
  43. ################################ GENERAL #####################################
  44. ################################ 常用 #####################################
  45. # By default Redis does not run as a daemon. Use 'yes' if you need it.
  46. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
  47. # 默认情况下 redis 不是作为守护进程运行的,如果你想让它在后台运行,你就把它改成 yes。
  48. # 当redis作为守护进程运行的时候,它会写一个 pid 到 /var/run/redis.pid 文件里面。
  49. daemonize yes
  50. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
  51. # default. You can specify a custom pid file location here.
  52. # 当 Redis 以守护进程的方式运行的时候,Redis 默认会把 pid 文件放在/var/run/redis.pid
  53. # 可配置到其他地址,当运行多个 redis 服务时,需要指定不同的 pid 文件和端口
  54. # 指定存储Redis进程号的文件路径
  55. pidfile /var/run/redis.pid
  56. # Accept connections on the specified port, default is 6379.
  57. # If port 0 is specified Redis will not listen on a TCP socket.
  58. # 端口,默认端口是6379,生产环境中建议更改端口号,安全性更高
  59. # 如果你设为 0 ,redis 将不在 socket 上监听任何客户端连接。
  60. port 9966
  61. # TCP listen() backlog.
  62. #
  63. # In high requests-per-second environments you need an high backlog in order
  64. # to avoid slow clients connections issues. Note that the Linux kernel
  65. # will silently truncate it to the value of /proc/sys/net/core/somaxconn so
  66. # make sure to raise both the value of somaxconn and tcp_max_syn_backlog
  67. # in order to get the desired effect.
  68. # TCP 监听的最大容纳数量
  69. # 此参数确定了TCP连接中已完成队列(完成三次握手之后)的长度,
  70. # 当系统并发量大并且客户端速度缓慢的时候,你需要把这个值调高以避免客户端连接缓慢的问题。
  71. # Linux 内核会一声不响的把这个值缩小成 /proc/sys/net/core/somaxconn 对应的值,默认是511,而Linux的默认参数值是128。
  72. # 所以可以将这二个参数一起参考设定,你以便达到你的预期。
  73. #
  74. tcp-backlog 511
  75. # By default Redis listens for connections from all the network interfaces
  76. # available on the server. It is possible to listen to just one or multiple
  77. # interfaces using the "bind" configuration directive, followed by one or
  78. # more IP addresses.
  79. #
  80. # Examples:
  81. #
  82. # bind 192.168.1.100 10.0.0.1
  83. # 有时候为了安全起见,redis一般都是监听127.0.0.1 但是有时候又有同网段能连接的需求,当然可以绑定0.0.0.0 用iptables来控制访问权限,或者设置redis访问密码来保证数据安全
  84. # 不设置将处理所有请求,建议生产环境中设置,有个误区:bind是用来限制外网IP访问的,其实不是,限制外网ip访问可以通过iptables;如:-A INPUT -s 10.10.1.0/24 -p tcp -m state --state NEW -m tcp --dport 9966 -j ACCEPT ;
  85. # 实际上,bind ip 绑定的是redis所在服务器网卡的ip,当然127.0.0.1也是可以的
  86. #如果绑定一个外网ip,就会报错:Creating Server TCP listening socket xxx.xxx.xxx.xxx:9966: bind: Cannot assign requested address
  87. # bind 127.0.0.1
  88. bind 127.0.0.1 10.10.1.3
  89. # 假设绑定是以上ip,使用 netstat -anp|grep 9966 会发现,这两个ip被bind,其中10.10.1.3是服务器网卡的ip
  90. # tcp 0 0 10.10.1.3:9966 0.0.0.0:* LISTEN 11188/redis-server
  91. # tcp 0 0 127.0.0.1:9966 0.0.0.0:* LISTEN 11188/redis-server
  92. # Specify the path for the Unix socket that will be used to listen for
  93. # incoming connections. There is no default, so Redis will not listen
  94. # on a unix socket when not specified.
  95. #
  96. # unixsocket /tmp/redis.sock
  97. # unixsocketperm 700
  98. # Close the connection after a client is idle for N seconds (0 to disable)
  99. # 客户端和Redis服务端的连接超时时间,默认是0,表示永不超时。
  100. timeout 0
  101. # TCP keepalive.
  102. #
  103. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
  104. # of communication. This is useful for two reasons:
  105. #
  106. # 1) Detect dead peers.
  107. # 2) Take the connection alive from the point of view of network
  108. # equipment in the middle.
  109. #
  110. # On Linux, the specified value (in seconds) is the period used to send ACKs.
  111. # Note that to close the connection the double of the time is needed.
  112. # On other kernels the period depends on the kernel configuration.
  113. #
  114. # A reasonable value for this option is 60 seconds.
  115. # tcp 心跳包。
  116. #
  117. # 如果设置为非零,则在与客户端缺乏通讯的时候使用 SO_KEEPALIVE 发送 tcp acks 给客户端。
  118. # 这个之所有有用,主要由两个原因:
  119. #
  120. # 1) 防止死的 peers
  121. # 2) Take the connection alive from the point of view of network
  122. # equipment in the middle.
  123. #
  124. # 推荐一个合理的值就是60秒
  125. tcp-keepalive 0
  126. # Specify the server verbosity level.
  127. # This can be one of:
  128. # debug (a lot of information, useful for development/testing)
  129. # verbose (many rarely useful info, but not a mess like the debug level)
  130. # notice (moderately verbose, what you want in production probably)
  131. # warning (only very important / critical messages are logged)
  132. # 日志记录等级,4个可选值debug,verbose,notice,warning
  133. # 可以是下面的这些值:
  134. # debug (适用于开发或测试阶段)
  135. # verbose (many rarely useful info, but not a mess like the debug level)
  136. # notice (适用于生产环境)
  137. # warning (仅仅一些重要的消息被记录)
  138. loglevel notice
  139. # Specify the log file name. Also the empty string can be used to force
  140. # Redis to log on the standard output. Note that if you use standard
  141. # output for logging but daemonize, logs will be sent to /dev/null
  142. #配置 log 文件地址,默认打印在命令行终端的窗口上,也可设为/dev/null屏蔽日志、
  143. logfile "/data/logs/redis/redis.log"
  144. # To enable logging to the system logger, just set 'syslog-enabled' to yes,
  145. # and optionally update the other syslog parameters to suit your needs.
  146. # 要想把日志记录到系统日志,就把它改成 yes,
  147. # 也可以可选择性的更新其他的syslog 参数以达到你的要求
  148. # syslog-enabled no
  149. # Specify the syslog identity.
  150. # 设置 syslog 的 identity。
  151. # syslog-ident redis
  152. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
  153. # syslog-facility local0
  154. # Set the number of databases. The default database is DB 0, you can select
  155. # a different one on a per-connection basis using SELECT <dbid> where
  156. # dbid is a number between 0 and 'databases'-1
  157. # 可用的数据库数,默认值为16,默认数据库为0,数据库范围在0-(database-1)之间
  158. databases 16
  159. ################################ SNAPSHOTTING ################################
  160. ################################ 快照 ################################
  161. #
  162. # Save the DB on disk:
  163. #
  164. # save <seconds> <changes>
  165. #
  166. # Will save the DB if both the given number of seconds and the given
  167. # number of write operations against the DB occurred.
  168. #
  169. # In the example below the behaviour will be to save:
  170. # after 900 sec (15 min) if at least 1 key changed
  171. # after 300 sec (5 min) if at least 10 keys changed
  172. # after 60 sec if at least 10000 keys changed
  173. #
  174. # Note: you can disable saving completely by commenting out all "save" lines.
  175. #
  176. # It is also possible to remove all the previously configured save
  177. # points by adding a save directive with a single empty string argument
  178. # like in the following example:
  179. #
  180. # save ""
  181. # 在 900 秒内最少有 1 个 key 被改动,或者 300 秒内最少有 10 个 key 被改动,又或者 60 秒内最少有 1000 个 key 被改动,以上三个条件随便满足一个,就触发一次保存操作。
  182. # if(在60秒之内有10000个keys发生变化时){
  183. # 进行镜像备份
  184. # }else if(在300秒之内有10个keys发生了变化){
  185. # 进行镜像备份
  186. # }else if(在900秒之内有1个keys发生了变化){
  187. # 进行镜像备份
  188. # }
  189. save 900 1
  190. save 300 10
  191. save 60 10000
  192. # By default Redis will stop accepting writes if RDB snapshots are enabled
  193. # (at least one save point) and the latest background save failed.
  194. # This will make the user aware (in a hard way) that data is not persisting
  195. # on disk properly, otherwise chances are that no one will notice and some
  196. #:/ disaster will happen.
  197. #
  198. # If the background saving process will start working again Redis will
  199. # automatically allow writes again.
  200. #
  201. # However if you have setup your proper monitoring of the Redis server
  202. # and persistence, you may want to disable this feature so that Redis will
  203. # continue to work as usual even if there are problems with disk,
  204. # permissions, and so forth.
  205. # 默认情况下,如果 redis 最后一次的后台保存失败,redis 将停止接受写操作,
  206. # 这样以一种强硬的方式让用户知道数据不能正确的持久化到磁盘,
  207. # 否则就会没人注意到灾难的发生。
  208. #
  209. # 如果后台保存进程重新启动工作了,redis 也将自动的允许写操作。
  210. #
  211. # 然而你要是安装了靠谱的监控,你可能不希望 redis 这样做,那你就改成 no 好
  212. stop-writes-on-bgsave-error yes
  213. # Compress string objects using LZF when dump .rdb databases?
  214. # For default that's set to 'yes' as it's almost always a win.
  215. # If you want to save some CPU in the saving child set it to 'no' but
  216. # the dataset will likely be bigger if you have compressible values or keys.
  217. # 在进行备份时,是否进行压缩
  218. # 是否在 dump .rdb 数据库的时候使用 LZF 压缩字符串
  219. # 默认都设为 yes
  220. # 如果你希望保存子进程节省点 cpu ,你就设置它为 no ,
  221. # 不过这个数据集可能就会比较大
  222. rdbcompression yes
  223. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.
  224. # This makes the format more resistant to corruption but there is a performance
  225. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it
  226. # for maximum performances.
  227. #
  228. # RDB files created with checksum disabled have a checksum of zero that will
  229. # tell the loading code to skip the check.
  230. # 读取和写入的时候是否支持CRC64校验,默认是开启的
  231. rdbchecksum yes
  232. # The filename where to dump the DB
  233. # 备份文件的文件名
  234. dbfilename dump.rdb
  235. # The working directory.
  236. #
  237. # The DB will be written inside this directory, with the filename specified
  238. # above using the 'dbfilename' configuration directive.
  239. #
  240. # The Append Only File will also be created inside this directory.
  241. #
  242. # Note that you must specify a directory here, not a file name.
  243. # 数据库备份的文件放置的路径
  244. # 路径跟文件名分开配置是因为 Redis 备份时,先会将当前数据库的状态写入到一个临时文件
  245. # 等备份完成时,再把该临时文件替换为上面所指定的文件
  246. # 而临时文件和上面所配置的备份文件都会放在这个指定的路径当中
  247. # 默认值为 ./
  248. dir /data/data/redis/
  249. ################################# REPLICATION #################################
  250. ################################# 主从复制 #################################
  251. # Master-Slave replication. Use slaveof to make a Redis instance a copy of
  252. # another Redis server. A few things to understand ASAP about Redis replication.
  253. #
  254. # 1) Redis replication is asynchronous, but you can configure a master to
  255. # stop accepting writes if it appears to be not connected with at least
  256. # a given number of slaves.
  257. # 2) Redis slaves are able to perform a partial resynchronization with the
  258. # master if the replication link is lost for a relatively small amount of
  259. # time. You may want to configure the replication backlog size (see the next
  260. # sections of this file) with a sensible value depending on your needs.
  261. # 3) Replication is automatic and does not need user intervention. After a
  262. # network partition slaves automatically try to reconnect to masters
  263. # and resynchronize with them.
  264. #
  265. # 设置该数据库为其他数据库的从数据库
  266. # slaveof <masterip> <masterport> 当本机为从服务时,设置主服务的IP及端口
  267. # slaveof <masterip> <masterport>
  268. # If the master is password protected (using the "requirepass" configuration
  269. # directive below) it is possible to tell the slave to authenticate before
  270. # starting the replication synchronization process, otherwise the master will
  271. # refuse the slave request.
  272. #
  273. # 指定与主数据库连接时需要的密码验证
  274. # masterauth <master-password> 当本机为从服务时,设置访问master服务器的密码
  275. # masterauth <master-password>
  276. # When a slave loses its connection with the master, or when the replication
  277. # is still in progress, the slave can act in two different ways:
  278. #
  279. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
  280. # still reply to client requests, possibly with out of date data, or the
  281. # data set may just be empty if this is the first synchronization.
  282. #
  283. # 2) if slave-serve-stale-data is set to 'no' the slave will reply with
  284. # an error "SYNC with master in progress" to all the kind of commands
  285. # but to INFO and SLAVEOF.
  286. #
  287. # 当slave服务器和master服务器失去连接后,或者当数据正在复制传输的时候,如果此参数值设置“yes”,slave服务器可以继续接受客户端的请求,否则,会返回给请求的客户端如下信息“SYNC with master in progress”,除了INFO,SLAVEOF这两个命令
  288. slave-serve-stale-data yes
  289. # You can configure a slave instance to accept writes or not. Writing against
  290. # a slave instance may be useful to store some ephemeral data (because data
  291. # written on a slave will be easily deleted after resync with the master) but
  292. # may also cause problems if clients are writing to it because of a
  293. # misconfiguration.
  294. #
  295. # Since Redis 2.6 by default slaves are read-only.
  296. #
  297. # Note: read only slaves are not designed to be exposed to untrusted clients
  298. # on the internet. It's just a protection layer against misuse of the instance.
  299. # Still a read only slave exports by default all the administrative commands
  300. # such as CONFIG, DEBUG, and so forth. To a limited extent you can improve
  301. # security of read only slaves using 'rename-command' to shadow all the
  302. # administrative / dangerous commands.
  303. # 是否允许slave服务器节点只提供读服务
  304. slave-read-only yes
  305. # Replication SYNC strategy: disk or socket.
  306. #
  307. # -------------------------------------------------------
  308. # WARNING: DISKLESS REPLICATION IS EXPERIMENTAL CURRENTLY
  309. # -------------------------------------------------------
  310. #
  311. # New slaves and reconnecting slaves that are not able to continue the replication
  312. # process just receiving differences, need to do what is called a "full
  313. # synchronization". An RDB file is transmitted from the master to the slaves.
  314. # The transmission can happen in two different ways:
  315. #
  316. # 1) Disk-backed: The Redis master creates a new process that writes the RDB
  317. # file on disk. Later the file is transferred by the parent
  318. # process to the slaves incrementally.
  319. # 2) Diskless: The Redis master creates a new process that directly writes the
  320. # RDB file to slave sockets, without touching the disk at all.
  321. #
  322. # With disk-backed replication, while the RDB file is generated, more slaves
  323. # can be queued and served with the RDB file as soon as the current child producing
  324. # the RDB file finishes its work. With diskless replication instead once
  325. # the transfer starts, new slaves arriving will be queued and a new transfer
  326. # will start when the current one terminates.
  327. #
  328. # When diskless replication is used, the master waits a configurable amount of
  329. # time (in seconds) before starting the transfer in the hope that multiple slaves
  330. # will arrive and the transfer can be parallelized.
  331. #
  332. # With slow disks and fast (large bandwidth) networks, diskless replication
  333. # works better.
  334. repl-diskless-sync no
  335. # When diskless replication is enabled, it is possible to configure the delay
  336. # the server waits in order to spawn the child that transfers the RDB via socket
  337. # to the slaves.
  338. #
  339. # This is important since once the transfer starts, it is not possible to serve
  340. # new slaves arriving, that will be queued for the next RDB transfer, so the server
  341. # waits a delay in order to let more slaves arrive.
  342. #
  343. # The delay is specified in seconds, and by default is 5 seconds. To disable
  344. # it entirely just set it to 0 seconds and the transfer will start ASAP.
  345. repl-diskless-sync-delay 5
  346. # Slaves send PINGs to server in a predefined interval. It's possible to change
  347. # this interval with the repl_ping_slave_period option. The default value is 10
  348. # seconds.
  349. #
  350. # Slaves 在一个预定义的时间间隔内发送 ping 命令到 server 。
  351. # 你可以改变这个时间间隔。默认为 10 秒。
  352. # repl-ping-slave-period 10
  353. # The following option sets the replication timeout for:
  354. #
  355. # 1) Bulk transfer I/O during SYNC, from the point of view of slave.
  356. # 2) Master timeout from the point of view of slaves (data, pings).
  357. # 3) Slave timeout from the point of view of masters (REPLCONF ACK pings).
  358. #
  359. # It is important to make sure that this value is greater than the value
  360. # specified for repl-ping-slave-period otherwise a timeout will be detected
  361. # every time there is low traffic between the master and the slave.
  362. #
  363. # 设置主从复制过期时间
  364. # 这个值一定要比 repl-ping-slave-period 大
  365. # repl-timeout 60
  366. # Disable TCP_NODELAY on the slave socket after SYNC?
  367. #
  368. # If you select "yes" Redis will use a smaller number of TCP packets and
  369. # less bandwidth to send data to slaves. But this can add a delay for
  370. # the data to appear on the slave side, up to 40 milliseconds with
  371. # Linux kernels using a default configuration.
  372. #
  373. # If you select "no" the delay for data to appear on the slave side will
  374. # be reduced but more bandwidth will be used for replication.
  375. #
  376. # By default we optimize for low latency, but in very high traffic conditions
  377. # or when the master and slaves are many hops away, turning this to "yes" may
  378. # be a good idea.
  379. # 指定向slave同步数据时,是否禁用socket的NO_DELAY选 项。若配置为“yes”,则禁用NO_DELAY,则TCP协议栈会合并小包统一发送,这样可以减少主从节点间的包数量并节省带宽,但会增加数据同步到 slave的时间。若配置为“no”,表明启用NO_DELAY,则TCP协议栈不会延迟小包的发送时机,这样数据同步的延时会减少,但需要更大的带宽。 通常情况下,应该配置为no以降低同步延时,但在主从节点间网络负载已经很高的情况下,可以配置为yes。
  380. repl-disable-tcp-nodelay no
  381. # Set the replication backlog size. The backlog is a buffer that accumulates
  382. # slave data when slaves are disconnected for some time, so that when a slave
  383. # wants to reconnect again, often a full resync is not needed, but a partial
  384. # resync is enough, just passing the portion of data the slave missed while
  385. # disconnected.
  386. #
  387. # The bigger the replication backlog, the longer the time the slave can be
  388. # disconnected and later be able to perform a partial resynchronization.
  389. #
  390. # The backlog is only allocated once there is at least a slave connected.
  391. #
  392. # 设置主从复制容量大小。这个 backlog 是一个用来在 slaves 被断开连接时
  393. # 存放 slave 数据的 buffer,所以当一个 slave 想要重新连接,通常不希望全部重新同步,
  394. # 只是部分同步就够了,仅仅传递 slave 在断开连接时丢失的这部分数据。
  395. #
  396. # The biggest the replication backlog, the longer the time the slave can be
  397. # disconnected and later be able to perform a partial resynchronization.
  398. # 这个值越大,salve 可以断开连接的时间就越长。
  399. # repl-backlog-size 1mb
  400. # After a master has no longer connected slaves for some time, the backlog
  401. # will be freed. The following option configures the amount of seconds that
  402. # need to elapse, starting from the time the last slave disconnected, for
  403. # the backlog buffer to be freed.
  404. #
  405. # A value of 0 means to never release the backlog.
  406. #
  407. # 在某些时候,master 不再连接 slaves,backlog 将被释放。
  408. # 如果设置为 0 ,意味着绝不释放 backlog 。
  409. # repl-backlog-ttl 3600
  410. # The slave priority is an integer number published by Redis in the INFO output.
  411. # It is used by Redis Sentinel in order to select a slave to promote into a
  412. # master if the master is no longer working correctly.
  413. #
  414. # A slave with a low priority number is considered better for promotion, so
  415. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will
  416. # pick the one with priority 10, that is the lowest.
  417. #
  418. # However a special priority of 0 marks the slave as not able to perform the
  419. # role of master, so a slave with priority of 0 will never be selected by
  420. # Redis Sentinel for promotion.
  421. #
  422. # By default the priority is 100.
  423. # 指定slave的优先级。在不只1个slave存在的部署环境下,当master宕机时,Redis
  424. # Sentinel会将priority值最小的slave提升为master。
  425. # 这个值越小,就越会被优先选中,需要注意的是,
  426. # 若该配置项为0,则对应的slave永远不会自动提升为master。
  427. slave-priority 100
  428. # It is possible for a master to stop accepting writes if there are less than
  429. # N slaves connected, having a lag less or equal than M seconds.
  430. #
  431. # The N slaves need to be in "online" state.
  432. #
  433. # The lag in seconds, that must be <= the specified value, is calculated from
  434. # the last ping received from the slave, that is usually sent every second.
  435. #
  436. # This option does not GUARANTEE that N replicas will accept the write, but
  437. # will limit the window of exposure for lost writes in case not enough slaves
  438. # are available, to the specified number of seconds
  439. #
  440. # For example to require at least 3 slaves with a lag <= 10 seconds use:
  441. #
  442. # min-slaves-to-write 3
  443. # min-slaves-max-lag 10
  444. #
  445. # Setting one or the other to 0 disables the feature.
  446. #
  447. # By default min-slaves-to-write is set to 0 (feature disabled) and
  448. # min-slaves-max-lag is set to 10.
  449. ################################## SECURITY ###################################
  450. ################################## 安全 ###################################
  451. # Require clients to issue AUTH <PASSWORD> before processing any other
  452. # commands. This might be useful in environments in which you do not trust
  453. # others with access to the host running redis-server.
  454. #
  455. # This should stay commented out for backward compatibility and because most
  456. # people do not need auth (e.g. they run their own servers).
  457. #
  458. # Warning: since Redis is pretty fast an outside user can try up to
  459. # 150k passwords per second against a good box. This means that you should
  460. # use a very strong password otherwise it will be very easy to break.
  461. #
  462. # 设置连接redis的密码
  463. # redis速度相当快,一个外部用户在一秒钟进行150K次密码尝试,需指定强大的密码来防止暴力破解
  464. requirepass set_enough_strong_passwd
  465. # Command renaming.
  466. #
  467. # It is possible to change the name of dangerous commands in a shared
  468. # environment. For instance the CONFIG command may be renamed into something
  469. # hard to guess so that it will still be available for internal-use tools
  470. # but not available for general clients.
  471. #
  472. # Example:
  473. #
  474. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
  475. #
  476. # It is also possible to completely kill a command by renaming it into
  477. # an empty string:
  478. #
  479. # rename-command CONFIG ""
  480. #
  481. # Please note that changing the name of commands that are logged into the
  482. # AOF file or transmitted to slaves may cause problems.
  483. # 重命名一些高危命令,用来禁止高危命令
  484. rename-command FLUSHALL ZYzv6FOBdwflW2nX
  485. rename-command CONFIG aI7zwm1GDzMMrEi
  486. rename-command EVAL S9UHPKEpSvUJMM
  487. rename-command FLUSHDB D60FPVDJuip7gy6l
  488. ################################### LIMITS ####################################
  489. ################################### 限制 ####################################
  490. # Set the max number of connected clients at the same time. By default
  491. # this limit is set to 10000 clients, however if the Redis server is not
  492. # able to configure the process file limit to allow for the specified limit
  493. # the max number of allowed clients is set to the current file limit
  494. # minus 32 (as Redis reserves a few file descriptors for internal uses).
  495. #
  496. # Once the limit is reached Redis will close all the new connections sending
  497. # an error 'max number of clients reached'.
  498. #
  499. # 限制同时连接的客户数量,默认是10000
  500. # 当连接数超过这个值时,redis 将不再接收其他连接请求,客户端尝试连接时将收到 error 信息
  501. # maxclients 10000
  502. # Don't use more memory than the specified amount of bytes.
  503. # When the memory limit is reached Redis will try to remove keys
  504. # according to the eviction policy selected (see maxmemory-policy).
  505. #
  506. # If Redis can't remove keys according to the policy, or if the policy is
  507. # set to 'noeviction', Redis will start to reply with errors to commands
  508. # that would use more memory, like SET, LPUSH, and so on, and will continue
  509. # to reply to read-only commands like GET.
  510. #
  511. # This option is usually useful when using Redis as an LRU cache, or to set
  512. # a hard memory limit for an instance (using the 'noeviction' policy).
  513. #
  514. # WARNING: If you have slaves attached to an instance with maxmemory on,
  515. # the size of the output buffers needed to feed the slaves are subtracted
  516. # from the used memory count, so that network problems / resyncs will
  517. # not trigger a loop where keys are evicted, and in turn the output
  518. # buffer of slaves is full with DELs of keys evicted triggering the deletion
  519. # of more keys, and so forth until the database is completely emptied.
  520. #
  521. # In short... if you have slaves attached it is suggested that you set a lower
  522. # limit for maxmemory so that there is some free RAM on the system for slave
  523. # output buffers (but this is not needed if the policy is 'noeviction').
  524. #
  525. # 设置redis能够使用的最大内存。
  526. # 达到最大内存设置后,Redis会先尝试清除已到期或即将到期的Key(设置过expire信息的key)
  527. # 在删除时,按照过期时间进行删除,最早将要被过期的key将最先被删除
  528. # 如果已到期或即将到期的key删光,仍进行set操作,那么将返回错误
  529. # 此时redis将不再接收写请求,只接收get请求。
  530. # maxmemory的设置比较适合于把redis当作于类似memcached 的缓存来使用
  531. # maxmemory <bytes>
  532. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
  533. # is reached. You can select among five behaviors:
  534. #
  535. # volatile-lru -> remove the key with an expire set using an LRU algorithm
  536. # allkeys-lru -> remove any key according to the LRU algorithm
  537. # volatile-random -> remove a random key with an expire set
  538. # allkeys-random -> remove a random key, any key
  539. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)
  540. # noeviction -> don't expire at all, just return an error on write operations
  541. #
  542. # Note: with any of the above policies, Redis will return an error on write
  543. # operations, when there are no suitable keys for eviction.
  544. #
  545. # At the date of writing these commands are: set setnx setex append
  546. # incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
  547. # sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
  548. # zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
  549. # getset mset msetnx exec sort
  550. #
  551. # The default is:
  552. #
  553. # maxmemory-policy noeviction
  554. # LRU and minimal TTL algorithms are not precise algorithms but approximated
  555. # algorithms (in order to save memory), so you can tune it for speed or
  556. # accuracy. For default Redis will check five keys and pick the one that was
  557. # used less recently, you can change the sample size using the following
  558. # configuration directive.
  559. #
  560. # The default of 5 produces good enough results. 10 Approximates very closely
  561. # true LRU but costs a bit more CPU. 3 is very fast but not very accurate.
  562. #
  563. # maxmemory-samples 5
  564. ############################## APPEND ONLY MODE ###############################
  565. # By default Redis asynchronously dumps the dataset on disk. This mode is
  566. # good enough in many applications, but an issue with the Redis process or
  567. # a power outage may result into a few minutes of writes lost (depending on
  568. # the configured save points).
  569. #
  570. # The Append Only File is an alternative persistence mode that provides
  571. # much better durability. For instance using the default data fsync policy
  572. # (see later in the config file) Redis can lose just one second of writes in a
  573. # dramatic event like a server power outage, or a single write if something
  574. # wrong with the Redis process itself happens, but the operating system is
  575. # still running correctly.
  576. #
  577. # AOF and RDB persistence can be enabled at the same time without problems.
  578. # If the AOF is enabled on startup Redis will load the AOF, that is the file
  579. # with the better durability guarantees.
  580. #
  581. # Please check http://redis.io/topics/persistence for more information.
  582. # redis 默认每次更新操作后会在后台异步的把数据库镜像备份到磁盘,但该备份非常耗时,且备份不宜太频繁
  583. # redis 同步数据文件是按上面save条件来同步的
  584. # 如果发生诸如拉闸限电、拔插头等状况,那么将造成比较大范围的数据丢失
  585. # 所以redis提供了另外一种更加高效的数据库备份及灾难恢复方式
  586. # 开启append only 模式后,redis 将每一次写操作请求都追加到appendonly.aof 文件中
  587. # redis重新启动时,会从该文件恢复出之前的状态。
  588. # 但可能会造成 appendonly.aof 文件过大,所以redis支持BGREWRITEAOF 指令,对appendonly.aof重新整理,默认是不开启的。
  589. appendonly no
  590. # The name of the append only file (default: "appendonly.aof")
  591. # 默认为appendonly.aof。
  592. appendfilename "appendonly.aof"
  593. # The fsync() call tells the Operating System to actually write data on disk
  594. # instead of waiting for more data in the output buffer. Some OS will really flush
  595. # data on disk, some other OS will just try to do it ASAP.
  596. #
  597. # Redis supports three different modes:
  598. #
  599. # no: don't fsync, just let the OS flush the data when it wants. Faster.
  600. # always: fsync after every write to the append only log. Slow, Safest.
  601. # everysec: fsync only one time every second. Compromise.
  602. #
  603. # The default is "everysec", as that's usually the right compromise between
  604. # speed and data safety. It's up to you to understand if you can relax this to
  605. # "no" that will let the operating system flush the output buffer when
  606. # it wants, for better performances (but if you can live with the idea of
  607. # some data loss consider the default persistence mode that's snapshotting),
  608. # or on the contrary, use "always" that's very slow but a bit safer than
  609. # everysec.
  610. #
  611. # More details please check the following article:
  612. # http://antirez.com/post/redis-persistence-demystified.html
  613. #
  614. # If unsure, use "everysec".
  615. # 设置对 appendonly.aof 文件进行同步的频率,有三种选择always、everysec、no,默认是everysec表示每秒同步一次。
  616. # always 表示每次有写操作都进行同步,everysec 表示对写操作进行累积,每秒同步一次。
  617. # no表示等操作系统进行数据缓存同步到磁盘,都进行同步,everysec 表示对写操作进行累积,每秒同步一次
  618. # appendfsync always
  619. # appendfsync everysec
  620. # appendfsync no
  621. # When the AOF fsync policy is set to always or everysec, and a background
  622. # saving process (a background save or AOF log background rewriting) is
  623. # performing a lot of I/O against the disk, in some Linux configurations
  624. # Redis may block too long on the fsync() call. Note that there is no fix for
  625. # this currently, as even performing fsync in a different thread will block
  626. # our synchronous write(2) call.
  627. #
  628. # In order to mitigate this problem it's possible to use the following option
  629. # that will prevent fsync() from being called in the main process while a
  630. # BGSAVE or BGREWRITEAOF is in progress.
  631. #
  632. # This means that while another child is saving, the durability of Redis is
  633. # the same as "appendfsync none". In practical terms, this means that it is
  634. # possible to lose up to 30 seconds of log in the worst scenario (with the
  635. # default Linux settings).
  636. #
  637. # If you have latency problems turn this to "yes". Otherwise leave it as
  638. # "no" that is the safest pick from the point of view of durability.
  639. # 指定是否在后台aof文件rewrite期间调用fsync,默认为no,表示要调用fsync(无论后台是否有子进程在刷盘)。Redis在后台写RDB文件或重写afo文件期间会存在大量磁盘IO,此时,在某些linux系统中,调用fsync可能会阻塞。
  640. no-appendfsync-on-rewrite yes
  641. # Automatic rewrite of the append only file.
  642. # Redis is able to automatically rewrite the log file implicitly calling
  643. # BGREWRITEAOF when the AOF log size grows by the specified percentage.
  644. #
  645. # This is how it works: Redis remembers the size of the AOF file after the
  646. # latest rewrite (if no rewrite has happened since the restart, the size of
  647. # the AOF at startup is used).
  648. #
  649. # This base size is compared to the current size. If the current size is
  650. # bigger than the specified percentage, the rewrite is triggered. Also
  651. # you need to specify a minimal size for the AOF file to be rewritten, this
  652. # is useful to avoid rewriting the AOF file even if the percentage increase
  653. # is reached but it is still pretty small.
  654. #
  655. # Specify a percentage of zero in order to disable the automatic AOF
  656. # rewrite feature.
  657. # 指定Redis重写aof文件的条件,默认为100,表示与上次rewrite的aof文件大小相比,当前aof文件增长量超过上次afo文件大小的100%时,就会触发background rewrite。若配置为0,则会禁用自动rewrite
  658. auto-aof-rewrite-percentage 100
  659. # 指定触发rewrite的aof文件大小。若aof文件小于该值,即使当前文件的增量比例达到auto-aof-rewrite-percentage的配置值,也不会触发自动rewrite。即这两个配置项同时满足时,才会触发rewrite。
  660. auto-aof-rewrite-min-size 64mb
  661. # An AOF file may be found to be truncated at the end during the Redis
  662. # startup process, when the AOF data gets loaded back into memory.
  663. # This may happen when the system where Redis is running
  664. # crashes, especially when an ext4 filesystem is mounted without the
  665. # data=ordered option (however this can't happen when Redis itself
  666. # crashes or aborts but the operating system still works correctly).
  667. #
  668. # Redis can either exit with an error when this happens, or load as much
  669. # data as possible (the default now) and start if the AOF file is found
  670. # to be truncated at the end. The following option controls this behavior.
  671. #
  672. # If aof-load-truncated is set to yes, a truncated AOF file is loaded and
  673. # the Redis server starts emitting a log to inform the user of the event.
  674. # Otherwise if the option is set to no, the server aborts with an error
  675. # and refuses to start. When the option is set to no, the user requires
  676. # to fix the AOF file using the "redis-check-aof" utility before to restart
  677. # the server.
  678. #
  679. # Note that if the AOF file will be found to be corrupted in the middle
  680. # the server will still exit with an error. This option only applies when
  681. # Redis will try to read more data from the AOF file but not enough bytes
  682. # will be found.
  683. aof-load-truncated yes
  684. ################################ LUA SCRIPTING ###############################
  685. # Max execution time of a Lua script in milliseconds.
  686. #
  687. # If the maximum execution time is reached Redis will log that a script is
  688. # still in execution after the maximum allowed time and will start to
  689. # reply to queries with an error.
  690. #
  691. # When a long running script exceeds the maximum execution time only the
  692. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be
  693. # used to stop a script that did not yet called write commands. The second
  694. # is the only way to shut down the server in the case a write command was
  695. # already issued by the script but the user doesn't want to wait for the natural
  696. # termination of the script.
  697. #
  698. # Set it to 0 or a negative value for unlimited execution without warnings.
  699. # 一个Lua脚本最长的执行时间,单位为毫秒,如果为0或负数表示无限执行时间,默认为5000
  700. lua-time-limit 5000
  701. ################################ REDIS CLUSTER ###############################
  702. #
  703. # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  704. # WARNING EXPERIMENTAL: Redis Cluster is considered to be stable code, however
  705. # in order to mark it as "mature" we need to wait for a non trivial percentage
  706. # of users to deploy it in production.
  707. # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  708. #
  709. # Normal Redis instances can't be part of a Redis Cluster; only nodes that are
  710. # started as cluster nodes can. In order to start a Redis instance as a
  711. # cluster node enable the cluster support uncommenting the following:
  712. #
  713. # cluster-enabled yes
  714. # Every cluster node has a cluster configuration file. This file is not
  715. # intended to be edited by hand. It is created and updated by Redis nodes.
  716. # Every Redis Cluster node requires a different cluster configuration file.
  717. # Make sure that instances running in the same system do not have
  718. # overlapping cluster configuration file names.
  719. #
  720. # cluster-config-file nodes-6379.conf
  721. # Cluster node timeout is the amount of milliseconds a node must be unreachable
  722. # for it to be considered in failure state.
  723. # Most other internal time limits are multiple of the node timeout.
  724. #
  725. # cluster-node-timeout 15000
  726. # A slave of a failing master will avoid to start a failover if its data
  727. # looks too old.
  728. #
  729. # There is no simple way for a slave to actually have a exact measure of
  730. # its "data age", so the following two checks are performed:
  731. #
  732. # 1) If there are multiple slaves able to failover, they exchange messages
  733. # in order to try to give an advantage to the slave with the best
  734. # replication offset (more data from the master processed).
  735. # Slaves will try to get their rank by offset, and apply to the start
  736. # of the failover a delay proportional to their rank.
  737. #
  738. # 2) Every single slave computes the time of the last interaction with
  739. # its master. This can be the last ping or command received (if the master
  740. # is still in the "connected" state), or the time that elapsed since the
  741. # disconnection with the master (if the replication link is currently down).
  742. # If the last interaction is too old, the slave will not try to failover
  743. # at all.
  744. #
  745. # The point "2" can be tuned by user. Specifically a slave will not perform
  746. # the failover if, since the last interaction with the master, the time
  747. # elapsed is greater than:
  748. #
  749. # (node-timeout * slave-validity-factor) + repl-ping-slave-period
  750. #
  751. # So for example if node-timeout is 30 seconds, and the slave-validity-factor
  752. # is 10, and assuming a default repl-ping-slave-period of 10 seconds, the
  753. # slave will not try to failover if it was not able to talk with the master
  754. # for longer than 310 seconds.
  755. #
  756. # A large slave-validity-factor may allow slaves with too old data to failover
  757. # a master, while a too small value may prevent the cluster from being able to
  758. # elect a slave at all.
  759. #
  760. # For maximum availability, it is possible to set the slave-validity-factor
  761. # to a value of 0, which means, that slaves will always try to failover the
  762. # master regardless of the last time they interacted with the master.
  763. # (However they'll always try to apply a delay proportional to their
  764. # offset rank).
  765. #
  766. # Zero is the only value able to guarantee that when all the partitions heal
  767. # the cluster will always be able to continue.
  768. #
  769. # cluster-slave-validity-factor 10
  770. # Cluster slaves are able to migrate to orphaned masters, that are masters
  771. # that are left without working slaves. This improves the cluster ability
  772. # to resist to failures as otherwise an orphaned master can't be failed over
  773. # in case of failure if it has no working slaves.
  774. #
  775. # Slaves migrate to orphaned masters only if there are still at least a
  776. # given number of other working slaves for their old master. This number
  777. # is the "migration barrier". A migration barrier of 1 means that a slave
  778. # will migrate only if there is at least 1 other working slave for its master
  779. # and so forth. It usually reflects the number of slaves you want for every
  780. # master in your cluster.
  781. #
  782. # Default is 1 (slaves migrate only if their masters remain with at least
  783. # one slave). To disable migration just set it to a very large value.
  784. # A value of 0 can be set but is useful only for debugging and dangerous
  785. # in production.
  786. #
  787. # cluster-migration-barrier 1
  788. # By default Redis Cluster nodes stop accepting queries if they detect there
  789. # is at least an hash slot uncovered (no available node is serving it).
  790. # This way if the cluster is partially down (for example a range of hash slots
  791. # are no longer covered) all the cluster becomes, eventually, unavailable.
  792. # It automatically returns available as soon as all the slots are covered again.
  793. #
  794. # However sometimes you want the subset of the cluster which is working,
  795. # to continue to accept queries for the part of the key space that is still
  796. # covered. In order to do so, just set the cluster-require-full-coverage
  797. # option to no.
  798. #
  799. # cluster-require-full-coverage yes
  800. # In order to setup your cluster make sure to read the documentation
  801. # available at http://redis.io web site.
  802. ################################## SLOW LOG ###################################
  803. # The Redis Slow Log is a system to log queries that exceeded a specified
  804. # execution time. The execution time does not include the I/O operations
  805. # like talking with the client, sending the reply and so forth,
  806. # but just the time needed to actually execute the command (this is the only
  807. # stage of command execution where the thread is blocked and can not serve
  808. # other requests in the meantime).
  809. #
  810. # You can configure the slow log with two parameters: one tells Redis
  811. # what is the execution time, in microseconds, to exceed in order for the
  812. # command to get logged, and the other parameter is the length of the
  813. # slow log. When a new command is logged the oldest one is removed from the
  814. # queue of logged commands.
  815. # The following time is expressed in microseconds, so 1000000 is equivalent
  816. # to one second. Note that a negative number disables the slow log, while
  817. # a value of zero forces the logging of every command.
  818. slowlog-log-slower-than 10000
  819. # There is no limit to this length. Just be aware that it will consume memory.
  820. # You can reclaim memory used by the slow log with SLOWLOG RESET.
  821. slowlog-max-len 128
  822. ################################ LATENCY MONITOR ##############################
  823. # The Redis latency monitoring subsystem samples different operations
  824. # at runtime in order to collect data related to possible sources of
  825. # latency of a Redis instance.
  826. #
  827. # Via the LATENCY command this information is available to the user that can
  828. # print graphs and obtain reports.
  829. #
  830. # The system only logs operations that were performed in a time equal or
  831. # greater than the amount of milliseconds specified via the
  832. # latency-monitor-threshold configuration directive. When its value is set
  833. # to zero, the latency monitor is turned off.
  834. #
  835. # By default latency monitoring is disabled since it is mostly not needed
  836. # if you don't have latency issues, and collecting data has a performance
  837. # impact, that while very small, can be measured under big load. Latency
  838. # monitoring can easily be enabled at runtime using the command
  839. # "CONFIG SET latency-monitor-threshold <milliseconds>" if needed.
  840. latency-monitor-threshold 0
  841. ############################# EVENT NOTIFICATION ##############################
  842. # Redis can notify Pub/Sub clients about events happening in the key space.
  843. # This feature is documented at http://redis.io/topics/notifications
  844. #
  845. # For instance if keyspace events notification is enabled, and a client
  846. # performs a DEL operation on key "foo" stored in the Database 0, two
  847. # messages will be published via Pub/Sub:
  848. #
  849. # PUBLISH __keyspace@0__:foo del
  850. # PUBLISH __keyevent@0__:del foo
  851. #
  852. # It is possible to select the events that Redis will notify among a set
  853. # of classes. Every class is identified by a single character:
  854. #
  855. # K Keyspace events, published with __keyspace@<db>__ prefix.
  856. # E Keyevent events, published with __keyevent@<db>__ prefix.
  857. # g Generic commands (non-type specific) like DEL, EXPIRE, RENAME, ...
  858. # $ String commands
  859. # l List commands
  860. # s Set commands
  861. # h Hash commands
  862. # z Sorted set commands
  863. # x Expired events (events generated every time a key expires)
  864. # e Evicted events (events generated when a key is evicted for maxmemory)
  865. # A Alias for g$lshzxe, so that the "AKE" string means all the events.
  866. #
  867. # The "notify-keyspace-events" takes as argument a string that is composed
  868. # of zero or multiple characters. The empty string means that notifications
  869. # are disabled.
  870. #
  871. # Example: to enable list and generic events, from the point of view of the
  872. # event name, use:
  873. #
  874. # notify-keyspace-events Elg
  875. #
  876. # Example 2: to get the stream of the expired keys subscribing to channel
  877. # name __keyevent@0__:expired use:
  878. #
  879. # notify-keyspace-events Ex
  880. #
  881. # By default all notifications are disabled because most users don't need
  882. # this feature and the feature has some overhead. Note that if you don't
  883. # specify at least one of K or E, no events will be delivered.
  884. notify-keyspace-events ""
  885. ############################### ADVANCED CONFIG ###############################
  886. # Hashes are encoded using a memory efficient data structure when they have a
  887. # small number of entries, and the biggest entry does not exceed a given
  888. # threshold. These thresholds can be configured using the following directives.
  889. # 当hash中包含超过指定元素个数并且最大的元素没有超过临界时,
  890. # hash将以一种特殊的编码方式(大大减少内存使用)来存储,这里可以设置这两个临界值
  891. hash-max-ziplist-entries 512
  892. hash-max-ziplist-value 64
  893. # Similarly to hashes, small lists are also encoded in a special way in order
  894. # to save a lot of space. The special representation is only used when
  895. # you are under the following limits:
  896. # list数据类型多少节点以下会采用去指针的紧凑存储格式。
  897. # list数据类型节点值大小小于多少字节会采用紧凑存储格式。
  898. list-max-ziplist-entries 512
  899. list-max-ziplist-value 64
  900. # Sets have a special encoding in just one case: when a set is composed
  901. # of just strings that happen to be integers in radix 10 in the range
  902. # of 64 bit signed integers.
  903. # The following configuration setting sets the limit in the size of the
  904. # set in order to use this special memory saving encoding.
  905. # set数据类型内部数据如果全部是数值型,且包含多少节点以下会采用紧凑格式存储。
  906. set-max-intset-entries 512
  907. # Similarly to hashes and lists, sorted sets are also specially encoded in
  908. # order to save a lot of space. This encoding is only used when the length and
  909. # elements of a sorted set are below the following limits:
  910. # zsort数据类型多少节点以下会采用去指针的紧凑存储格式。
  911. # zsort数据类型节点值大小小于多少字节会采用紧凑存储格式。
  912. zset-max-ziplist-entries 128
  913. zset-max-ziplist-value 64
  914. # HyperLogLog sparse representation bytes limit. The limit includes the
  915. # 16 bytes header. When an HyperLogLog using the sparse representation crosses
  916. # this limit, it is converted into the dense representation.
  917. #
  918. # A value greater than 16000 is totally useless, since at that point the
  919. # dense representation is more memory efficient.
  920. #
  921. # The suggested value is ~ 3000 in order to have the benefits of
  922. # the space efficient encoding without slowing down too much PFADD,
  923. # which is O(N) with the sparse encoding. The value can be raised to
  924. # ~ 10000 when CPU is not a concern, but space is, and the data set is
  925. # composed of many HyperLogLogs with cardinality in the 0 - 15000 range.
  926. hll-sparse-max-bytes 3000
  927. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
  928. # order to help rehashing the main Redis hash table (the one mapping top-level
  929. # keys to values). The hash table implementation Redis uses (see dict.c)
  930. # performs a lazy rehashing: the more operation you run into a hash table
  931. # that is rehashing, the more rehashing "steps" are performed, so if the
  932. # server is idle the rehashing is never complete and some more memory is used
  933. # by the hash table.
  934. #
  935. # The default is to use this millisecond 10 times every second in order to
  936. # actively rehash the main dictionaries, freeing memory when possible.
  937. #
  938. # If unsure:
  939. # use "activerehashing no" if you have hard latency requirements and it is
  940. # not a good thing in your environment that Redis can reply from time to time
  941. # to queries with 2 milliseconds delay.
  942. #
  943. # use "activerehashing yes" if you don't have such hard requirements but
  944. # want to free memory asap when possible.
  945. # Redis将在每100毫秒时使用1毫秒的CPU时间来对redis的hash表进行重新hash,可以降低内存的使用
  946. # 当你的使用场景中,有非常严格的实时性需要,不能够接受Redis时不时的对请求有2毫秒的延迟的话,把这项配置为no。
  947. # 如果没有这么严格的实时性要求,可以设置为yes,以便能够尽可能快的释放内存
  948. activerehashing yes
  949. # The client output buffer limits can be used to force disconnection of clients
  950. # that are not reading data from the server fast enough for some reason (a
  951. # common reason is that a Pub/Sub client can't consume messages as fast as the
  952. # publisher can produce them).
  953. #
  954. # The limit can be set differently for the three different classes of clients:
  955. #
  956. # normal -> normal clients including MONITOR clients
  957. # slave -> slave clients
  958. # pubsub -> clients subscribed to at least one pubsub channel or pattern
  959. #
  960. # The syntax of every client-output-buffer-limit directive is the following:
  961. #
  962. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
  963. #
  964. # A client is immediately disconnected once the hard limit is reached, or if
  965. # the soft limit is reached and remains reached for the specified number of
  966. # seconds (continuously).
  967. # So for instance if the hard limit is 32 megabytes and the soft limit is
  968. # 16 megabytes / 10 seconds, the client will get disconnected immediately
  969. # if the size of the output buffers reach 32 megabytes, but will also get
  970. # disconnected if the client reaches 16 megabytes and continuously overcomes
  971. # the limit for 10 seconds.
  972. #
  973. # By default normal clients are not limited because they don't receive data
  974. # without asking (in a push way), but just after a request, so only
  975. # asynchronous clients may create a scenario where data is requested faster
  976. # than it can read.
  977. #
  978. # Instead there is a default limit for pubsub and slave clients, since
  979. # subscribers and slaves receive data in a push fashion.
  980. #
  981. # Both the hard or the soft limit can be disabled by setting them to zero.
  982. client-output-buffer-limit normal 0 0 0
  983. client-output-buffer-limit slave 256mb 64mb 60
  984. client-output-buffer-limit pubsub 32mb 8mb 60
  985. # Redis calls an internal function to perform many background tasks, like
  986. # closing connections of clients in timeout, purging expired keys that are
  987. # never requested, and so forth.
  988. #
  989. # Not all tasks are performed with the same frequency, but Redis checks for
  990. # tasks to perform according to the specified "hz" value.
  991. #
  992. # By default "hz" is set to 10. Raising the value will use more CPU when
  993. # Redis is idle, but at the same time will make Redis more responsive when
  994. # there are many keys expiring at the same time, and timeouts may be
  995. # handled with more precision.
  996. #
  997. # The range is between 1 and 500, however a value over 100 is usually not
  998. # a good idea. Most users should use the default of 10 and raise this up to
  999. # 100 only in environments where very low latency is required.
  1000. hz 10
  1001. # When a child rewrites the AOF file, if the following option is enabled
  1002. # the file will be fsync-ed every 32 MB of data generated. This is useful
  1003. # in order to commit the file to the disk more incrementally and avoid
  1004. # big latency spikes.
  1005. # aof rewrite过程中,是否采取增量文件同步策略,默认为“yes”。 rewrite过程中,每32M数据进行一次文件同步,这样可以减少aof大文件写入对磁盘的操作次数
  1006. aof-rewrite-incremental-fsync yes
  1007. # redis数据存储
  1008. redis的存储分为内存存储、磁盘存储和log文件三部分,配置文件中有三个参数对其进行配置。
  1009. save seconds updates,save配置,指出在多长时间内,有多少次更新操作,就将数据同步到数据文件。可多个条件配合,默认配置了三个条件。
  1010. appendonly yes/no ,appendonly配置,指出是否在每次更新操作后进行日志记录,如果不开启,可能会在断电时导致一段时间内的数据丢失。因为redis本身同步数据文件是按上面的save条件来同步的,所以有的数据会在一段时间内只存在于内存中。
  1011. appendfsync no/always/everysec ,appendfsync配置,no表示等操作系统进行数据缓存同步到磁盘,always表示每次更新操作后手动调用fsync()将数据写到磁盘,everysec表示每秒同步一次。

注意:

redis配置密码,尤为重要,否则容易遭受攻击

去掉行前的注释,并修改密码为所需的密码

  1. #requirepass foobared
  2. requirepass yourPasswd

Redis 未授权访问缺陷,这个 Redis 未授权访问缺陷可轻易导致系统被黑。感兴趣的自己可以尝试下整个攻击过程。

漏洞概要:

Redis 默认情况下,会绑定在 0.0.0.0:6379,这样将会将Redis服务暴露到公网上,如果在没有开启认证的情况下,可以导致任意用户在可以访问目标服务器的情况下未授权访 问Redis以及读取Redis的数据。攻击者在未授权访问Redis的情况下可以利用Redis的相关方法,可以成功将自己的公钥写入目标服务器的 /root/.ssh 文件夹的authotrized_keys 文件中,进而可以直接登录目标服务器。

漏洞描述:

  1. redis 安全模型的观念是: “请不要将Redis暴露在公开网络中, 因为让不受信任的客户接触到Redis是非常危险的” 。
  2. Redis 作者之所以放弃解决未授权访问导致的不安全性是因为, 99.99%使用Redis的场景都是在沙盒化的环境中, 为了0.01%的可能性增加安全规则的同时也增加了复杂性, 虽然这个问题的并不是不能解决的, 但是这在他的设计哲学中仍是不划算的。
  3. 因为其他受信任用户需要使用Redis或者因为运维人员的疏忽等原因,部分Redis 绑定在0.0.0.0:6379,并且没有开启认证(这是Redis的默认配置),如果没有进行采用相关的策略,比如添加防火墙规则避免其他非信任来源 ip访问等,将会导致Redis服务直接暴露在公网上,导致其他用户可以直接在非授权情况下直接访问Redis服务并进行相关操作。
  4. 利用Redis自身的相关方法,可以进行写文件操作,攻击者可以成功将自己的公钥写入目标服务器的 /root/.ssh 文件夹的authotrized_keys 文件中,进而可以直接登录目标服务器。

漏洞影响:

Redis 暴露在公网(即绑定在0.0.0.0:6379,目标IP公网可访问),并且没有开启相关认证和添加相关安全策略情况下可受影响而导致被利用。

本文为joshua317原创文章,转载请注明:转载自joshua317博客 https://www.joshua317.com/article/38

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/906875
推荐阅读
相关标签
  

闽ICP备14008679号