本站总访问量 redis单节点+哨兵集群搭建 - Jerry的小站

Jerry Gao

上帝就是真理,真理就是上帝

Kubernetes 一键部署

Kubernetes 单节点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: redis-data
namespace: stable-db
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: standard-rwo
volumeMode: Filesystem
---
kind: ConfigMap
apiVersion: v1
metadata:
name: redis-config
namespace: stable-db
data:
default.conf: |-
bind 0.0.0.0
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile ""
loglevel notice
logfile ""
databases 16
always-show-logo yes
save ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis
maxclients 10000
# maxmemory
maxmemory-policy noeviction
maxmemory-samples 5
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
client-query-buffer-limit 1gb
proto-max-bulk-len 512mb
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
# lfu-log-factor 10
# lfu-decay-time 1
requirepass <password>
user.conf: |-
# redis.conf
appendonly yes
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: redis
namespace: stable-db
labels:
app: redis
spec:
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
volumes:
- name: redis-data
persistentVolumeClaim:
claimName: redis-data
- name: redis-config
configMap:
name: redis-config
defaultMode: 420
containers:
- name: redis
image: redis:6.0.9-alpine
command:
- /bin/sh
- -c
- |
rm -rf /redis/data/lost+found
args="
--include /conf/default.conf
--include /conf/user.conf
"
redis-server $args
ports:
- name: redis
containerPort: 6379
protocol: TCP
resources:
limits:
cpu: "2"
memory: 4Gi
ephemeral-storage: 5Gi
requests:
cpu: "2"
memory: 4Gi
ephemeral-storage: 5Gi
livenessProbe:
tcpSocket:
port: 6379
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
readinessProbe:
tcpSocket:
port: 6379
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
startupProbe:
tcpSocket:
port: 6379
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
volumeMounts:
- name: redis-data
mountPath: /data/redis
- name: redis-config
mountPath: /conf
readOnly: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent

哨兵集群

master 节点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: redis-data-master
namespace: stable-db
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: standard-rwo
volumeMode: Filesystem
---
kind: ConfigMap
apiVersion: v1
metadata:
name: redis-config-master
namespace: stable-db
data:
default.conf: |-
bind 0.0.0.0
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile ""
loglevel notice
logfile ""
databases 16
always-show-logo yes
save ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis
maxclients 10000
# maxmemory
maxmemory-policy noeviction
maxmemory-samples 5
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
client-query-buffer-limit 1gb
proto-max-bulk-len 512mb
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
# lfu-log-factor 10
# lfu-decay-time 1
requirepass <password>
user.conf: |-
# redis.conf
appendonly yes
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: redis-master
namespace: stable-db
labels:
app: redis-master
spec:
replicas: 1
selector:
matchLabels:
app: redis-master
template:
metadata:
labels:
app: redis-master
spec:
volumes:
- name: redis-data-master
persistentVolumeClaim:
claimName: redis-data-master
- name: redis-config-master
configMap:
name: redis-config-master
defaultMode: 420
containers:
- name: redis-master
image: redis:6.0.8
env:
- name: ANNOUNCE_IP
value: <master IP>
- name: ANNOUNCE_PORT
value: <master Port>
command:
- /bin/sh
- -c
- |
rm -rf /redis/data/lost+found
args="
--include /conf/default.conf
--include /conf/user.conf
--cluster-announce-bus-port <master Port>
--cluster-announce-ip <master IP>
"
redis-server $args
ports:
- name: redis
containerPort: 6379
protocol: TCP
resources:
limits:
cpu: "2"
memory: 4Gi
ephemeral-storage: 5Gi
requests:
cpu: "2"
memory: 4Gi
ephemeral-storage: 5Gi
livenessProbe:
tcpSocket:
port: 6379
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
readinessProbe:
tcpSocket:
port: 6379
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
startupProbe:
tcpSocket:
port: 6379
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
volumeMounts:
- name: redis-data-master
mountPath: /data/redis
- name: redis-config-master
mountPath: /conf
readOnly: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
---
apiVersion: v1
kind: Service
metadata:
name: redis-master
namespace: stable-db
annotations:
cloud.google.com/l4-rbs: "enabled"
labels:
app: redis-master
spec:
loadBalancerIP: <master IP>
type: LoadBalancer
externalTrafficPolicy: Cluster
ports:
- port: <master Port>
nodePort: <master Port>
targetPort: 6379
protocol: TCP
selector:
app: redis-master

slave 节点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: redis-data-slave
namespace: stable-db
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: standard-rwo
volumeMode: Filesystem
---
kind: ConfigMap
apiVersion: v1
metadata:
name: redis-config-slave
namespace: stable-db
data:
default.conf: |-
bind 0.0.0.0
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile ""
loglevel notice
logfile ""
databases 16
always-show-logo yes
save ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis
maxclients 10000
# maxmemory
maxmemory-policy noeviction
maxmemory-samples 5
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
client-query-buffer-limit 1gb
proto-max-bulk-len 512mb
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
# lfu-log-factor 10
# lfu-decay-time 1
requirepass <password>
masterauth <master password>
user.conf: |-
# redis.conf
appendonly yes
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: redis-slave
namespace: stable-db
labels:
app: redis-slave
spec:
replicas: 1
selector:
matchLabels:
app: redis-slave
template:
metadata:
labels:
app: redis-slave
spec:
volumes:
- name: redis-data-slave
persistentVolumeClaim:
claimName: redis-data-slave
- name: redis-config-slave
configMap:
name: redis-config-slave
defaultMode: 420
containers:
- name: redis-slave
image: redis:6.0.8
env:
- name: ANNOUNCE_IP
value: <master Ip>
- name: ANNOUNCE_PORT
value: <master Port>
command:
- /bin/sh
- -c
- |
rm -rf /redis/data/lost+found
args="
--include /conf/default.conf
--include /conf/user.conf
--cluster-announce-bus-port <master Port>
--cluster-announce-ip <master Ip>
--slaveof <master Ip> <master Port>
"
redis-server $args
ports:
- name: redis
containerPort: 6379
protocol: TCP
resources:
limits:
cpu: "2"
memory: 4Gi
ephemeral-storage: 5Gi
requests:
cpu: "2"
memory: 4Gi
ephemeral-storage: 5Gi
livenessProbe:
tcpSocket:
port: 6379
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
readinessProbe:
tcpSocket:
port: 6379
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
startupProbe:
tcpSocket:
port: 6379
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
volumeMounts:
- name: redis-data-slave
mountPath: /data/redis
- name: redis-config-slave
mountPath: /conf
readOnly: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
---
apiVersion: v1
kind: Service
metadata:
name: redis-slave
namespace: stable-db
annotations:
cloud.google.com/l4-rbs: "enabled"
labels:
app: redis-slave
spec:
loadBalancerIP: <slave IP>
type: LoadBalancer
externalTrafficPolicy: Cluster
ports:
- port: <slave Port>
nodePort: <slave Port>
targetPort: 6379
protocol: TCP
selector:
app: redis-slave

Sentinel 节点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: redis-data-sentinel
namespace: stable-db
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: standard-rwo
volumeMode: Filesystem
---
kind: ConfigMap
apiVersion: v1
metadata:
name: redis-config-sentinel
namespace: stable-db
data:
default.conf: |-
bind 0.0.0.0
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile ""
loglevel notice
logfile ""
databases 16
always-show-logo yes
save ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis
maxclients 10000
# maxmemory
maxmemory-policy noeviction
maxmemory-samples 5
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
client-query-buffer-limit 1gb
proto-max-bulk-len 512mb
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
# lfu-log-factor 10
# lfu-decay-time 1
sentinel monitor redis-master-0 <master Ip> <master Port> 1
sentinel down-after-milliseconds redis-master-0 1000
sentinel auth-pass redis-master-0 <password>
sentinel failover-timeout redis-master-0 30000
sentinel parallel-syncs redis-master-0 1
sentinel announce-ip <master Ip>
requirepass <password>
user.conf: |-
# redis.conf
appendonly yes
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: redis-sentinel
namespace: stable-db
labels:
app: redis-sentinel
spec:
replicas: 1
selector:
matchLabels:
app: redis-sentinel
template:
metadata:
labels:
app: redis-sentinel
spec:
volumes:
- name: redis-data-sentinel
persistentVolumeClaim:
claimName: redis-data-sentinel
- name: redis-config-sentinel
configMap:
name: redis-config-sentinel
defaultMode: 493
containers:
- name: redis-sentinel
image: redis:6.0.8
env:
- name: ANNOUNCE_IP
value: <master IP>
- name: ANNOUNCE_PORT
value: <master Port>
command:
- /bin/sh
- -c
- |
mkdir -p /conf
cp /tmp/default.conf /conf/default.conf
chmod 777 /conf/default.conf
args="
/conf/default.conf
"
redis-sentinel $args
ports:
- name: redis
containerPort: 6379
protocol: TCP
resources:
limits:
cpu: "2"
memory: 4Gi
ephemeral-storage: 5Gi
requests:
cpu: "2"
memory: 4Gi
ephemeral-storage: 5Gi
livenessProbe:
tcpSocket:
port: 6379
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
readinessProbe:
tcpSocket:
port: 6379
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
startupProbe:
tcpSocket:
port: 6379
initialDelaySeconds: 10
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
volumeMounts:
- name: redis-data-sentinel
mountPath: /data/redis
- name: redis-config-sentinel
mountPath: /tmp
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
---
apiVersion: v1
kind: Service
metadata:
name: redis-sentinel
namespace: stable-db
annotations:
cloud.google.com/l4-rbs: "enabled"
labels:
app: redis-sentinel
spec:
loadBalancerIP: <master IP>
type: LoadBalancer
externalTrafficPolicy: Cluster
ports:
- port: <master Port>
nodePort: <master Port>
targetPort: 6379
protocol: TCP
selector:
app: redis-sentinel

docker compose 部署

单节点

配置文件:

  • conf/default.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
bind 0.0.0.0
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile ""
loglevel notice
logfile ""
databases 16
always-show-logo yes
save ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis
maxclients 10000
# maxmemory
maxmemory-policy noeviction
maxmemory-samples 5
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
client-query-buffer-limit 1gb
proto-max-bulk-len 512mb
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
# lfu-log-factor 10
# lfu-decay-time 1
requirepass <password>
  • conf/user.conf
1
2
# redis.conf
appendonly yes

docker compose:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
version: "3"
services:
redis:
image: redis:6.0.9-alpine
container_name: redis
restart: always
ports:
- "6379:6379"
volumes:
- /data/redis:/data/redis
- ./conf:/conf
deploy:
resources:
limits:
cpus: "2"
memory: 4G
reservations:
cpus: "2"
memory: 4G
entrypoint:
- /bin/sh
- -c
- redis-server --include /conf/default.conf --include /conf/user.conf

哨兵集群

master配置

  • conf/default.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
bind 0.0.0.0
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile ""
loglevel notice
logfile ""
databases 16
always-show-logo yes
save ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis
maxclients 10000
# maxmemory
maxmemory-policy noeviction
maxmemory-samples 5
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
client-query-buffer-limit 1gb
proto-max-bulk-len 512mb
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
# lfu-log-factor 10
# lfu-decay-time 1
requirepass <password>
  • conf/user.conf
1
2
# redis.conf
appendonly yes

slave 配置

  • conf/default.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
bind 0.0.0.0
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile ""
loglevel notice
logfile ""
databases 16
always-show-logo yes
save ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis
maxclients 10000
# maxmemory
maxmemory-policy noeviction
maxmemory-samples 5
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
client-query-buffer-limit 1gb
proto-max-bulk-len 512mb
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
# lfu-log-factor 10
# lfu-decay-time 1
requirepass <password>
masterauth <master password>
  • conf/user.conf
1
2
# redis.conf
appendonly yes

Sentinel 配置

  • conf/default.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
bind 0.0.0.0
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile ""
loglevel notice
logfile ""
databases 16
always-show-logo yes
save ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis
maxclients 10000
# maxmemory
maxmemory-policy noeviction
maxmemory-samples 5
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
client-query-buffer-limit 1gb
proto-max-bulk-len 512mb
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
# lfu-log-factor 10
# lfu-decay-time 1
sentinel monitor redis-master-0 <master IP> 16379 1
sentinel down-after-milliseconds redis-master-0 1000
sentinel auth-pass redis-master-0 <password>
sentinel failover-timeout redis-master-0 30000
sentinel parallel-syncs redis-master-0 1
sentinel announce-ip <master IP>
requirepass <password>
  • conf/user.conf
1
2
# redis.conf
appendonly yes

docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
version: "3"
services:
redis-master:
image: redis:6.0.8
container_name: redis-master
privileged: true
restart: always
ports:
- "<master Port>:6379"
volumes:
- ./master/conf:/conf
- /data/redisSentinelCluster/master:/data/redis
environment:
- ANNOUNCE_IP=<master Ip>
- ANNOUNCE_PORT=<master Port>
entrypoint:
- /bin/sh
- -c
- redis-server --include /conf/default.conf --include /conf/user.conf --cluster-announce-bus-port <master Port> --cluster-announce-ip <master Ip>
deploy:
resources:
limits:
cpus: "1"
memory: 1G
reservations:
cpus: "1"
memory: 1G

redis-slave:
image: redis:6.0.8
container_name: redis-slave
privileged: true
restart: always
ports:
- "<slave Port>:6379"
volumes:
- ./slave/conf:/conf
- /data/redisSentinelCluster/slave:/data/redis
environment:
- ANNOUNCE_IP=<master Ip>
- ANNOUNCE_PORT=<master Port>
entrypoint:
- /bin/sh
- -c
- redis-server --include /conf/default.conf --include /conf/user.conf --cluster-announce-bus-port <slave Port> --cluster-announce-ip <master Ip> --slaveof <master Ip> <master Port>
deploy:
resources:
limits:
cpus: "1"
memory: 1G
reservations:
cpus: "1"
memory: 1G
depends_on:
- redis-master

redis-sentinel:
image: redis:6.0.8
container_name: redis-sentinel
privileged: true
restart: always
ports:
- "<sentinel Port>:6379"
volumes:
- ./sentinel/conf:/conf
- /data/redisSentinelCluster/sentinel:/data/redis
environment:
- ANNOUNCE_IP=<master Ip>
- ANNOUNCE_PORT=<master Port>
entrypoint:
- /bin/sh
- -c
- redis-sentinel /conf/default.conf
deploy:
resources:
limits:
cpus: "1"
memory: 1G
reservations:
cpus: "1"
memory: 1G
depends_on:
- redis-master
- redis-slave

评论