Redis basic configuration file

Time:2021-4-12

In general, redis configuration file provides many default options, which can be used directly without any modification. This paper mainly describes the common configuration options in the configuration file, which are only for learning and sharing. If there are any shortcomings, please correct them.

Redis startup mode

When starting redis, there must be a configuration file matching it (for example, / root / myredis)/ redis.conf ), as follows:

1 [[email protected] bin]# ./redis-server /root/myredis/redis.conf 

 

Redis configuration file details

Redis configuration file items are mainly divided into the following parts:

  1. Includes: a configuration file that can be imported into other configuration files.
  2. Modules: modules loaded at startup.
  3. Network: network related configuration.
  4. TLS / SSL: secure transmission module.
  5. General: general configuration related.
  6. Snapshot: snapshot configuration related.
  7. Replication: master and slave copy related configuration items.
  8. Keys tracking: key tracking related configuration items.
  9. Security: security related configuration.
  10. Clients: client related configuration.
  11. Memory management: memory management related configuration items.
  12. Lazy free: delay releasing configuration items.
  13. Thread I / O: multi thread I / O related configuration items.
  14. Kernel oom control: Linux kernel to prevent excessive memory usage configuration options.
  15. Append only mode: data persistent append mode.
  16. Lua scripting: Lua script related configuration items.
  17. Redis cluster: redis cluster related configuration items.
  18. Cluster docker / NAT support: docker / NAT cluster supports configuration items.
  19. Slow log: time consuming log.
  20. Latency monitor: delay monitoring configuration related options.
  21. Event notification: configuration items related to event notification.
  22. Gopher server: gopher server.
  23. Advanced config: advanced configuration.
  24. Active defragmentation: active defragmentation related configuration.

Note: the redis configuration file starts with # to indicate comments or instructions; if enabled, remove #.

INCLUDES

If there is a standard configuration template when redis starts, but you need to customize the relevant configuration of each instance, you can import it in the way of include configuration file. If you do not need to import a file by default, this is a comment. As follows:

1 # include /path/to/local.conf
2 # include /path/to/other.conf

MODULES

The module that needs to be started is loaded at startup. By default, it does not need to be started, so it is also annotated. As follows:

1 # loadmodule /path/to/my_module.so
2 # loadmodule /path/to/other_module.so

NETWORK

Network is mainly used to configure network related items, as follows:

Bind configuration can access the IP address, can configure multiple, generally recommended LAN internal IP. It is very dangerous to run redis on the Internet and bind all IP addresses.

If you want all IP addresses to be accessible, you can comment out the following statement. As follows:

1 # Examples:
2 #
3 # bind 192.168.1.100 10.0.0.1
4 # bind 127.0.0.1 ::1
5 
6 bind 127.0.0.1

Port specifies the port number when redis starts. The default is 6379. It is not recommended to use a port number below 1000, because it is easy to conflict with the operating system port number. As follows:

1 # Accept connections on the specified port, default is 6379 (IANA #815344).
2 # If port 0 is specified Redis will not listen on a TCP socket.
3 port 6379

TCP backlog configures the size of the full connection queue, which is 511 by default. However, this value generally cannot be greater than the value configured by / proc / sys / net / core / somaxconn. As follows:

1 # In high requests-per-second environments you need a high backlog in order
2 # to avoid slow clients connection issues. Note that the Linux kernel
3 # will silently truncate it to the value of /proc/sys/net/core/somaxconn so
4 # make sure to raise both the value of somaxconn and tcp_max_syn_backlog
5 # in order to get the desired effect.
6 tcp-backlog 511

The values of / proc / sys / net / core / somaxconn are as follows:

1 [[email protected] bin]# cat /proc/sys/net/core/somaxconn
2 128

Timeout sets the timeout time, which is used to set the disconnection time when the client is not connected. 0 means failure. As follows:

1 # Close the connection after a client is idle for N seconds (0 to disable)
2 timeout 0

TCP keepalive sets the duration of the connection. If the duration exceeds, TCP ack will be sent to the client, as shown below:

1 # A reasonable value for this option is 300 seconds, which is the new
2 # Redis default starting with Redis 3.2.1.
3 tcp-keepalive 300

GENERAL

Daemonize is used to configure whether redis runs as a daemons. The default value is No. when it starts, a window will be started separately. When the window is closed, the redis process ends. So in order for redis to run in the background, you need to change this item to yes. As follows:

1 # By default Redis does not run as a daemon. Use 'yes' if you need it.
2 # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
3 daemonize yes

Pidfile configures the process file. When redis is started as a guardian, it will be generated when it is started and deleted when it is closed, as shown below:

 1 # If a pid file is specified, Redis writes it where specified at startup
 2 # and removes it at exit.
 3 #
 4 # When the server runs non daemonized, no pid file is created if none is
 5 # specified in the configuration. When the server is daemonized, the pid file
 6 # is used even if not specified, defaulting to "/var/run/redis.pid".
 7 #
 8 # Creating a pid file is best effort: if Redis is not able to create it
 9 # nothing bad happens, the server will start and run normally.
10 pidfile /var/run/redis_6379.pid

Log level: there are four log levels: debug, verb, notice and warning. The default is notice, as shown below:

1 # Specify the server verbosity level.
2 # This can be one of:
3 # debug (a lot of information, useful for development/testing)
4 # verbose (many rarely useful info, but not a mess like the debug level)
5 # notice (moderately verbose, what you want in production probably)
6 # warning (only very important / critical messages are logged)
7 loglevel notice

Logfile log file configuration. If it is empty by default, no log will be recorded, as shown below:

1 # Specify the log file name. Also the empty string can be used to force
2 # Redis to log on the standard output. Note that if you use standard
3 # output for logging but daemonize, logs will be sent to /dev/null
4 logfile ""

Syslog enabled is used to record the system log. It is not recorded by default, as shown below:

1 # To enable logging to the system logger, just set 'syslog-enabled' to yes,
2 # and optionally update the other syslog parameters to suit your needs.
3 # syslog-enabled no
4 
5 # Specify the syslog identity.
6 # syslog-ident redis
7 
8 # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
9 # syslog-facility local0

There are 16 databases in redis by default, and the default is 0, as shown below:

1 # Set the number of databases. The default database is DB 0, you can select
2 # a different one on a per-connection basis using SELECT  where
3 # dbid is a number between 0 and 'databases'-1
4 databases 16

Always show logo sets whether the logo is displayed. The default value is yes, as shown below:

1 # By default Redis shows an ASCII art logo only when started to log to the
2 # standard output and if the standard output is a TTY. Basically this means
3 # that normally a logo is displayed only in interactive sessions.
4 #
5 # However it is possible to force the pre-4.0 behavior and always show a
6 # ASCII art logo in startup logs by setting the following option to yes.
7 always-show-logo yes

SNAPSHOTTING

Snapshot is mainly used to save the data in memory to the hard disk.

The Save command, which configures how often to save, can set a variety of modes, as follows:

1 # Save the DB on disk:
 2 #
 3 #   save  
 4 #
 5 #   Will save the DB if both the given number of seconds and the given
 6 #   number of write operations against the DB occurred.
 7 #
 8 #   In the example below the behavior will be to save:
 9 #   after 900 sec (15 min) if at least 1 key changed
10 #   after 300 sec (5 min) if at least 10 keys changed
11 #   after 60 sec if at least 10000 keys changed
12 
13 save 900 1
14 save 300 10
15 save 60 10000

Stop writes on bgsave error whether to stop writing when saving or making an error. The default value is yes, as shown below:

1 # However if you have setup your proper monitoring of the Redis server
2 # and persistence, you may want to disable this feature so that Redis will
3 # continue to work as usual even if there are problems with disk,
4 # permissions, and so forth.
5 stop-writes-on-bgsave-error yes

Is the rdbcompression snapshot file compressed? If not, the database file will be large, as shown below:

1 # Compress string objects using LZF when dump .rdb databases?
2 # By default compression is enabled as it's almost always a win.
3 # If you want to save some CPU in the saving child set it to 'no' but
4 # the dataset will likely be bigger if you have compressible values or keys.
5 rdbcompression yes

Dbfilename, the default is dump.rdb . As follows:

1 # The filename where to dump the DB
2 dbfilename dump.rdb

The directory to save the dir database file is as follows:

1 # The working directory.
2 #
3 # The DB will be written inside this directory, with the filename specified
4 # above using the 'dbfilename' configuration directive.
5 #
6 # The Append Only File will also be created inside this directory.
7 #
8 # Note that you must specify a directory here, not a file name.
9 dir ./

SECURITY

Requirepass sets the default user login password, and there is no password by default, as follows:

1 # IMPORTANT NOTE: starting with Redis 6 "requirepass" is just a compatibility
2 # layer on top of the new ACL system. The option effect will be just setting
3 # the password for the default user. Clients will still authenticate using
4 # AUTH  as usually, or more explicitly with AUTH default 
5 # if they follow the new protocol: both will work.
6 #
7 # requirepass foobared

CLIENTS

Maxclients the maximum number of clients allowed to connect at the same time is as follows:

 1 # Set the max number of connected clients at the same time. By default
 2 # this limit is set to 10000 clients, however if the Redis server is not
 3 # able to configure the process file limit to allow for the specified limit
 4 # the max number of allowed clients is set to the current file limit
 5 # minus 32 (as Redis reserves a few file descriptors for internal uses).
 6 #
 7 # Once the limit is reached Redis will close all the new connections sending
 8 # an error 'max number of clients reached'.
 9 #
10 # maxclients 10000

When configuring a redis cluster, the number of redis connections and the cluster bus are shared.

Redis command mode configuration

In addition to modifying the configuration file, redis can also modify the configuration item through the client. Examples are as follows:

Config get * is used to get all configuration items, as follows:

Redis basic configuration fileRedis basic configuration file

  1 127.0.0.1:6379> config get *
  2   1) "rdbchecksum"
  3   2) "yes"
  4   3) "daemonize"
  5   4) "yes"
  6   5) "io-threads-do-reads"
  7   6) "no"
  8   7) "lua-replicate-commands"
  9   8) "yes"
 10   9) "always-show-logo"
 11  10) "yes"
 12  11) "protected-mode"
 13  12) "yes"
 14  13) "rdbcompression"
 15  14) "yes"
 16  15) "rdb-del-sync-files"
 17  16) "no"
 18  17) "activerehashing"
 19  18) "yes"
 20  19) "stop-writes-on-bgsave-error"
 21  20) "yes"
 22  21) "dynamic-hz"
 23  22) "yes"
 24  23) "lazyfree-lazy-eviction"
 25  24) "no"
 26  25) "lazyfree-lazy-expire"
 27  26) "no"
 28  27) "lazyfree-lazy-server-del"
 29  28) "no"
 30  29) "lazyfree-lazy-user-del"
 31  30) "no"
 32  31) "repl-disable-tcp-nodelay"
 33  32) "no"
 34  33) "repl-diskless-sync"
 35  34) "no"
 36  35) "gopher-enabled"
 37  36) "no"
 38  37) "aof-rewrite-incremental-fsync"
 39  38) "yes"
 40  39) "no-appendfsync-on-rewrite"
 41  40) "no"
 42  41) "cluster-require-full-coverage"
 43  42) "yes"
 44  43) "rdb-save-incremental-fsync"
 45  44) "yes"
 46  45) "aof-load-truncated"
 47  46) "yes"
 48  47) "aof-use-rdb-preamble"
 49  48) "yes"
 50  49) "cluster-replica-no-failover"
 51  50) "no"
 52  51) "cluster-slave-no-failover"
 53  52) "no"
 54  53) "replica-lazy-flush"
 55  54) "no"
 56  55) "slave-lazy-flush"
 57  56) "no"
 58  57) "replica-serve-stale-data"
 59  58) "yes"
 60  59) "slave-serve-stale-data"
 61  60) "yes"
 62  61) "replica-read-only"
 63  62) "yes"
 64  63) "slave-read-only"
 65  64) "yes"
 66  65) "replica-ignore-maxmemory"
 67  66) "yes"
 68  67) "slave-ignore-maxmemory"
 69  68) "yes"
 70  69) "jemalloc-bg-thread"
 71  70) "yes"
 72  71) "activedefrag"
 73  72) "no"
 74  73) "syslog-enabled"
 75  74) "no"
 76  75) "cluster-enabled"
 77  76) "no"
 78  77) "appendonly"
 79  78) "no"
 80  79) "cluster-allow-reads-when-down"
 81  80) "no"
 82  81) "oom-score-adj"
 83  82) "no"
 84  83) "aclfile"
 85  84) ""
 86  85) "unixsocket"
 87  86) ""
 88  87) "pidfile"
 89  88) "/var/run/redis_6379.pid"
 90  89) "replica-announce-ip"
 91  90) ""
 92  91) "slave-announce-ip"
 93  92) ""
 94  93) "masteruser"
 95  94) ""
 96  95) "masterauth"
 97  96) ""
 98  97) "cluster-announce-ip"
 99  98) ""
100  99) "syslog-ident"
101 100) "redis"
102 101) "dbfilename"
103 102) "dump.rdb"
104 103) "appendfilename"
105 104) "appendonly.aof"
106 105) "server_cpulist"
107 106) ""
108 107) "bio_cpulist"
109 108) ""
110 109) "aof_rewrite_cpulist"
111 110) ""
112 111) "bgsave_cpulist"
113 112) ""
114 113) "supervised"
115 114) "no"
116 115) "syslog-facility"
117 116) "local0"
118 117) "repl-diskless-load"
119 118) "disabled"
120 119) "loglevel"
121 120) "notice"
122 121) "maxmemory-policy"
123 122) "noeviction"
124 123) "appendfsync"
125 124) "everysec"
126 125) "databases"
127 126) "16"
128 127) "port"
129 128) "6379"
130 129) "io-threads"
131 130) "1"
132 131) "auto-aof-rewrite-percentage"
133 132) "100"
134 133) "cluster-replica-validity-factor"
135 134) "10"
136 135) "cluster-slave-validity-factor"
137 136) "10"
138 137) "list-max-ziplist-size"
139 138) "-2"
140 139) "tcp-keepalive"
141 140) "300"
142 141) "cluster-migration-barrier"
143 142) "1"
144 143) "active-defrag-cycle-min"
145 144) "1"
146 145) "active-defrag-cycle-max"
147 146) "25"
148 147) "active-defrag-threshold-lower"
149 148) "10"
150 149) "active-defrag-threshold-upper"
151 150) "100"
152 151) "lfu-log-factor"
153 152) "10"
154 153) "lfu-decay-time"
155 154) "1"
156 155) "replica-priority"
157 156) "100"
158 157) "slave-priority"
159 158) "100"
160 159) "repl-diskless-sync-delay"
161 160) "5"
162 161) "maxmemory-samples"
163 162) "5"
164 163) "timeout"
165 164) "0"
166 165) "replica-announce-port"
167 166) "0"
168 167) "slave-announce-port"
169 168) "0"
170 169) "tcp-backlog"
171 170) "511"
172 171) "cluster-announce-bus-port"
173 172) "0"
174 173) "cluster-announce-port"
175 174) "0"
176 175) "repl-timeout"
177 176) "60"
178 177) "repl-ping-replica-period"
179 178) "10"
180 179) "repl-ping-slave-period"
181 180) "10"
182 181) "list-compress-depth"
183 182) "0"
184 183) "rdb-key-save-delay"
185 184) "0"
186 185) "key-load-delay"
187 186) "0"
188 187) "active-expire-effort"
189 188) "1"
190 189) "hz"
191 190) "10"
192 191) "min-replicas-to-write"
193 192) "0"
194 193) "min-slaves-to-write"
195 194) "0"
196 195) "min-replicas-max-lag"
197 196) "10"
198 197) "min-slaves-max-lag"
199 198) "10"
200 199) "maxclients"
201 200) "10000"
202 201) "active-defrag-max-scan-fields"
203 202) "1000"
204 203) "slowlog-max-len"
205 204) "128"
206 205) "acllog-max-len"
207 206) "128"
208 207) "lua-time-limit"
209 208) "5000"
210 209) "cluster-node-timeout"
211 210) "15000"
212 211) "slowlog-log-slower-than"
213 212) "10000"
214 213) "latency-monitor-threshold"
215 214) "0"
216 215) "proto-max-bulk-len"
217 216) "536870912"
218 217) "stream-node-max-entries"
219 218) "100"
220 219) "repl-backlog-size"
221 220) "1048576"
222 221) "maxmemory"
223 222) "0"
224 223) "hash-max-ziplist-entries"
225 224) "512"
226 225) "set-max-intset-entries"
227 226) "512"
228 227) "zset-max-ziplist-entries"
229 228) "128"
230 229) "active-defrag-ignore-bytes"
231 230) "104857600"
232 231) "hash-max-ziplist-value"
233 232) "64"
234 233) "stream-node-max-bytes"
235 234) "4096"
236 235) "zset-max-ziplist-value"
237 236) "64"
238 237) "hll-sparse-max-bytes"
239 238) "3000"
240 239) "tracking-table-max-keys"
241 240) "1000000"
242 241) "repl-backlog-ttl"
243 242) "3600"
244 243) "auto-aof-rewrite-min-size"
245 244) "67108864"
246 245) "logfile"
247 246) ""
248 247) "client-query-buffer-limit"
249 248) "1073741824"
250 249) "watchdog-period"
251 250) "0"
252 251) "dir"
253 252) "/usr/local/redis/bin"
254 253) "save"
255 254) "900 1 300 10 60 10000"
256 255) "client-output-buffer-limit"
257 256) "normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60"
258 257) "unixsocketperm"
259 258) "0"
260 259) "slaveof"
261 260) ""
262 261) "notify-keyspace-events"
263 262) ""
264 263) "bind"
265 264) "127.0.0.1"
266 265) "requirepass"
267 266) ""
268 267) "oom-score-adj-values"
269 268) "0 200 800"

View Code

Config get setting name to get a separate configuration item, such as loglevel, as follows:

1 127.0.0.1:6379> config get loglevel
2 1) "loglevel"
3 2) "notice"
4 127.0.0.1:6379> 

Config set setting name setting value, as follows:

1 127.0.0.1:6379> config set loglevel verbose
2 OK
3 127.0.0.1:6379> config get loglevel
4 1) "loglevel"
5 2) "verbose"
6 127.0.0.1:6379> 

This paper mainly describes the common configuration, more configuration, can refer toRookie course

remarks

Dongxian song

Dynasty: Song Dynasty|Author: Su Shi

When the servant was seven years old, he saw Meizhou laoni, surnamed Zhu, and forgot his name. He was 90 years old. He said to himself that he went with his master to the palace of Meng Chang, the master of Shu, and his wife, Huarui, enjoyed a cool night on the Maha pool. Zhu Ju can remember this word.
In the past 40 years, Zhu has been dead for a long time. People don’t know about this word. But if you remember the first two sentences and ponder over them in your spare time, isn’t it the order of Dongxian song? It is the cloud of feet.
 
Ice flesh and jade bone, from cool without sweat.
The water hall is full of fragrance.
Embroidered curtain open, a little moon peep at people, people are not sleeping, q (q) pillow hairpin disordered temples.
 
Up with plain hands, the court door silent, see sparse star crossing the Han River.
How about the night?
It’s three o’clock in the night, the golden wave is light, and the jade rope turns low.
But when will the west wind come,
I don’t want to change it secretly.

Recommended Today

Review of SQL Sever basic command

catalogue preface Installation of virtual machine Commands and operations Basic command syntax Case sensitive SQL keyword and function name Column and Index Names alias Too long to see? Space Database connection Connection of SSMS Connection of command line Database operation establish delete constraint integrity constraint Common constraints NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY DEFAULT […]