目录
- 说明
- 文件概况
- 文件所含节点
- 0.开始
- 1.Includes
- 2.Modules
- 3.NetWork
- 4.General
- 5.Snapshotting
- 6.Replication
- 7.Security
- 8.Clients
- 9.Memory Management
- 10.Lazy Freeing
- 11.Appned only mode
- 12.lua scripting
- 13.redis cluster
- 14.CLUSTER DOCKER/NAT support
- 15.Slow Log
- 16.LATENCY MONITOR
- 17.EVENT NOTIFICATION
- 18.ADVANCED CONFIG
- 19.ACTIVE DEFRAGMENTATION
- 总结
- 第一次梳理
说明
解读官方配置文件,也可以说是翻译。
借此机会,深入了解Redis。
旨在梳理一遍,不会逐行翻译。大体根据自己的理解,记录重要的点。
文件概况
- lines: 1317
1 | wc -l redis.conf |
- words: 10187
1 | wc -w redis.conf |
文件所含节点
文档所述,共包含8个节点。分别如下
0.开始
使配置文件生效,必须采用特别的启动方式
1 | ./redis-server /path/to/redis.conf |
关于内存单位的说明
1 | 1k == 1000 bytes |
结论1:1k 和 1kb是不一样的,1000 和 1024 的差距;2:以 1000 和 1024 的次方增长。
单位不区分大小写,如 1GB 1gB 1Gb是等同的。
1.Includes
配置文件嵌套,适合一些定制化的配置,配置文件又可以include配置文件。
1 | include /path/to/local.conf |
2.Modules
Load modules at startup.
1 | loadmodule /path/to/my_module.so |
load local native module
3.NetWork
- bind
if no bind configuration directive, Redis listens for connections from all the network interfaces auailable on the server.
examples:
1 | bind 192.168.1.100 10.0.0.1 |
if Redis directly exposed to internet, binding to all interface is dangerous.
1 | # uncomment following bin directive, Redis accept connections only from clients running into same computer it is running. comment..., it is dangerous if Redis is exposed to internet. |
- protected-mode
与bind配合使用,如果bind配置了ip,则只有ip内的connect client才被accept。默认开启
1 | protected-mode yes |
- port
if port 0 is specified Redis will not listen on TCP scoket.
1 | port 6379 |
- tcp-backlog
TCP listen() log.
1 | tcp-backlog 511 |
- Unix socket
unix socket used to listen for incoming connections.
no default
1 | unixsocket /tmp/redis.sock |
- timeout
close connection after client idle for N seconds
0 disable
1 | timeout 0 |
- tcp-keepalive
period used to send TCP ACKs to client.
1 | tcp-keepalive 300 |
4.General
- daemonize
run as a daemon
1 | daemonize yes |
- supervised
- supervised no
- supervised upstart
- supervised systemd
- supervised auto
1 | supervised no |
- pidfile
若指定该文件,则会自动创建、自动remove;non daemonized, no pidfile if none is specified following. daemonized, if non specified pipfile, it has default “/var/run/redis.pid”.
1 | pidfile /var/run/redis_6379.pip |
- loglevel
- debug
- verbose
- notice
- warning
1 | loglevel notice |
- logfile
empty string, logs will be send to /dev/null
1 | logfile "/usr/local/redis/log/redis.log" |
- syslog-enable
1 | syslog-enable no |
- syslog-ident
syslog identity
1 | syslog-ident redis |
- syslog-facility
must be user or between LOCAL0-LOCAL7
1 | syslog-facility local0 |
- databases
default 0
1 | databases 16 |
- always-show-logo
1 | always-show-logo yes |
5.Snapshotting
- save
save db if both seconds and write operations against the db occurred.
Save db on disk:
save <seconds> <changes>
remove all previously configured save points
save ""
1 | # 900 sec at least 1 key changed |
- stop-writes-on-bgsave-error
1 | stop-writes-on-bgsave-error yes |
- rdbcompression
compress string objects using LZF when dump .rdb databases.
1 | rdbcompression yes |
- rdbchecksum
1 | rdbchecksum yes |
- dbfilename
1 | dbfilename dump.rdb |
- dir
- Important. if not specified, db file or append only file will store in a directory you just opened. create so many uselessfile.
- working directory store db.
- .rdb and .aof file store in.
- specify a directory, not file name.
1 | dir /usr/local/redis/data/ |
6.Replication
- Master-Slave replication
1 | slaveof <masterip> <masterport> |
- master is password protected
1 | masterauth <master-password> |
- slave loses its connection with the master
- yes: slave still reply to client requests
- no: slave will reply with error “SYNC with master in progress”
1 | slave-serve-stale-data yes |
- slave instance to accept writes or not
1 | slave-read-only yes |
- Replication SYNC strategy: disk or socket
- 1.Disk-backed: Redis master creates a new process that writes the RDB file on disk. Later the file is transferred by the parent process to the slaves incrementally
- 2.Diskless: Redis master creates a new process that directly writes the RDB file to slave sockets, without touching the disk
1 | repl-diskless-sync no |
- delay the server waits
1 | repl-diskless-sync-delay 5 |
- Slaves send PINGs to server in a predefined interval
1 | repl-ping-slave-period 10 |
- replication timeout
greater than the value specified for repl-ping-slave-period
1 | repl-timeout 60 |
- TCP_NODELAY on the slave socket after SYNC
- 1.”yes” Redis will use a smaller number of TCP packets and less bandwidth to send data to slaves
- 2.”no” the delay for data to appear on the slave side will be reduced but more bandwidth will be used for replication
1 | repl-disable-tcp-nodelay no |
replication backlog size
- buffer
- slaves are disconnected
- full resync is not needed, but a partial resync is enough, just passing the portion of data the slave missed while disconnected.
1 | repl-backlog-size 1mb |
- master has no longer connected slaves for some time, the backlog will be freed
seconds that need to elapse, starting from the time the last slave disconnected, for the backlog buffer to be freed.
1 | # repl-backlog-ttl 3600 |
- slave priority
- master no longer working, select from slave as master.选举
- 优先级,数字越小越考前,当然0不能被选做master
1 | slave-priority 100 |
- master to stop accepting writes if there are less than N slaves connected
1 | # min-slaves-to-write 3 |
- master is able to list the address and port of the attached slaves in different ways
1 | # slave-announce-ip 5.5.5.5 |
7.Security
- Require clients issue AUTH
useful in environments in which you do not trust others. stay commented
1 | # requirepass foobared |
- command renaming
dangerous commands in shared environment.
1 | # Example: |
8.Clients
- max number of connected clients at the same time.
1 | # maxclients 10000 |
9.Memory Management
- max memory
1 | # maxmemory <bytes> |
- max memory policy noeviction
maxmemory policy: how Redis will select what to remove when maxmemory reached.
# policies:
- # volatile-lru -> Evict using approximated LRU among the keys with an expire set.
- # allkeys-lru -> Evict any key using approximated LRU.
- # volatile-lfu -> Evict using approximated LFU among the keys with an expire set.
- # allkeys-lfu -> Evict any key using approximated LFU.
- # volatile-random -> Remove a random key among the ones with an expire set.
- # allkeys-random -> Remove a random key, any key.
- # volatile-ttl -> Remove the key with the nearest expire time (minor TTL)
- # noeviction -> Don't evict anything, just return an error on write operations.
- #
- # LRU means Least Recently Used
- # LFU means Least Frequently Used
1 | maxmemory-policy noeviction |
- max memory samples
1 | # maxmemory-samples 5 |
10.Lazy Freeing
two primitives to delete keys. one: del, blocking deletion of object. two: non blocking deletion, such as
unlink
and async option offlushall
,flushdb
. reclaim memory in background.
release memory in a non-blocking way like if UNLINK was called, using following configuration directives:
1 | lazyfree-lazy-eviction no |
11.Appned only mode
- appendonly yes or no
- asynchronously dumps dataset on disk.
- can lose just one second of wirtes
1 | appendonly yes |
- append filename
append only file store in dir
1 | appendfilename "appendonly.aof" |
- appendfsync
1 | # appendfsync always |
- no appendfsync on rewrite
1 | no-appendfsync-on-rewrite yes |
- automatic rewrite of the append only file
1 | auto-aof-rewrite-percentage 100 |
- aof load truncated
1 | aof-load-truncated yes |
- aof use rdb preamble
1 | aof-use-rdb-preamble no |
12.lua scripting
- max execution time of a lua script in milliseconds.
set 0 or negative value for unlimited execution without warnings.
1 | lua-time-limit 5000 |
13.redis cluster
- cluster enable
start a Redis instance as a cluster node enable the cluster.
1 | # cluster-enable yes |
- cluster config file
1 | cluster-config-file nodes-6379.conf |
- cluster node timeout
1 | cluster-node-timeout 15000 |
- cluster slave validity factor
1 | # cluster-slave-validity-factor 10 |
- cluster migration barrier
1 | cluster-migration-barrier 1 |
- cluster require full coverage
1 | cluster-require-full-coverage yes |
- cluster slave no failover
- 故障转移?
- prevents slaves from trying to failover its master during master failures.
1 | cluster-slave-no-failover |
14.CLUSTER DOCKER/NAT support
Redis Cluster nodes address discovery fails. A static configuration where each node knows its public address.
- cluster-announce-ip
- cluster-announce-port
- cluster-announce-bus-port
1 | # cluster-announce-ip |
15.Slow Log
- execution time, in microseconds
1 | slowlog-log-slower-than 10000 |
- length of the slow log
1 | slowlog-max-len 128 |
16.LATENCY MONITOR
- 隐形监控
- latency-monitor-threshold
- time equal or greater than
, system will operate in order to collect data related to possible sources of latency of a Redis instance. - 0: turn off
1 | latency-monitor-threshold 0 |
17.EVENT NOTIFICATION
- notify Pub/Sub clients about events happening in the key space.
- document: http://redis.io/topics/notifications
1 | notify-keyspace-events "" |
18.ADVANCED CONFIG
高级配置?
- hash encoded using memory efficient data structure. biggest entyr does not exceed a given threshold.
1 | hash-max-ziplist-entries 512 |
- list-max-ziplist-size
1 | list-max-ziplist-size -2 |
- lsit-compress-depth
1 | lsit-compress-depth 0 |
- set-max-intset-entries
1 | set-max-intset-entries 512 |
1 | zset-max-ziplist-entries 128 |
1 | hll-sparse-max-bytes 3000 |
1 | activerehashing yes |
1 | client-output-buffer-limit normal 0 0 0 |
1 | hz 10 |
1 | apf-rewrite-incremental-fsync yes |
19.ACTIVE DEFRAGMENTATION
- experimental
- 内存碎片重组、压缩
- activedefrag yes or no
1 | # activedefrag yes |
- active-defrag-ignore-bytes
1 | # active-defrag-ignore-bytes 100mb |
- active-defrag-threshold-lower
1 | # active-defrag-threshold-lower 10 |
- active-defrag-threshold-upper
1 | # active-defrag-threshold-upper 100 |
- active-defrag-cycle-min
1 | # active-defrag-cycle-min 25 |
- active-defrag-cycle-max
1 | # active-defrag-cycle-max 75 |
总结
第一次梳理
本次只是简单的过一遍,在后面用到的过程中,有个印象,及时的找到需要的配置。
很多属性还没有用过,需要在项目中或者自己创造条件运用,测试。
- 本文作者: Linking
- 本文链接: https://linking.fun/2019/12/25/redis-conf-readthrough/
- 版权声明: 版权所有,转载请注明出处!