redis server配置,启动指令 redis-server
未指定redis.conf则使用默认的配置启动
基于redis 7.0.5
1 repl-diskless-sync-max-replicas 0
2 lazyfree-lazy-user-del no
3 port 6379
4 oom-score-adj no
5 replicaof 172.17.0.9 6379
6 min-slaves-to-write 0
7 zset-max-listpack-value 64
8 sanitize-dump-payload no
9 io-threads-do-reads no
10 zset-max-ziplist-value 64
11 tls-key-file
12 maxclients 10000
13 cluster-replica-no-failover no
14 io-threads 1
15 tls-key-file-pass
16 tcp-backlog 511
17 list-compress-depth 0
18 oom-score-adj-values 0 200 800
19 cluster-require-full-coverage yes
20 repl-backlog-size 1048576
21 acllog-max-len 128
22 masteruser
23 cluster-port 0
24 slave-announce-ip
25 stop-writes-on-bgsave-error yes
26 syslog-ident redis
27 jemalloc-bg-thread yes
28 slave-lazy-flush no
29 syslog-enabled no
30 lazyfree-lazy-user-flush no
31 active-defrag-max-scan-fields 1000
32 lfu-log-factor 10
33 tls-ca-cert-file
34 slaveof 172.17.0.9 6379
35 dynamic-hz yes
36 requirepass
37 ignore-warnings
38 maxmemory-policy noeviction
39 pidfile
40 bio_cpulist
41 loglevel notice
42 repl-diskless-sync-delay 5
43 dir /data
44 cluster-announce-hostname
45 zset-max-listpack-entries 128
46 tracking-table-max-keys 1000000
47 hash-max-ziplist-value 64
48 tls-session-cache-size 20480
49 acl-pubsub-default resetchannels
50 replica-serve-stale-data yes
51 stream-node-max-entries 100
52 replica-ignore-disk-write-errors no
53 tls-ciphers
54 maxmemory 0
55 stream-node-max-bytes 4096
56 hash-max-listpack-entries 512
57 slave-ignore-maxmemory yes
58 replica-announce-port 0
59 busy-reply-threshold 5000
60 lazyfree-lazy-server-del no
61 active-expire-effort 1
62 slave-announce-port 0
63 min-replicas-max-lag 10
64 daemonize no
65 active-defrag-threshold-upper 100
66 tls-dh-params-file
67 repl-backlog-ttl 3600
68 cluster-node-timeout 15000
69 maxmemory-samples 5
70 rdbchecksum yes
71 save 3600 1 300 100 60 10000
72 tls-cluster no
73 tls-client-cert-file
74 rdb-del-sync-files no
75 slave-serve-stale-data yes
76 unixsocketperm 0
77 bgsave_cpulist
78 cluster-config-file nodes.conf
79 cluster-allow-reads-when-down no
80 rdbcompression yes
81 unixsocket
82 client-output-buffer-limit normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60
83 cluster-announce-port 0
84 rdb-save-incremental-fsync yes
85 hll-sparse-max-bytes 3000
86 cluster-allow-pubsubshard-when-down yes
87 enable-debug-command no
88 tls-port 0
89 auto-aof-rewrite-percentage 100
90 slowlog-log-slower-than 10000
91 lua-time-limit 5000
92 propagation-error-behavior ignore
93 cluster-migration-barrier 1
94 list-max-ziplist-size -2
95 tls-prefer-server-ciphers no
96 latency-monitor-threshold 0
97 min-replicas-to-write 0
98 cluster-replica-validity-factor 10
99 aof_rewrite_cpulist
100 bind * -::*
101 slave-priority 100
102 aof-use-rdb-preamble yes
103 repl-ping-slave-period 10
104 lfu-decay-time 1
105 tls-session-cache-timeout 300
106 shutdown-timeout 10
107 repl-diskless-sync yes
108 min-slaves-max-lag 10
109 always-show-logo no
110 proc-title-template {title} {listen-addr} {server-mode}
111 cluster-announce-tls-port 0
112 tls-client-key-file-pass
113 slowlog-max-len 128
114 tls-ciphersuites
115 tls-protocols
116 latency-tracking yes
117 list-max-listpack-size -2
118 hash-max-ziplist-entries 512
119 crash-log-enabled yes
120 enable-module-command no
121 repl-diskless-load disabled
122 aof-load-truncated yes
123 logfile
124 crash-memcheck-enabled yes
125 activerehashing yes
126 socket-mark-id 0
127 cluster-allow-replica-migration yes
128 set-proc-title yes
129 replica-announce-ip
130 cluster-announce-ip
131 no-appendfsync-on-rewrite no
132 tls-session-caching yes
133 aclfile
134 replica-announced yes
135 appenddirname appendonlydir
136 repl-timeout 60
137 active-defrag-cycle-max 25
138 cluster-link-sendbuf-limit 0
139 aof-disable-auto-gc no
140 maxmemory-clients 0
141 protected-mode no
142 aof-timestamp-enabled no
143 timeout 0
144 active-defrag-ignore-bytes 104857600
145 bind-source-addr
146 replica-lazy-flush no
147 masterauth
148 cluster-preferred-endpoint-type ip
149 syslog-facility local0
150 cluster-enabled no
151 replica-read-only yes
152 latency-tracking-info-percentiles 50 99 99.9
153 appendonly no
154 dbfilename dump.rdb
155 lazyfree-lazy-eviction no
156 repl-ping-replica-period 10
157 databases 16
158 appendfilename appendonly.aof
159 tcp-keepalive 300
160 hz 10
161 notify-keyspace-events
162 zset-max-ziplist-entries 128
163 client-query-buffer-limit 1073741824
164 tls-ca-cert-dir
165 active-defrag-threshold-lower 10
166 active-defrag-cycle-min 1
167 activedefrag no
168 lazyfree-lazy-expire no
169 replica-ignore-maxmemory yes
170 repl-disable-tcp-nodelay no
171 tls-client-key-file
172 tls-auth-clients yes
173 tls-replication no
174 proto-max-bulk-len 536870912
175 aof-rewrite-incremental-fsync yes
176 appendfsync everysec
177 cluster-slave-validity-factor 10
178 server_cpulist
179 auto-aof-rewrite-min-size 67108864
180 slave-read-only yes
181 shutdown-on-sigint default
182 supervised no
183 set-max-intset-entries 512
184 disable-thp yes
185 shutdown-on-sigterm default
186 hash-max-listpack-value 64
187 cluster-announce-bus-port 0
188 enable-protected-configs no
189 replica-priority 100
190 maxmemory-eviction-tenacity 10
191 tls-cert-file
192 cluster-slave-no-failover no
具体配置项目含义参考链接redis-config-7.0.5
一般个人使用的redis-server配置,默认使用端口6379
appendonly yes
appendfsync everysec
appendfilename "appendonly.aof"
一般个人使用的sentinel配置,默认使用端口26379,sentinel模式启动命令
redis-server
# 设置主节点名 IP 端口 sentinel客观下线条件
sentinel monitor mymaster 127.0.0.1 6379 2
# 超过指定时间无回应认为down 毫秒为单位
sentinel down-after-milliseconds mymaster 60000
sentinel failover-timeout mymaster 180000
sentinel parallel-syncs mymaster 1
# 其他部分sentinel会自动进行重写
一般个人使用的cluster配置,默认使用端口6379作为客户端通讯接口,16379作为通讯总线,cluster 模式启动命令同 server,但是实例启动后需要redis-cli构建集群,完整指令如下
redis-server <path>/cluster.conf
# 构建集群关系,replicas表示从节点数目,最小规模构建一主一从,需要六个实例
redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001
127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
--cluster-replicas 1
官方github上有集群构建脚本,实质上也是以上原理 create-cluster
# 该配置同server配置,只需要配置cluster-enabled yes即可
cluster-enabled <yes/no>: 如果配置"yes"则开启集群功能,此redis实例作为集群的一个节点,否则,它是一个普通的单一的redis实例。
cluster-config-file <filename>: 注意:虽然此配置的名字叫"集群配置文件",但是此配置文件不能人工编辑,它是集群节点自动维护的文件,主要用于记录集群中有哪些节点、他们的状态以及一些持久化参数等,方便在重启时恢复这些状态。通常是在收到请求之后这个文件就会被更新。
cluster-node-timeout <milliseconds>: 这是集群中的节点能够失联的最大时间,超过这个时间,该节点就会被认为故障。如果主节点超过这个时间还是不可达,则用它的从节点将启动故障迁移,升级成主节点。注意,任何一个节点在这个时间之内如果还是没有连上大部分的主节点,则此节点将停止接收任何请求。
cluster-slave-validity-factor <factor>: 如果设置成0,则无论从节点与主节点失联多久,从节点都会尝试升级成主节点。如果设置成正数,则cluster-node-timeout乘以cluster-slave-validity-factor得到的时间,是从节点与主节点失联后,此从节点数据有效的最长时间,超过这个时间,从节点不会启动故障迁移。假设cluster-node-timeout=5,cluster-slave-validity-factor=10,则如果从节点跟主节点失联超过50秒,此从节点不能成为主节点。注意,如果此参数配置为非0,将可能出现由于某主节点失联却没有从节点能顶上的情况,从而导致集群不能正常工作,在这种情况下,只有等到原来的主节点重新回归到集群,集群才恢复运作。
cluster-migration-barrier <count>:主节点需要的最小从节点数,只有达到这个数,主节点失败时,它从节点才会进行迁移。更详细介绍可以看本教程后面关于副本迁移到部分。
cluster-require-full-coverage <yes/no>:在部分key所在的节点不可用时,如果此参数设置为"yes"(默认值), 则整个集群停止接受操作;如果此参数设置为"no",则集群依然为可达节点上的key提供读操作。
# 其他的配置项同server配置
...
注意集群模式节点使用时使用redis-cli -c模式启动
Q.E.D.