-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose-sentinel.yml
More file actions
289 lines (273 loc) · 7.27 KB
/
docker-compose-sentinel.yml
File metadata and controls
289 lines (273 loc) · 7.27 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
version: '3.8'
# Redis 哨兵模式部署配置(高性能优化版)
# 架构: 1 主 2 从 + 3 哨兵
# 性能目标: 50000 QPS(Redis 单机极限的 50%)
# 高可用: 主节点故障时,哨兵自动选举新主节点(30秒内)
services:
# ==================== Redis 节点 ====================
# Redis 主节点(高性能优化)
redis-master:
image: redis:7-alpine
container_name: huxirating-redis-master
command: >
redis-server
--port 6379
--bind 0.0.0.0
--requirepass huxirating123
--masterauth huxirating123
--appendonly yes
--appendfsync everysec
--save 900 1
--save 300 10
--save 60 10000
--maxmemory 2gb
--maxmemory-policy allkeys-lru
--tcp-backlog 511
--tcp-keepalive 300
--hz 10
--dynamic-hz yes
--logfile /data/master.log
ports:
- "6379:6379"
volumes:
- redis-master-data:/data
networks:
- redis-sentinel
healthcheck:
test: ["CMD", "redis-cli", "-a", "huxirating123", "ping"]
interval: 5s
timeout: 3s
retries: 5
restart: on-failure
# Redis 从节点 1(高性能优化)
redis-slave-1:
image: redis:7-alpine
container_name: huxirating-redis-slave-1
command: >
redis-server
--port 6379
--bind 0.0.0.0
--requirepass huxirating123
--masterauth huxirating123
--replicaof redis-master 6379
--appendonly yes
--appendfsync everysec
--maxmemory 2gb
--maxmemory-policy allkeys-lru
--tcp-backlog 511
--tcp-keepalive 300
--hz 10
--dynamic-hz yes
--logfile /data/slave1.log
ports:
- "6380:6379"
volumes:
- redis-slave-1-data:/data
networks:
- redis-sentinel
depends_on:
redis-master:
condition: service_healthy
healthcheck:
test: ["CMD", "redis-cli", "-a", "huxirating123", "ping"]
interval: 5s
timeout: 3s
retries: 5
restart: on-failure
# Redis 从节点 2(高性能优化)
redis-slave-2:
image: redis:7-alpine
container_name: huxirating-redis-slave-2
command: >
redis-server
--port 6379
--bind 0.0.0.0
--requirepass huxirating123
--masterauth huxirating123
--replicaof redis-master 6379
--appendonly yes
--appendfsync everysec
--maxmemory 2gb
--maxmemory-policy allkeys-lru
--tcp-backlog 511
--tcp-keepalive 300
--hz 10
--dynamic-hz yes
--logfile /data/slave2.log
ports:
- "6381:6379"
volumes:
- redis-slave-2-data:/data
networks:
- redis-sentinel
depends_on:
redis-master:
condition: service_healthy
healthcheck:
test: ["CMD", "redis-cli", "-a", "huxirating123", "ping"]
interval: 5s
timeout: 3s
retries: 5
restart: on-failure
# ==================== Sentinel 哨兵节点 ====================
# 哨兵节点 1
redis-sentinel-1:
image: redis:7-alpine
container_name: huxirating-redis-sentinel-1
command: >
redis-sentinel
/etc/redis/sentinel.conf
--sentinel
--port 26379
--bind 0.0.0.0
ports:
- "26379:26379"
volumes:
- ./redis-sentinel/sentinel1.conf:/etc/redis/sentinel.conf:ro
- redis-sentinel-1-data:/data
networks:
- redis-sentinel
depends_on:
redis-master:
condition: service_healthy
redis-slave-1:
condition: service_healthy
redis-slave-2:
condition: service_healthy
restart: on-failure
# 哨兵节点 2
redis-sentinel-2:
image: redis:7-alpine
container_name: huxirating-redis-sentinel-2
command: >
redis-sentinel
/etc/redis/sentinel.conf
--sentinel
--port 26379
--bind 0.0.0.0
ports:
- "26380:26379"
volumes:
- ./redis-sentinel/sentinel2.conf:/etc/redis/sentinel.conf:ro
- redis-sentinel-2-data:/data
networks:
- redis-sentinel
depends_on:
redis-master:
condition: service_healthy
redis-slave-1:
condition: service_healthy
redis-slave-2:
condition: service_healthy
restart: on-failure
# 哨兵节点 3
redis-sentinel-3:
image: redis:7-alpine
container_name: huxirating-redis-sentinel-3
command: >
redis-sentinel
/etc/redis/sentinel.conf
--sentinel
--port 26379
--bind 0.0.0.0
ports:
- "26381:26379"
volumes:
- ./redis-sentinel/sentinel3.conf:/etc/redis/sentinel.conf:ro
- redis-sentinel-3-data:/data
networks:
- redis-sentinel
depends_on:
redis-master:
condition: service_healthy
redis-slave-1:
condition: service_healthy
redis-slave-2:
condition: service_healthy
restart: on-failure
# ==================== 应用服务 ====================
app:
build: .
container_name: huxirating-backend
ports:
- "8081:8081"
environment:
SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/huxirating?allowPublicKeyRetrieval=true&useSSL=false
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_PASSWORD: 12345678
# Redis 哨兵模式配置
SPRING_REDIS_HOST: localhost # 单机模式备用
SPRING_REDIS_PORT: 6379
SPRING_REDIS_PASSWORD: huxirating123
SPRING_REDIS_SENTINEL_ENABLED: "true"
SPRING_REDIS_SENTINEL_MASTER: mymaster
SPRING_REDIS_SENTINEL_NODES: redis-sentinel-1:26379,redis-sentinel-2:26379,redis-sentinel-3:26379
# RabbitMQ
SPRING_RABBITMQ_HOST: rabbitmq
SPRING_RABBITMQ_PORT: 5672
SPRING_RABBITMQ_USERNAME: guest
SPRING_RABBITMQ_PASSWORD: guest
networks:
- redis-sentinel
depends_on:
redis-master:
condition: service_healthy
redis-slave-1:
condition: service_healthy
redis-slave-2:
condition: service_healthy
redis-sentinel-1:
condition: service_started
redis-sentinel-2:
condition: service_started
redis-sentinel-3:
condition: service_started
restart: on-failure
# ==================== 其他服务 ====================
mysql:
image: mysql:8.0
container_name: huxirating-mysql
environment:
MYSQL_ROOT_PASSWORD: 12345678
MYSQL_DATABASE: huxirating
ports:
- "3306:3306"
volumes:
- mysql-data:/var/lib/mysql
- ./src/main/resources/db/huxirating.sql:/docker-entrypoint-initdb.d/init.sql
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
retries: 5
networks:
- redis-sentinel
rabbitmq:
image: rabbitmq:3-management-alpine
container_name: huxirating-rabbitmq
ports:
- "5672:5672"
- "15672:15672"
environment:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
volumes:
- rabbitmq-data:/var/lib/rabbitmq
healthcheck:
test: ["CMD", "rabbitmq-diagnostics", "check_running"]
interval: 10s
retries: 5
networks:
- redis-sentinel
networks:
redis-sentinel:
driver: bridge
volumes:
redis-master-data:
redis-slave-1-data:
redis-slave-2-data:
redis-sentinel-1-data:
redis-sentinel-2-data:
redis-sentinel-3-data:
mysql-data:
rabbitmq-data: