Repository navigation
Expand file tree
/
Copy pathdocker-compose.cluster.yml
More file actions
463 lines (435 loc) · 12.9 KB
/
Copy pathdocker-compose.cluster.yml
File metadata and controls
463 lines (435 loc) · 12.9 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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
version: '3.8'
networks:
lufy-cluster:
driver: bridge
ipam:
config:
- subnet: 172.20.0.0/16
volumes:
redis-cluster-data:
mongodb-rs-data-1:
mongodb-rs-data-2:
mongodb-rs-data-3:
etcd-cluster-data-1:
etcd-cluster-data-2:
etcd-cluster-data-3:
services:
# Redis 集群部署 (6节点:3主3从)
redis-cluster-1:
image: redis:7-alpine
container_name: lufy-redis-cluster-1
ports:
- "7000:6379"
volumes:
- ./redis-cluster/redis.conf:/usr/local/etc/redis/redis.conf
command: redis-server /usr/local/etc/redis/redis.conf --port 6379 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes
networks:
lufy-cluster:
ipv4_address: 172.20.1.1
redis-cluster-2:
image: redis:7-alpine
container_name: lufy-redis-cluster-2
ports:
- "7001:6379"
volumes:
- ./redis-cluster/redis.conf:/usr/local/etc/redis/redis.conf
command: redis-server /usr/local/etc/redis/redis.conf --port 6379 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes
networks:
lufy-cluster:
ipv4_address: 172.20.1.2
redis-cluster-3:
image: redis:7-alpine
container_name: lufy-redis-cluster-3
ports:
- "7002:6379"
volumes:
- ./redis-cluster/redis.conf:/usr/local/etc/redis/redis.conf
command: redis-server /usr/local/etc/redis/redis.conf --port 6379 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes
networks:
lufy-cluster:
ipv4_address: 172.20.1.3
redis-cluster-4:
image: redis:7-alpine
container_name: lufy-redis-cluster-4
ports:
- "7003:6379"
volumes:
- ./redis-cluster/redis.conf:/usr/local/etc/redis/redis.conf
command: redis-server /usr/local/etc/redis/redis.conf --port 6379 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes
networks:
lufy-cluster:
ipv4_address: 172.20.1.4
redis-cluster-5:
image: redis:7-alpine
container_name: lufy-redis-cluster-5
ports:
- "7004:6379"
volumes:
- ./redis-cluster/redis.conf:/usr/local/etc/redis/redis.conf
command: redis-server /usr/local/etc/redis/redis.conf --port 6379 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes
networks:
lufy-cluster:
ipv4_address: 172.20.1.5
redis-cluster-6:
image: redis:7-alpine
container_name: lufy-redis-cluster-6
ports:
- "7005:6379"
volumes:
- ./redis-cluster/redis.conf:/usr/local/etc/redis/redis.conf
command: redis-server /usr/local/etc/redis/redis.conf --port 6379 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 5000 --appendonly yes
networks:
lufy-cluster:
ipv4_address: 172.20.1.6
# Redis 集群初始化
redis-cluster-init:
image: redis:7-alpine
container_name: lufy-redis-cluster-init
depends_on:
- redis-cluster-1
- redis-cluster-2
- redis-cluster-3
- redis-cluster-4
- redis-cluster-5
- redis-cluster-6
command: >
sh -c "
sleep 10 &&
redis-cli --cluster create
172.20.1.1:6379 172.20.1.2:6379 172.20.1.3:6379
172.20.1.4:6379 172.20.1.5:6379 172.20.1.6:6379
--cluster-replicas 1 --cluster-yes
"
networks:
- lufy-cluster
# MongoDB 副本集部署 (3节点)
mongodb-rs-1:
image: mongo:6.0
container_name: lufy-mongodb-rs-1
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password123
volumes:
- mongodb-rs-data-1:/data/db
- ./mongodb-cluster/mongod.conf:/etc/mongod.conf
- ./scripts/init-replica-set.js:/docker-entrypoint-initdb.d/init-replica-set.js
command: mongod --config /etc/mongod.conf --replSet rs0
networks:
lufy-cluster:
ipv4_address: 172.20.2.1
mongodb-rs-2:
image: mongo:6.0
container_name: lufy-mongodb-rs-2
ports:
- "27018:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password123
volumes:
- mongodb-rs-data-2:/data/db
- ./mongodb-cluster/mongod.conf:/etc/mongod.conf
command: mongod --config /etc/mongod.conf --replSet rs0
networks:
lufy-cluster:
ipv4_address: 172.20.2.2
mongodb-rs-3:
image: mongo:6.0
container_name: lufy-mongodb-rs-3
ports:
- "27019:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password123
volumes:
- mongodb-rs-data-3:/data/db
- ./mongodb-cluster/mongod.conf:/etc/mongod.conf
command: mongod --config /etc/mongod.conf --replSet rs0
networks:
lufy-cluster:
ipv4_address: 172.20.2.3
# MongoDB 副本集初始化
mongodb-rs-init:
image: mongo:6.0
container_name: lufy-mongodb-rs-init
depends_on:
- mongodb-rs-1
- mongodb-rs-2
- mongodb-rs-3
command: >
sh -c "
sleep 15 &&
mongosh --host 172.20.2.1:27017 --eval '
rs.initiate({
_id: \"rs0\",
members: [
{_id: 0, host: \"172.20.2.1:27017\", priority: 3},
{_id: 1, host: \"172.20.2.2:27017\", priority: 2},
{_id: 2, host: \"172.20.2.3:27017\", priority: 1}
]
})
'
"
networks:
- lufy-cluster
# ETCD 集群部署 (3节点)
etcd-1:
image: quay.io/coreos/etcd:v3.5.9
container_name: lufy-etcd-1
ports:
- "2379:2379"
- "2380:2380"
environment:
ETCD_NAME: etcd-1
ETCD_INITIAL_ADVERTISE_PEER_URLS: http://172.20.3.1:2380
ETCD_LISTEN_PEER_URLS: http://0.0.0.0:2380
ETCD_ADVERTISE_CLIENT_URLS: http://172.20.3.1:2379
ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379
ETCD_INITIAL_CLUSTER: etcd-1=http://172.20.3.1:2380,etcd-2=http://172.20.3.2:2380,etcd-3=http://172.20.3.3:2380
ETCD_INITIAL_CLUSTER_STATE: new
ETCD_INITIAL_CLUSTER_TOKEN: lufy-etcd-cluster
volumes:
- etcd-cluster-data-1:/etcd-data
networks:
lufy-cluster:
ipv4_address: 172.20.3.1
etcd-2:
image: quay.io/coreos/etcd:v3.5.9
container_name: lufy-etcd-2
ports:
- "2381:2379"
- "2382:2380"
environment:
ETCD_NAME: etcd-2
ETCD_INITIAL_ADVERTISE_PEER_URLS: http://172.20.3.2:2380
ETCD_LISTEN_PEER_URLS: http://0.0.0.0:2380
ETCD_ADVERTISE_CLIENT_URLS: http://172.20.3.2:2379
ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379
ETCD_INITIAL_CLUSTER: etcd-1=http://172.20.3.1:2380,etcd-2=http://172.20.3.2:2380,etcd-3=http://172.20.3.3:2380
ETCD_INITIAL_CLUSTER_STATE: new
ETCD_INITIAL_CLUSTER_TOKEN: lufy-etcd-cluster
volumes:
- etcd-cluster-data-2:/etcd-data
networks:
lufy-cluster:
ipv4_address: 172.20.3.2
etcd-3:
image: quay.io/coreos/etcd:v3.5.9
container_name: lufy-etcd-3
ports:
- "2383:2379"
- "2384:2380"
environment:
ETCD_NAME: etcd-3
ETCD_INITIAL_ADVERTISE_PEER_URLS: http://172.20.3.3:2380
ETCD_LISTEN_PEER_URLS: http://0.0.0.0:2380
ETCD_ADVERTISE_CLIENT_URLS: http://172.20.3.3:2379
ETCD_LISTEN_CLIENT_URLS: http://0.0.0.0:2379
ETCD_INITIAL_CLUSTER: etcd-1=http://172.20.3.1:2380,etcd-2=http://172.20.3.2:2380,etcd-3=http://172.20.3.3:2380
ETCD_INITIAL_CLUSTER_STATE: new
ETCD_INITIAL_CLUSTER_TOKEN: lufy-etcd-cluster
volumes:
- etcd-cluster-data-3:/etcd-data
networks:
lufy-cluster:
ipv4_address: 172.20.3.3
# NSQ 集群部署
nsqlookupd-1:
image: nsqio/nsq:v1.2.1
container_name: lufy-nsqlookupd-1
command: /nsqlookupd
ports:
- "4161:4161"
- "4160:4160"
networks:
lufy-cluster:
ipv4_address: 172.20.4.1
nsqlookupd-2:
image: nsqio/nsq:v1.2.1
container_name: lufy-nsqlookupd-2
command: /nsqlookupd
ports:
- "4163:4161"
- "4162:4160"
networks:
lufy-cluster:
ipv4_address: 172.20.4.2
nsqd-1:
image: nsqio/nsq:v1.2.1
container_name: lufy-nsqd-1
command: /nsqd --lookupd-tcp-address=172.20.4.1:4160 --lookupd-tcp-address=172.20.4.2:4160 --broadcast-address=172.20.4.11
ports:
- "4150:4150"
- "4151:4151"
depends_on:
- nsqlookupd-1
- nsqlookupd-2
networks:
lufy-cluster:
ipv4_address: 172.20.4.11
nsqd-2:
image: nsqio/nsq:v1.2.1
container_name: lufy-nsqd-2
command: /nsqd --lookupd-tcp-address=172.20.4.1:4160 --lookupd-tcp-address=172.20.4.2:4160 --broadcast-address=172.20.4.12
ports:
- "4152:4150"
- "4153:4151"
depends_on:
- nsqlookupd-1
- nsqlookupd-2
networks:
lufy-cluster:
ipv4_address: 172.20.4.12
nsqd-3:
image: nsqio/nsq:v1.2.1
container_name: lufy-nsqd-3
command: /nsqd --lookupd-tcp-address=172.20.4.1:4160 --lookupd-tcp-address=172.20.4.2:4160 --broadcast-address=172.20.4.13
ports:
- "4154:4150"
- "4155:4151"
depends_on:
- nsqlookupd-1
- nsqlookupd-2
networks:
lufy-cluster:
ipv4_address: 172.20.4.13
# Lufy游戏服务器集群(使用集群配置)
lufy-center-cluster:
build: .
container_name: lufy-center-cluster
command: ["-config=config/cluster.yaml", "-node=center", "-id=center1"]
ports:
- "8010:8010"
- "9010:9010"
- "7010:7010"
depends_on:
- etcd-1
- etcd-2
- etcd-3
- mongodb-rs-init
- redis-cluster-init
networks:
lufy-cluster:
ipv4_address: 172.20.5.1
volumes:
- ./logs:/app/logs
- ./config/cluster.yaml:/app/config/cluster.yaml:ro
environment:
- NODE_TYPE=center
- NODE_ID=center1
- CLUSTER_MODE=true
restart: unless-stopped
lufy-gateway-cluster-1:
build: .
container_name: lufy-gateway-cluster-1
command: ["-config=config/cluster.yaml", "-node=gateway", "-id=gateway1"]
ports:
- "8001:8001"
- "9001:9001"
- "7001:7001"
depends_on:
- lufy-center-cluster
networks:
lufy-cluster:
ipv4_address: 172.20.5.11
volumes:
- ./logs:/app/logs
- ./config/cluster.yaml:/app/config/cluster.yaml:ro
environment:
- NODE_TYPE=gateway
- NODE_ID=gateway1
- CLUSTER_MODE=true
restart: unless-stopped
lufy-gateway-cluster-2:
build: .
container_name: lufy-gateway-cluster-2
command: ["-config=config/cluster.yaml", "-node=gateway", "-id=gateway2"]
ports:
- "8002:8002"
- "9002:9002"
- "7002:7002"
depends_on:
- lufy-center-cluster
networks:
lufy-cluster:
ipv4_address: 172.20.5.12
volumes:
- ./logs:/app/logs
- ./config/cluster.yaml:/app/config/cluster.yaml:ro
environment:
- NODE_TYPE=gateway
- NODE_ID=gateway2
- CLUSTER_MODE=true
restart: unless-stopped
# 负载均衡器
nginx-lb:
image: nginx:alpine
container_name: lufy-nginx-lb
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./nginx/ssl:/etc/nginx/ssl:ro
depends_on:
- lufy-gateway-cluster-1
- lufy-gateway-cluster-2
networks:
lufy-cluster:
ipv4_address: 172.20.6.1
restart: unless-stopped
# 集群监控
prometheus-cluster:
image: prom/prometheus:latest
container_name: lufy-prometheus-cluster
ports:
- "9090:9090"
volumes:
- ./monitoring/prometheus-cluster.yml:/etc/prometheus/prometheus.yml:ro
- ./monitoring/lufy_rules.yml:/etc/prometheus/lufy_rules.yml:ro
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/etc/prometheus/console_libraries'
- '--web.console.templates=/etc/prometheus/consoles'
- '--web.enable-lifecycle'
- '--web.enable-admin-api'
networks:
- lufy-cluster
restart: unless-stopped
grafana-cluster:
image: grafana/grafana:latest
container_name: lufy-grafana-cluster
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin123
- GF_USERS_ALLOW_SIGN_UP=false
volumes:
- ./grafana/provisioning:/etc/grafana/provisioning:ro
- ./grafana/dashboards:/var/lib/grafana/dashboards:ro
depends_on:
- prometheus-cluster
networks:
- lufy-cluster
restart: unless-stopped
# 集群初始化工具
cluster-init:
build:
context: .
dockerfile: Dockerfile.cluster-init
container_name: lufy-cluster-init
depends_on:
- redis-cluster-init
- mongodb-rs-init
- etcd-1
- etcd-2
- etcd-3
volumes:
- ./scripts:/scripts:ro
- ./config:/config:ro
command: /scripts/init-cluster.sh
networks:
- lufy-cluster
restart: "no"